Oct 252008

If you are doing any PHP command line scripting, you may have wondered how you can add a bit of simple colouring to your scripts so it is easier for you, or your clients to view the output.

Using some Bash codes, you can colour the output to the terminal (assuming you are running the scripts in Bash or some other compatible terminal). Depending on the font colours and effects you want, you can use any of this code in your script. Just place it at the top, and include the variables in your output:

 * Font Colours
$BLACK="33[0;30m"; //Can not be used on backgrounds
$DARKGRAY="33[1;30m"; //Can be used on backgrounds
$RED="33[0;31m"; //Can not be used on backgrounds
$LIGHTRED="33[1;31m"; //Can be used on backgrounds
$GREEN="33[0;32m"; //Can not be used on backgrounds
$LIGHTGREEN="33[1;32m"; //Can be used on backgrounds
$BROWN="33[0;33m"; //Can not be used on backgrounds
$YELLOW="33[1;33m"; //Can be used on backgrounds
$BLUE="33[0;34m"; //Can not be used on backgrounds
$LIGHTBLUE="33[1;34m"; //Can be used on backgrounds
$PURPLE="33[0;35m"; //Can not be used on backgrounds
$LIGHTPURPLE="33[1;35m"; //Can be used on backgrounds
$CYAN="33[0;36m"; //Can not be used on backgrounds
$LIGHTCYAN="33[1;36m"; //Can be used on backgrounds
$LIGHTGRAY="33[0;37m"; //Can not be used on backgrounds
$WHITE="33[1;37m"; //Can be used on backgrounds
 * Bolded colours that can be used on backgrounds
 * Duplicates of the colours above with BOLD in the name
 * Background Colours
 * Font Effects
$BLINK="33[5;30m"; //Doesn't seem to work.
$INVISIBLE="33[8;30m"; //Pretty pointless
 * Turn it back to the default

To test this out, you can place this in a php script and execute it:

echo "<-- Font Colours -->
echo "$BLACK This is BLACK
echo "$RED This is RED
echo "$GREEN This is GREEN
echo "$BROWN This is BROWN
echo "$YELLOW This is YELLOW
echo "$BLUE This is BLUE
echo "$PURPLE This is PURPLE
echo "$CYAN This is CYAN
echo "$WHITE This is WHITE

echo "<-- Backgrounds -->
echo "$BLACKBG This is BLACKBG
echo "$REDBG This is REDBG
echo "$GREENBG This is GREENBG
echo "$BROWNBG This is BROWNBG
echo "$BLUEBG This is BLUEBG
echo "$CYANBG This is CYANBG

echo "<-- Font Effects -->
echo "$BLINK This is BLINK //Doesn't seem to work.
echo "$INVISIBLE This is INVISIBLE {$DEFAULT}//Invisible - Pretty pointless
echo "$DEFAULT Back to the default.

echo "<-- A Few Examples -->
echo "{$REDBG}{$YELLOW}This is a red background, with yellow font that {$UNDERLINE}{$YELLOW}is underlined{$DEFAULT}{$REDBG}{$YELLOW} for a portion. {$DEFAULT}
echo "{$CYANBG}{$LIGHTRED}This is red text on a cyan background. {$DEFAULT}

And practical example would be:

//Check to see if courses.txt exists
	echo "$RED The courses.txt file doesn't exist. $DEFAULT
Oct 212008

We recently played the round robin portion of the Wiitastic Cup of Hockey. This is a hockey tournament played using NHL 2K9 for the Wii.

It was a fun afternoon for all. There were some fantastic performances by some players through out the tournament. Stefan racked up the most goals, while I gave up the fewest. However, the best performance by far was by Miikka “Jesus” Kiprusoff. Jon had a gem in goal, stopping awesome shot after shot. However, he could not carry the team alone, and the Flames were sunk by their lack of scoring.

There were some inconsistencies regarding the rules for some of the games, but fortunately that didn’t generate any problems. Here are the results following the round robin:

Player Wins Losses Goals For Goals Against
Thomas (Pens) 3 0 10 6
Robert (Sens) 2 1 10 7
Stefan (Habs) 1 2 11 15
Jon (Flames) 0 3 4 7

The playoffs will be played using a Page Playoff system. Here is the layout:

Wiitastic Hockey Page Playoff

Oct 182008

I was trying to fix a friends computer recently.  It was a Windows XP machine which would boot up (in both normal and safe mode) and give the error with services.exe:

This application has failed to start because MSVCP60.dll was not found.  Re-installing the application may fix this problem.

And then completely stop loading.  This appeared to begin after a botched SP3 install through automatic updates.  None of the normal tricks for getting into windows would work, so I booted to a Ubuntu live CD (7.04) and took a look at the hard drive.

All of the information was still there, that was good news.  I found a copy of MSVCP60.dll on the harddrive, but it wasn’t in the c:windowssystem32 folder, and hence the error.  So I tried to copy it, but Ubuntu 7.04 Live CD cannot write to NTFS partitions.  Bummer.

So, I copied the file from another computer to a USB key, put that into the Live CD Ubuntu desktop, copied the file to the floppy, rebooted into Windows Recovery mode (from an old Win XP CD I had) and tried to copy the file from the floppy to the hard drive, however I was getting “Permission Denied” errors.

So, I took a look at the C: and sure enough, Windows Recovery Console could not read any files there.  Another bummer.

So, I started downloading a new version of Ubuntu (8.10 beta) in order to get read/write NTFS in the live CD.  While I was waiting, I thought I’d try to fix the boot sector on the broken machine.  I poked around for a bit.  Tried chkdsk but got an error about ‘one or more unrecoverable file system errors’.  Then the fixboot command looked interesting, so I ran it.


It said it fixed the boot sector, and threw a nice FAT16 table at the beginning, after autodetecting what it was.  Huh?  Now when I search the C:, I get a message, “No Files Found”.

So, when I finally got Ubuntu downloaded and burned, I rebooted and took a look at the partition.  Double click…and nothing.  Can’t read the media.  I opened it Gparted partition editor, and sure enough, a nice 300GB FAT16 partition that cannot be read.  Well at this point I began to get worried.

I decided to take the machine home for the night, as I had more tools available there.

I knew that there was a backup boot sector on the drive, and what I had to do was to restore that.  But with what?  I did some searching and came across TestDisk.  I had used this in the past to try and recover an ext3 partition, but with no success.  Then I started poking around at a rescue CD that included TestDisk.  Ubuntu Rescue Remix is one of the rescue disks I cam across.  I also download Knoppix, but URR finished sooner because it was a much smaller ISO, so my success was with that one. 😉

Booted on the rescue disk.  It gives you a nice console.  Ran:

sudo testdisk

And started to get to work.  The drive was detected properly, always a good start.  I then scanned for partitions, there were 3 listed (actually only one on the drive) in the table, and they overlapped, which is not possible.  The application knew something was wrong, and did a slightly deeper scan and detected one NTFS partition that took up the whole drive.  I wrote this information to the disk.

I think I actually had fixed it at this point, but I kept on poking around.  I went back to the main menu, and went to the advanced tools.  I took a look at the boot sector recovery.  The detection showed both the master and backup being the same.  Not sure if when I rewrote it, it rewrote the backup too (that would make sense), but after writing once, the backup seemed unavailable as an option.

I then scanned the MFT to rebuild it if needed, but it was identical to what the application was going to reinstall.  So nothing to do there.  I rewrote the boot sector again, and then rebooted. (Have to take the CD out at this point, the boot menu gives you the option to boot to the hard drive, but that wouldn’t work for me)

I rebooted and got this error:

This application has failed to start because MSVCP60.dll was not found.  Re-installing the application may fix this problem.

Yeah!!!  Windows lives.  So, I rebooted, went into the new Ubuntu Live CD (8.10 beta) I had burned earlier and tried to access the drive.  No go.  Windows didn’t let go of it properly when it locked up.  Which isn’t a surprise really.  Ubuntu told me what command to use to force it to mount:

sudo mount /dev/sda1 /media/testdisk -t ntfs-3g -o force

I’m pretty sure that was it (from memory now).  /media/testdisk is a directory I created in order to mount the drive.

Mount successful.  File copy successful.  Rebooted, and Windows loaded!

It looked horrible.  The graphics driver was missing, probably killed in the botched SP3 upgrade.  There were still file missing errors, but I was able to get to the desktop.  I copied the files that were missing from somewhere else on the drive, back to c:windowssystem32 to make those errors go away.  I tried to download new video drivers, but Flash was also corrupted beyond repair it crashed all of the browsers when they loaded. All the websites that had the drivers (and the default homepages) used flash.  So I uninstalled flash, download new flash, and video drivers, installed both, and all is good.

The moral of the story, NEVER USE FIXBOOT!

Oct 032008

ASCII Sector is a space trading game written completely using ASCII graphics. It is available from www.asciisector.net. There are Windows and Linux versions. This is a post I made on the forum over there explaining how I got this to run in a 64bit environment.

Hello All, I thought I would tell you a story of how I got this running on my 64bit Ubuntu (since I didn’t at a glance see anything tho help me out with this).

First, I’m running a 64bit install of Mythbuntu that I converted to a regular Ubuntu desktop a few months after the install.

I downloaded and installed ASCII Sector as described in the instructions. When I ran the file, I would get the error:
bash: ./asciisec: No such file or directory

Of course, this made no sense since I was at the location of the file. I made sure I had libsdl and libsdl mixer installed, but that didn’t help. So I went browsing around, and found a post that said that this error was common when running 32bit apps on a 64bit install, and than installing the 32bit libraries would help. So I ran this command:
sudo apt-get install ia32-libs

This installed the libraries for me, and when I ran it, I no longer got that error (Yah!) I got this one instead (boo):
./asciisec: error while loading shared libraries: libsmpeg-0.4.so.0: cannot open shared object file: No such file or directory

So, I used Synaptic to ensure that I had libsmpeg installed and I did. So, I did an strace on the process to see where it was looking for the file. Then I ran the find command to see where it was:
sudo find / -name "libsmpeg*"
And it wasn’t looking where it was located. So I tried to create a symlink to a path it was looking in, but that didn’t work either. I got this error:
./asciisec: error while loading shared libraries: libsmpeg-0.4.so.0: wrong ELF class: ELFCLASS64

So I was back to the drawing board.

I did more searching, and came across a ubuntu 64bit gaming post referring to the getlibs application that installs 32bit compatible libs on 64 bit system. Here is that post: http://ubuntuforums.org/showthread.php?t=662770&page=6 I downloaded getlibs from here: http://ubuntuforums.org/showthread.php?t=474790 installed it, and then ran this command:
getlibs -l libsmpeg-0.4.so.0
The program works similar to apt-get and downloaded the library and installed it. Then I ran asciisec and I was in the game. (real Yah!) I didn’t actually get to play it yet, but I imagine it will work fine now that it is all loaded up.

I’ve played a little bit, and it is a pretty fun game. I hope to make some quests for it in the future.

Oct 022008

Hello everyone, and welcome back to my site (if any one ever really looked at it in the first place).

I’ve decided to setup a wordpress blog to jot down the tidbits that I run across in my daily life.  I had planned to write my own piece of software to do this, but my other projects are taking too much of my time to continue waiting (waiting for like 4 years now…FYI).

On this site you can expect to find tips and tidbits on programming, web design, linux, gaming and anything else note worthy I come across.  This will serve as a repository of knowledge (hopefully useful) for me, and for the general internet public.

This is the first time I’ve used WordPress, so it is pretty bland as of now.  Later, I’ll get around to customizing things more.

Hope you find something useful here at some point.