Fast Calendar Generator for PHP

August 2nd, 2007

I’ve been using various calendar modules for years, and I’ve found most of them to be either resource intensive, obtuse to use, or just plain ugly code. Having yet another project that requires a calendar, I decided to finally build my own generator. This function simply builds an HTML table for the specified month. The only loops in the code are to actually generate the table. The rest of it uses PHP’s built-in array functions. It does not validate the input variables, either — that is done at the point the input is received.


<?php
    
function fast_calendar$pYear null$pMonth null ) {
        
$stamp strtotime$pYear ‘-’ $pMonth ‘-01′ );
        
$grid = ( date‘w’$stamp ) > ) ? array_fill0date‘w’$stamp ), null ) : array();
        
$grid array_merge$gridrange1date‘t’$stamp ) ) );
        
$grid = ( count$grid ) % ) ? array_merge$gridarray_fillcount$grid ) - 1- ( count$grid ) % ), null ) ) : $grid;
        
$grid array_chunk$grid7true );
        
$str ‘<table border=”1″ cellpadding=”3″><tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>’;
        foreach( 
$grid as $week => $days ) {
            
$str .= ‘<tr>’;
            foreach( 
$days as $day => $label ) {
                
$str .= ‘<td height=”50″ width=”50″ valign=”top” align=”right”>’ $label ‘</td>’;
            }
            
$str .= ‘</tr>’;
        }
        
$str .= ‘</table>’;
        return( 
$str );
    }
?>


Core 2.0 Beta Released!

May 2nd, 2007

Core is a minimal distribution of the GNU/Linux operating system designed to be the basis for a complete system constructed by the end user. A fresh installation of Core will boot into a console and provide the user with the tools needed to download, compile and install other applications. Core contains nothing beyond what is required to perform these tasks. Core is primarily designed for experienced Linux users, though it has found an audience with those looking to learn about the internals and operation of a Linux system.

Four years ago, on April 4, 2003, Josh Devon released Core 1.x — today, May 1, 2007, the new Core development team has released a fully functional beta of Core 2.0. This beta has been in constant use for development for a number of weeks, and is more or less stable in that capacity.

Check out Core GNU/Linux website and the SourceForge project for information and downloads.

Internet Explorer on Linux

January 16th, 2007

Sergio Lopes has created a very good script to install Internet Explorer on Linux for use with WINE. You can visit the IEs4Linux site at http://www.tatanka.com.br/ies4linux/page/Main_Page.

After installing the three versions of IE that are available, I was left with the task of creating menu items for each launcher script, which I didn’t really want to do. Instead I wrote a launcher that lets me select which version of IE I want to run. I also generated usable icons from Sergio’s SVG image.

This trick requires Xdialog, and you will need to modify this script to work for your installation of IEs4Linux by setting the base variable. You can download the script from ielaunch or copy/paste it from here.

#!/bin/bash
base='/path/to/ies4linux/scripts/'
launch=$(Xdialog --stdout --title 'IEs4Linux Launcher' --no-tags --menu 'Select IE Version' \\
         10 40 15 '1' 'IE 5.01' '2' 'IE 5.5' '3' 'IE 6.0 SP2')
case $launch in
1)
   $base'ie5'
   ;;
2)
   $base'ie55'
   ;;
3)
   $base'ie6'
   ;;
esac

Now, just add a menu item pointing to the script (make sure the script is chmod +x!). You can use an icon from the icon pack. If all went well, you will see this dialog when you click your menu item -
IEs4Linux

Question and Answer Session with the Author

September 23rd, 2006

1. How did you learn programming? Were any schools of any use? Or maybe you didn’t even bother with any schools?

I am self-taught, and did not attend any courses at college/university or certification/training seminars.

2. What do you think is the most important skill every programmer should have?

Effective design techniques. The key mark of a good design technique is that it can be re-used as a problem solving technique equally as well.

3. Do you think mathematics and/or physics are an important skill for a programmer? Why?

Mathematics is definitely a valuable skill set for a programmer. Everything with computers is number-based. One could go on and on for a long time with examples, but they are generally self-evident.

An understanding of physics is equality important for some types of programming (image analysis, game development, etc), although not generally required for some fields of development.

The importance of other studies should not be ignored either. For example, an aptitude for genetics could be a help with various forms of programming in the fields of artificial and adaptive intelligence. Equally, an understanding of natural biology and the evolution and adaptation of species could prove invaluable to a programmer who wishes to create long-term technology solutions which will adapt and change over time.

4. What do you think will be the next big thing in computer programming? X-oriented programming, y language, quantum computers, what?

I think low-cost/personal clusters will be at the forefront soon.

5. If you had three months to learn one relatively new technology, which one would You choose?

C - It’s not new by any means, but it is the only major language I don’t know very well.

6. What do you think makes some programmers 10 or 100 times more productive than others?

Productivity is contextual. Some programmers have minds which lend themselves to what I call ‘production code’, that is, the ability to produce mass amounts of functional code consistantly over time. Other programmers do better when they multitask, making smaller steps on many projects. A third group of programmers is suited for working on large/complex issues which have not been attempted before. It really depends how the programmer’s mind is wired. There are even some programmers who can switch gears and be in any of the three modes as needed.

7. What are your favorite tools (operating system, programming/scripting language, text editor, version control system, shell, database engine, other tools you can’t live without) and why do you like them more than others?

OS: GNU/Linux (currently Fedora Core 5), but I have also built my own custom distro which I base my internet application servers on.
Language: PHP for web and shell scripting; Gambas for GUI work; Pike/Python for various tasks.
Editor: Eclipse for projects; UltraEdit (running under WINE) for single file/basic editing. VI for fast work.
RCS: Subversion
Shell: BASH
DB: MySQL for web-based or heavy searching systems; PostgreSQL for heavy transaction load projects;
Browser: Swiftfox, which is Firefox, compiled for specific architectures.
Graphics: the GIMP and Inkscape.
Docs: DocuWiki for online documentation / project notes. Easy to generate flat documentation packages in TXT and (x)HTML.
Bugs: Flyspray for bug/task tracking. Possible to generate change logs and collate with subversion change logs.
Publishing: Scribus for layout work; Open Office for general documents.

8. What is your favorite book related to computer programming?

Spidering Hacks (published by O’Reilly) — I wrote a few pages of it. :-) I don’t use books for programming/computer work very often, so I don’t really have a favorite.

9. What is Your favorite book NOT related to computer programming?

How about a series? The Posleen War series by John Ringo.

10. What are your favorite music bands/performers/compositors?

Richie Valens, Buddy Holly (I grew up in Holly’s hometown), Deep Purple, Depeche Mode, Roxette, Ace of Base, U2, Van Halen, Berlin, Madonna, others. I also like folk music from various regions of the world, particularly Celtic, Eastern Indian, and Arabic.

Software Freedom Day

September 14th, 2006

Press Release: Barrie, Ontario, Canada - September 14, 2006

Barrie’s second Software Freedom Day - September 16, 2006

Thousands of people expected to gather in cities around Canada and the world to share and promote the benefits of free and open source software.

The Barrie Linux Users Group is proud to announce Barrie’s inaugural Software Freedom Day on September 16, 2006. Software Freedom Day is a global initiative to celebrate and give back to the community by taking Free and Open Source software to the streets! The event will be held from 9am to 4pm at the Barrie Public Library’s Georgian Room.

Software Freedom Day will have over hundreds of teams across the world doing a variety of activities, including distributing free Linux CDs and other giveaways, running booths about Linux and open source software

More information about free software can be found online at http://en.wikibooks.org/wiki/FLOSS_Concept_Booklet

Free software offers everyone all the tools they need to improve their computer literacy, without any upfront cost. Computers have become an integral part of society and now drive most businesses. Computer skills have therefore become essential to advancing a person’s career.

In addition to job prospects, computer skills and online communications equip an individual with the means to a better education, online services and goods, a broader community, and to opportunities that simply may not be accessible to them in their area. The online culture does not judge people on their colour, age, sex, or beliefs, but rather on their achievements, and with the right tools, what an individual can achieve with a computer is solely limited by their imagination.

Examples of free software include the Linux operating system, OpenOffice.org office productivity suite, Firefox Web browser, and the GIMP image manipulation tool (similar to Adobe Photoshop). There is also free software for gaming, instant messaging, business and financial applications, and many more areas of computing.

Discover Free Software and what it can do for you on Software Freedom Day, September 16!

About Software Freedom Day

Software Freedom Day is a global initiative to celebrate and give back to the community by taking Free and Open Source software to the streets! See http://www.softwarefreedomday.org for more information.

About the Barrie Linux Users Group

The Barrie Linux Users Group (BLUG) was founded to cater for the needs of the Barrie Linux community and to promote the use of Linux and open source software in Barrie and central Ontario. For more information and the monthly meeting schedule see http://www.barrielug.org/ .

Contacts:

Alexander Rau – BLUG founder & event coordinator – alex.arau[it_goes_here]gmail.com

Pat Wendorf – BLUG founder & event coordinator – dungeons[it_goes_here]gmail.com

James Linden – BLUG co-founder & event coordinator – jl[it_goes_here]jameslinden.com

Journalists are very welcome to these events, and please contact us if you are interested in more information, interviews or photos.

Warmest regards,

Alexander Rau, Pat Wendorf, James Linden

Postfix (with MySQL support)

August 9th, 2006

After being unable to locate a Postfix RPM for Fedora Core 5 which had MySQL support compiled in, I ended up making one.

You can download it here: postfix-2.2.8-1.2.i386.rpm

It will require:

  • ldap-devel
  • mysql
  • mysql-devel
  • cyrus-sasl-devel
  • cyrus-sasl-libs
  • openssl-devel

And possibly others.

KSplash & GDM/KDM Themes

July 27th, 2006

After building KSplash and GDM/KDM themes using Tux, I ended up making a couple of others as well:

nuxified.org

KSplash Theme: [preview] [download]
GDM/KDM Theme: [preview] [download]

barrielug.org

KSplash Theme: [preview] [download]
GDM/KDM Theme: [preview] [download]

All are released under the BSD license.

To install, simply download and run the included install script.

GDM Login Theme: Tux

June 23rd, 2006

I made a basic GDM login theme with Tux, our esteemed mascot. This theme is designed to be very basic, so you can easily change the images, etc and make your own theme.

Instructions:

  1. Download gdm-Tux-0.1.tar.bz2
  2. Unarchive the file with tar -xjf gdm-Tux-0.1.tar.bz2
  3. Run the install script which is in the package. (The installer simply copies the Tux directory to /usr/share/gdm/themes/.)

Screenshot:

GDM Login Theme: Tux screenshot

KSplash Theme: Tux

June 23rd, 2006

I made a basic KSplash theme with Tux, our esteemed mascot. This theme is designed to be very basic, so you can easily change the images, etc and make your own theme.

Instructions:

  1. Download kplash-Tux-0.1.tar.bz2
  2. Unarchive the file with tar -xjf kplash-Tux-0.1.tar.bz2
  3. Run the install script which is in the package. (The installer simply copies the Tux directory to /usr/share/apps/ksplash/Themes/.)

Screenshot:

Tux KSplash Theme - screenshot

HTML Forms - Image Selector

April 19th, 2006

I wanted to be able to select an image icon easily, like this:

This is the stylesheet and javascript:

<style type="text/css">
.icon {
height: 32px;
width:  32px;
background-repeat: no-repeat;
padding-top: 1px;
padding-bottom: 1px;
background-color: white;
}
.group {
height: 35px;
background-color: white;
}
</style>
<script language="javascript" type="text/javascript">
function doIcon( pVal ) {
var obj = document.getElementById( 'imgCombo' );
var img = '/file/imgselect/' + pVal + '.png';
obj.style.background = "url( '" + img + "' ) no-repeat";
}
</script>

And this is the actual form code:

<form>
<select class="group" style="width: 54px;" onchange="javascript: doIcon( this.value );" id="imgCombo">
<option value="xclock" class="icon" style="background-image: url('/file/imgselect/xclock.png');"> </option>
<option value="firefox" class="icon" style="background-image: url('/file/imgselect/firefox.png');"> </option>
<option value="gimp" class="icon" style="background-image: url('/file/imgselect/gimp.png');"> </option>
</select>
</form>

You can look at the example by itself here.

« Previous Entries