PHP Tip: Command Line De-bugging
by Brent @ 10:53 am on 26.04.07
Here is a little tip you may or may not have known. The PHP parser on the command line will give more descriptive error messages than the browser will.
Here is a good example:
Right now, I am working on dynamic PNG creation using PHP and GD. I am creating a blog and we want the titles to be in a specific font, but we aren’t willing to go to all of the work to create the titles in Photoshop. I’ve used this technique before, if you are interested in the actual code, post a comment, and I will send it to you.
So, I go to run my PHP just to test it out…I get this back from the browser:
The image “http://localhost/blog/brent.php?text=hello&r=17&g=17&b=17”
cannot be displayed, because it contains errors.
Oh, I see. Yes, of course. It contains errors. That totally makes sense. Now, I could go and turn on the super-duper error reporting in php.ini, but then it would show every error and warning known to man, and I don’t want that. I don’t want to write some crazy error checking code for such a small simple thing either. I just want this to work, and I know it can, and I also know I am just doing something stupid. What to do? To the command line!
brent@office:~/public_html/blog$ php -f brent.php
Warning: imagettftext(): Could not find/open font in
/home/public_html/blog/brent.php on line 51
?PNG
Now that’s more like it! There is something wrong with reading or opening the .ttf! Man, I guess I could have caught that if I had gone through the code line by line, in an ultra-tedious manner. But even that won’t catch some errors. As it turns out, the real problem was the permissions on the .ttf file. Who knew? Command line php, that’s who!
A puzzling addiction
by Brett @ 12:36 am on 25.04.07
Any of you who read Penny Arcade will have heard the great reviews of the Puzzle Quest game for the DS and PSP. It’s been getting consistently great reviews from many sites, and I’ve read many people’s accounts of how addictive it is. Since this is a puzzle game mixed with a role-playing game, I just had to check it out.
The quick description is that you choose a class of character (wizard, warrior, druid, knight) and a portrait and then you start running around a big map. You interact with each town and pretty soon you’re into your first battle. A battle is just an 8×8 grid that you move jewels around on, and when you match colours, you get mana of that colour. That mana then lets you cast spells and perform moves, that you learn as you level up. You can’t use your special moves until you get some mana, and you can’t get mana unless you figure out how to align jewels to your advantage.
This game is totally worth the cash. It’s fun to play in the long term ’cause you get all sorts of fun stuff to do with your character - you can build a castle with all sorts of neat buildings to research spells, items, and stuff like that. You can buy all sorts of armour, weapons and gear which give you benefits in battle. Plus, the story seems to toe the line between “not too complicated” and “too simple” - both of which get very boring.
If you don’t feel like wandering around and compleing quests, then you can just sign in for a quick battle. You can also play multiplayer challenges, so the game turns into a mix of tetris and WoW. It’s kind of like Guild Wars in that you can only take a few spells with you into battle, and you gain tonnes of spells to use during battle. The spells are very different and allow for some very different tactics in defeating your foe. It’ll be neat to see the difference with different types of characters.
I highly recommend the game. I find myself picking it up whenever I have a few minutes to kill.
I think we have all been here…
by Brent @ 12:34 pm on 19.04.07
Powered by ScribeFire.
Encryption fun.
by Brett @ 12:00 am on 17.04.07
Recently, I procured a laptop from my place of business. It’s a wonderful piece of high-tech awesomeness.
I have the laptop so that I can code when I’m not at work. I’m supposed to know things about security, so I decided to encrypt the file-systems that would have confidential data on them. Plus, I didn’t really know how to do it, so this was a good excuse learn.
I decided to encrypt 2 partitions: /home and /filesystem. After making the partitions, it was pretty easy to encrypt them. For example, if I had a partition on /dev/sda7 and wanted to make that an encrypted partition on /filesystem, I would do this:
mkdir /filesystem
modprobe loop
modprobe cryptoloop
losetup -e blowfish /dev/loop0 /dev/sda7
enter a cool password
mkfs -t ext3 /dev/loop0
mount /dev/loop0 /filesystem
You’ll have to have a password ready for when you build the encrypted system.
Normally, you would change the boot scripts to ask the user for a password when the system’s booting up. But I don’t like that idea (and I couldn’t figure out how to get Ubuntu’s start up script to actually ask a question), so I decided to put the password on a USB key. I wouldn’t want the password to be sitting on the key in plain text, so I made an encrypted file system on a USB key and put the passwords on there. The password for the USB key, I just threw on the root partition of my hard drive - unencrypted. Let’s review: During bootup, a script will take the password it knows, unencrypt the USB key if it’s there, read in some passwords, and decrypt the local filesystems.
Now to boot up the machine with the encrypted partitions, you just need the USB key. So, then I just added a new rc script that will run during boot to do the work. I actually copy the contents of the key into memory so that I can unmount and remove the USB key after boot. That script is here. You’ll note that it passes file descriptors around - that’s because that was the only way I could figure out how to pass the losetup program a password - it didn’t want to accept a filename, or pipes. The passwords are stored in files on the root partition, and on the USB key - and have to be input in the init script.
It’s pretty easy to setup a linux system to run that script during boot - just copy it into the rc.sysinit directory and make symlinks as you see fit, into the right runlevels. Make sure you run it before any service that needs the filesystems that you’re mounting.
If anyone does manage to steal the laptop, then at least they won’t be able to read any code or docs. I can also store my own stuff on there, and not really worry about it. I’ve had this running for about a month now, and I haven’t noticed a huge hit in performance. I run eclipse with the workspace in the encrypted filesystem, and it runs faster than my desktop machine. Now you know, and knowing is half the battle.
Island of the Sequined Love Nun
by Brett @ 2:00 am on 05.04.07
I recently read Christopher Moore’s Island of the Sequined Love Nun, happily recommended and leant to me by the Pirate Styan. I’m very glad for the loan as this was a very entertaining read.
You know how you start some books and you don’t get into them right away? So, you’re thinking “I’ll give it a little while”, which you do. Then, after “awhile”, you are somewhat interested in the book, but not really hooked on it. You don’t stop ’cause you’ve invested so much time into it … it’s not that bad, and who knows, it might get better. Then you finish the book, and that usually hits some sort of “good” rating because it was fairly entertaining.
Well, this book is a bit different than that. I mean, it starts the same way - you don’t really get into the characters or the plot. I don’t really give a shit about the main character or his plight, and the author seems okay with that. In fact, he seems to have assumed my apathy. To keep me entertained until he can interest me in the protagonist, he throws a whole bunch of crazy events and characters around which were entertaining if nothing else. The story is full of mysterious clues, which I found fun ’cause I like solving puzzles. So, instead of spending the first half of the book trying to keep things straight, I found myself reading just to see what crazy stuff was coming up next, and the next thing I knew I was really into the book! Brilliance!
The main character is in a bit of a self-destructive phase of his life, when a series of disasters land him on an island populated by a bunch of shark killing natives, who worship an old B52 bomber pilot as a God, read a lot of hollywood magazines as holy scripture, and have their organs harvested by an insane missionary doctor and his beautiful ex-stipper apprentice.
With a number of interesting companions - including a cross-dressing son of a “navigator”, a talking fruit bat, and a cannibal - the main character tries to understand what’s going on and then save the natives from their predicament.
This novel is interesting on a number of levels. I really enjoy the main character’s struggle to get to know himself. After a series of near death experiences and difficult moral questions, the main character finds his sense of self, his faith, and what he wants of life.
An interesting question - the protaganist lands on this island and the natives believe in a God who to him is obviously fake. They are very steadfast in their faith, and oblivious to the harm being done to them. In fact, those who have had their organs harvested are considered the chosen ones. So, the question is: Is it wrong for the main character to “rescue” them from that situation? I guess you’ll have to read the book to find out how it all plays out. Unless you’ve read the book … then you can answer now.
Anyway - the book’s pretty unique and a fun read. If you’re looking for something new, I definitely think it’s worth the time.