Category Archives: Misc

Send and Receive POST Requests with PHP

This can be used to build an API or generally have different sites and scripts communicate externally.

function postback($url, $params, $optional_headers=null, $decode=true) {
$params['handshake'] = HANDSHAKE;
 $params['url'] = $url;
 $params['remote_ip'] = $_SERVER['REMOTE_ADDR'];
 $data = http_build_query($params);

$options = Array('http' => Array(
 'method' => "POST",
 'header'=> "Accept-language: en\r\n".
 "Content-type: application/x-www-form-urlencoded\r\n",
 "Content-Length: " . strlen($data) . "\r\n",
 'content' => $data));

if ($optional_headers !== null) {
 $params['http']['header'] .= $optional_headers;

$ctx = stream_context_create($options);
$fp = fopen($url, 'r', false, $ctx);
 if (!$fp) throw new Exception("Problem with URL '$url' {$php_errormsg}");

$response = stream_get_contents($fp);
 if ($response === false) throw new Exception("Problem reading data from $url, $php_errormsg");

 if ($decode) $response = json_decode(rawurldecode($response), TRUE);

// Invalid query?
 if (!isset($response['handshake']) || ($response['handshake'] !== HANDSHAKE))
 return NULL;

return $response;


This vs That — Be Tech Agnostic

Linux (Ubuntu) vs Windows 8 vs OS X
iOS vs Android vs Windows Mobile vs Whatever …

I’m not a “frontend developer.” That’s not my job. I’m a “backend” developer” and I only code PHP and MySQL on OS X. <-- Move away from this mentality and be more accepting of other technologies. Investors and businessmen don't care so much what's under the hood, and neither should you.

Don't limit yourself to a single OS or platform. Dabble in open source and use Linux*, OS X and Windows. Learn WordPress, Joomla, Drupal and Magento. Learn Django, Rails, Symfony and Ruby, Python and PHP. If you're wondering where to start, it's not the tools that matter, but how you use them. In IT, you'll always find a layer of abstraction above where you are right now. There's always a right tool for the job. Taking a top down approach, see the goal and work backwards on how to achieve it. It's true that if you know one programming language, you know them all, and even if you aren't as efficient with one language compared to another, those are "problems" that get streamlined early on.

Don't tie yourself down to an OS. Use whatever works for you. I don't have a "main" workstation. I have a Macbook Pro when I'm on the go and usually at home. I have Ubuntu and Windows on a desktop and Android on my phone. I am a developer. An engineer. I can code for all of these platforms and there's no reason to coerce yourself into one niche.

Zoom out and take note of the technologies and skills you've accumulated under your belt. These are all labels (i.e., a “wordpress developer” is or at least should be a PHP developer) Yes there are bad programmers and good programmers, but the difference isn’t in the code anymore. Working in IT means always being able to adapt to changes in trends. Make your work your sandbox. Don’t bullshit anyone, but don’t deny what you’re capable of either. Create.

See yourself as a problem solver and tackle challenges accordingly. Use your developer skillset to keep the wheels in motion. What makes programming worthwhile? Why reinvent the wheel when you can move the damn thing forward a millimeter or two?

Blackberry Desktop Software Released for Mac OS X


Earlier today, RIM released Blackberry Desktop Software for Mac (10.5.5+ required). It lets you sync your iTunes music with your Blackberry, sync your contacts and appointments with “popular Mac applications,” add/remove apps, and transfer data between your Mac and BB.
This 26 meg app is nice, but RIM needs to get going on a Mac port of their SDK. Sad considering most of it is just Java, with EXE wrappers. Fortunately there’s Openberry and other workarounds.

_Volumes_BlackBerry Desktop Manager-1.jpg

External Links Being Hidden Behind Emoticons/Smilies

Lately, I’ve noticed a lot of the spam comments on my blogs contain links concealed behind smilies. This helps you place any URL on a forum or a blog, without raising any red flags, as would happen if you blatantly add links to your posts or signature. It’s not obvious that this paragraph is just here to build a backlink to another site grin

Why the hell would you want your links where humans don’t notice them? Because machines do notice them, and your purpose is to have as many sites link back to you as possible. This artificially raises the rank of a site in the search engines. Whether this method actually helps or not is questionable. It helps, especially if done on a big level, but the point of this post isn’t to discuss SEO. It’s to raise awareness of this what I’m noticing to be an increasingly common tactic.

This idea isn’t new. Adding URLs to a 1×1 pixel transparent gif for tracking purposes is old and common, but this is now being used to build backlinks.

You can make this impossible by disabling UBB/HTML in your blog comments. Other methods include adding a border around smilies which are clickable.

The Gmail Captcha is Optional

When you try to login with bad credentials, Gmail gives you a captcha to fill in before your next login attempt. Not only does this captcha appear randomly (keep putting in the wrong username and it will sometimes appear, sometimes not) (update: now it appears to be more consistent), but it’s also optional*. Just put in your correct username and password, ignoring the captcha, and it will log you in.

I probably discovered this out of frustration, but for the past few months (or years) I thought it was something we all knew until I saw one of my friend’s enter the captcha value. I never actually stopped to think about why a captcha would be “optional” – it’s ridiculous, and I’m probably overlooking an obvious point to this.

Enter the correct name/pass and hit login
Enter the correct name/pass and hit login
Seemingly random captcha
Seemingly random captcha

* I’m not sure why, but some people are saying that they cannot login without entering the captcha. I’ve tried on Swiftweasel and Firefox 3.x/Opera 9.x and 10/Konqueror/Chrome on Linux, and on Safari on the Mac, and have never needed to enter the captcha.

Also worth mentioning, a lot of forms you get when you try to download something are optional. For example, if you try to download Mimer SQL, it gives you this form: but you can just scroll down and hit the download button without putting any info in.

Bash Tips for Power Users

Every Geek site needs an obligatory Bash Tips post

Copy Files Securely Between Two Machines

I used to always forget the syntax for this, until I realized that the syntax is exactly like the standard cp command. In fact, you can copy files like you normally would using scp, on your local machine. The following are equivalent:

$ cp file file.orig
$ scp file file.orig

Where they differ is, scp lets you copy files over a network, through SSH. Here’s an example:

$ scp contents.txt

This will copy local file contents.txt to /tmp on the remote machine, as user silver. Here are some more examples:

$ scp draft.pdf

(copy draft.pdf to my home dir on remote machine. username is implied to be the same locally and remotely.)

$ scp swine.jpg

(read: This will copy swine.jpg to local machine as a file named To make it go remote, append a : to the address, like above)

scp supports, among other things, compression (-C) and recursive copying of directories (-r).

$ scp -rC code/

Trying to copy to a directory you don’t have permission to (/usr etc) will fail.

Don’t Get Lost Jumping To and Fro Between Directories

You can use cd - to jump to the previous (NOT parent) dir. For example:

kiwi@localhost: ~ $ cd /usr/local/share
kiwi@localhost: /usr/local/share $ cd -
kiwi@localhost: ~ $ cd -
kiwi@localhost: /usr/local/share $

Another way is using pushd/popd – A Last In First Out (LIFO) stack of dirs.

kiwi@localhost: ~ $ pushd /usr/local/share/
/usr/local/share ~

pushd is like cd but keeps note of the current dir before cd’ing into a new one. The stack of dirs is listed every time you invoke pushd (the “/usr/local/share ~” output you see above.)

kiwi@localhost: /usr/local/share $ pushd /
/ /usr/local/share ~

Stack is ordered left to right, latest push first. If we pop the first dir off:

kiwi@localhost: / $ popd
/usr/local/share /tmp ~
kiwi@localhost: /usr/local/share $

We’re back in the share dir. We can keep popping until there’s nothing left (throws an error):

kiwi@localhost: /usr/local/share $ popd
/tmp ~
kiwi@localhost: /tmp $ pushd /lib
/lib /tmp ~
kiwi@localhost: /lib $ popd
/tmp ~
kiwi@localhost: /tmp $ popd
kiwi@localhost: ~ $ popd
bash: popd: directory stack empty

Working with Long Lines

No need for more Bash shortcut cheat sheets, but here are some useful ones to help you work with long lines.

You can jump to the start & end of a line using CTRL+a & CTRL+e respectively. Example (* is the cursor):

kiwi@localhost: ~ $ echo al the ducks are swimming in the w*

and you want to fix the first word. You can hop to the beginning of the line with CTRL+a:

kiwi@localhost: ~ $ *echo al the ducks are swimming in the w

and now you can jump to the end of the misspelled word “al” using CTRL+Right twice to correct it:

kiwi@localhost: ~ $ echo all*the ducks are swimming in the w

Now ctrl+e to jump to the end of line:

kiwi@localhost: ~ $ echo all the ducks are swimming in the w*

Instead of backspacing every character, use ALT+Backspace to backspace entire words. You can also delete all or part of a line using CTRL+u combo. It deletes everything before the cursor. Likewise, CTRL+k wipes out everything after the cursor. I’ve developed a habit of using CTRL+e CTRL+k to delete lines.

Bash has a lot of ALT commands that let you move and manipulate words. ALT+l and ALT+u will make a word in front of the cursor lowercase or uppercase, for example. A neat one I don’t think I ever used is ALT+\ It pulls everything after the cursor left to the first non-whitespace character. Here’s an example, * is the cursor:


$ my     spacebar is    *sticky


$ my     spacebar issticky

Avoid Retyping Commands & Arguments

ESC + . is very useful. Escape followed by a period will output the argument you sent to your last Bash command. Command calls themselves are outputted if they were invoked without any arguments (popd, ls, etc).

Example, unzipping a file and moving the archive to /tmp:

$ unzip
$ mv /tmp

In the mv command, the archive name was outputted by pressing ESC+. (full command being mv (ESC+.) /tmp) There was no need to type the long archive name twice.

The argument is taken from your bash history. You can keep invoking ESC+. to cycle back through all your recent command arguments. (history -c to clear)

Try not to forget this; You’ll naturally find plenty of uses for it.

Another way to avoid re-typing commands is CTRL+R. It will initiate a search of your command history. Begin typing, and watch Bash try to complete your command from previous ones you entered.

Command Getting Too Big? Send it to your Editor

Sometimes you begin writing what you think will be a simple command, only to realize that it has grown too complex for the command line, and you wish you were in your text editor.

First make sure your default editor is set. This is either in $EDITOR (export EDITOR=/usr/local/bin/vim) or elsewhere depending on the distro.

Use “fc” to open the last executed command in your editor:

ls -paul --sort=size
... ls output ...

Now the ls line will be open in your editor. But what if you hadn’t executed the command yet? No problem. You’re sending off an email, but quickly realize that the command line isn’t ideal for everything:

echo -e "Dear Santa, \n\n\tIt has become evident that your fat ass is contributing to Global Warming, primarily due to the large quantity of coal you distribute annually. We hereby

No matter where you are on the line, hit CTRL+x, CTRL+e to invoke your editor, which now contains what you were typing on the cmd line.

I always find myself wanting to finish a command in vim, but unwilling to type the first few lines over, especially when I’m trying to write a for loop or any ugly multiline Bash code.

IMPORTANT: Whatever you type in your editor is executed automatically after you quit the editor.
Continue reading Bash Tips for Power Users

Do You Keep Old Programming Books?

Photo by ailatan (flickr)
Photo by ailatan (flickr)

I knew HTML and learned ActionScript (actually ActionScript wasn’t out yet. Flash only had basic scripting support) , and around 1999 I wanted to learn Javascript. I ended up getting a book on Java, thinking it was Javascript. It didn’t take more than a day to figure out they’re completely different languages, but for some reason, I kept the book anyway. $30 was a lot of money at the time. I could of bought a used Playstation game, or saved it towards what would become the greatest console of all time, released 9/9/99. But – the book will be useful eventually, I told myself, and with that, on my bookshelf it went.

Today I walked by my bookshelf and there it was: Teach Yourself Java. The last time I opened this book was the day after I bought it, sometime in 1999. Even if I keep it, if I’d like to learn Java now, I would buy a new book anyway.

A lot of us keep books. Seeing our library physically grow feels good, even if we haven’t read most of the books in it, because we will eventually, right? Keeping reference books is one thing (though I never use mine, what with cheat and all) but most books should be traded or given away. Technical books especially, not only because they’re expensive, but because unlike novels and most other types of books, they become obsolete. But unless you seriously plan on re-reading them, even books that are cheap and timeless should be traded or given away.

Who doesn’t love a book fair? or going through a big box of books in a garage sale? If we all horde books, who would keep this circle going? So what can you do with your old books instead?
Continue reading Do You Keep Old Programming Books?

4 Do-It-Yourself Whiteboard Alternatives

Whiteboards are as useful as they are overpriced. I built one using tileboard (the thing they use in bathrooms), and I highly recommend making/buying one. It took me awhile to find tileboard in my area. In case anyone has the same problem, here are 4 alternatives I considered:

They are not in any specific order.

Glass or Plexiglas

Anything Expo markers can write on may be used as a board surface. This means a piece of glass, or acrylic glass (Plexiglas), placed over a bright white surface it (i.e., a wall or table). Glass actually works pretty well in terms of eligibility and clean up, but it’s heavy, has sharp edges and cannot be drilled into (easily). It’s also not cheap.

Plexiglas works well, but I heard some dry erase Expo markers have problems coming off. Research this before trying Plexiglas. Never use Acetone to clean Plexiglas (or any plastic).

Plexiglas might be a hassle to cut. Sawing at a high speed, be it power or manual, might cause the edge to melt and stick back together between each cut. It’s usually cut underwater ( don’t try putting a power saw in your bathtub).

What I did was use a regular hack saw, and had my friend shoot the area I was sawing with a water gun to cool it between each cut. A water gun.

Both glass and plexiglass have the advantage of letting you make overlays (assuming they are translucent). You can put anything behind this board, as opposed to having an all white surface. Some examples I’ve seen are adding templates like a blank calendar or checklist behind the glass.

If you put some work into it, this can be a nice, cheap setup.

Chalkboard or Chalkpaper

Chalkboards are cheaper than whiteboards, and even cheaper if you go the DIY route and make one using chalk paper. Chalk paper is basically a rough surface you can buy in rolls, which can be written on using standard chalk. Which means.. hopscotch in the office!

Chalkboards have great contrast, and chalk is dirt cheap compared to dry/wet erase markers (unless you steal those from your local college). The problem, and it’s a big one, is chalk dust. Chalk dust in a small room or office make this route unacceptable for most people. There is “anti-dust” / dust-free chalk, but dust can still be a problem if you don’t have good ventilation.
Continue reading 4 Do-It-Yourself Whiteboard Alternatives

Burning Xbox 360 Games on Linux (Stealth!)

You could run ImgBurn in Wine, or probably burn the games in VirtualBox running Windows, but that’s no solution… you’re reading this because you want to burn Xbox 360 games on Linux using native tools. It’s surprisingly easy!

The games are usually an ISO file, along with a little DVD (.dvd) file that tells the burner to use a layer break value of 1913760. This file is not necessary in Linux (or Windows) as we will be telling the app to use that break value explicitly.

I will go into detail on how to setup what you need. If you’re impatient, you might wanna skip the setup and jump straight to the quick recap.

Extract the ISO

cd /games/360/GameX
rar  x kfc-gamex.part01.rar

If you don’t have rar (“winrar”) installed, lookie:

The program 'unrar' can be found in the following packages:
 * unrar-free
 * unrar
Try: sudo apt-get install 

you can also DL it from

Now we need to see if the game is stealth/valid. This is done using an app that runs natively on Linux (and OS X) called abgx360.

Install abgx360


Download the tar.gz files from The TUI is nice. Don’t bother getting the GUI for abgx360.

tar -zxvf abgx360-1.0.0.tar.gz
cd abgx360-1.0.0/
./configure && make
sudo checkinstall -D

(You may use ‘make install’ but this is not recommended on Debian/Ubuntu. checkinstall keeps your shit organized.)

If ./configure fails with an error about wx-config/wxWidgets, make sure wxWidgets is installed..

apt-cache search wxgtk2 

and make sure wx-config is in your PATH. On Ubuntu Intrepid, it wasn’t. Find it and make a symlink to something in your path.. i.e.,

locate wx-config # (finds it in /etc/alternatives/wx-config)
sudo ln -s /etc/alternatives/wx-config /usr/bin/wx-config

Rerun ./configure/make/checkinstall

If you downloaded the local database (abgx360-data) from the site above, install it now; Just extract and move the .abgx360/ dir into your ~/

Checking ISO CRC/SS – Is the game stealth?

abgx360 -af3 kfc-gamex.iso

the af3 flag will automagically fix/patch the ISO should it encounter any problems.
What abgx360 will do is check the ISO’s CRC against an online (or offline, ~/.abgx360/) database. It might begin by updating its database. If this is a problem (no net connection), pass it -localonly

When that’s done…

Burning the ISO Using growisofs

Making sure the dual layer DVD is in your drive, run the following command:

# growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760  -dvd-compat -speed=4 -Z /dev/burner=kfc-gamex.iso

I commented it out so you don’t execute it trying to paste it. Let’s look closer at this command…

The break:1913760 is the layer break, which you’ll find in the .dvd file. If for whatever reason you can’t check the .dvd file, just use this value.

Set your speed to something low. Some say 2.5x but I have no problems burning at 4X (my max is 8X). You don’t need to know the lowest speed your burner can go. Just set it to 2-4 and you’ll be fine.

Set /dev/burner to your own device. It’s probably /dev/scd0, /dev/scd1, or may already have a symlink like /dev/dvd6 /dev/dvd etc..

Try grepping dmesg to find your device. i.e.,

dmesg | grep "LITE"

This might give you some information but probably nothing too helpful:

sudo dvdrecord -scanbus

To see if you have the right device, try ejecting it.

eject /dev/dvd6

Set the kfc-gamex.iso to whatever the name/path of your ISO is (case sensitive of course).

Now I usually begin with a dry run. By passing -dry-run to growisofs, it will proceed as normal but quit before writing anything to disk. Actually, it kind of just spits out a command and dies. Awful design! i.e.,

$ growisofs -dry-run -use-the-force-luke=dao -use-the-force-luke=break:1913760  -dvd-compat -speed=4 -Z /dev/burner=kfc-gamex.iso
Executing 'builtin_dd if=kfc-bh5.iso of=/dev/dvd6 obs=32k seek=0'

So the above is good. Now remove the -dry-run flag to proceed with the actual burn.

growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760  -dvd-compat -speed=4 -Z /dev/burner=kfc-gamex.iso

Find something to do, or just stare at the screen. After about 20 minutes (at 4X), you’ll see the burn end successfully with output like this:

 7798128640/7835492352 (99.5%) @3.8x, remaining 0:06 RBU 100.0% UBU  99.8%
 7815495680/7835492352 (99.7%) @3.8x, remaining 0:03 RBU  59.7% UBU  99.8%
 7832862720/7835492352 (100.0%) @3.8x, remaining 0:00 RBU   7.9% UBU  99.8%
builtin_dd: 3825936*2KB out @ average 3.9x1352KBps
/dev/burner: flushing cache
/dev/burner: closing track
/dev/burner: closing disc

You’re done!

Quick Recap

Assuming you installed all the dependencies above, here’s a quick recap of what needs to be done to burn a game.
It really takes about 1 minute to begin the process. Write a shell script if you like.

rar x kfc-gamex.part01.rar # Extract game ISO 
abgx360 -af3 kfc-gamex.iso # Checks if rip is valid/stealth/ss patched
growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760  -dvd-compat -speed=4 -Z /dev/burner=kfc-gamex.iso
eject /dev/burner # When burn is done, eject & play. 

Blackberry Bold 9000 vs Curve 8900

Phones aren’t something I’ve been into, and not something I ever wrote about (or ever planned to), but I feel this post will be helpful to many people choosing between these two devices, and out of all my sites, I feel this is the most relevant one I can throw this post up on. I’ll  primarily stick to the main points I noticed, and on practical use, rather than on the specific technical differences between each Blackberry.

Hard choice, but comes down to two points. Do you really need 3G? and are you willing to switch carriers or do you want to stick with your current one?

The Blackberry Curve 8900

Build / Form Factor

It might not be noticeable in the pics, but the 8900 has a much better build than the Bold. The  device is physically smaller and more comfortable to carry with one hand (the Bold must feel like a classic Gameboy to people with small hands), letting you type with one hand comfortably.
The trackball is solid and much more accurate than the Bold’s, which feels flimsy and feels worn out after a few days. If you have a bold and hold it up to your ear and keep tapping the trackball without actually pressing it down, you’ll notice it makes a sound kind of like the sound your keyboard makes when you tap it without actually pressing it down. This isn’t much of a problem and not something I notice in practice, but it does feel cheap. The 8900s also feels perfect at the default sensitivity (70).

The keyboard buttons are raised higher than the bold and are physically separated. The keys aren’t as slippery and it’s much harder to mistype. They also feel ‘heavier’ and nicer to push overall. Having the numbers in red on the 8900 (all white on the Bold) is also a nice touch, but while I prefer the 8900’s keyboard, I have absolutely no problems with the Bold’s after getting used to it.

RIM definitely took issues present in the Bold into account when designing the 8900. The right convenience button (camera by default) on the 8900 must be pressed down harder and held down longer before the camera application is invoked. This gets rid of the annoying “could not start camera” error or pitch black pictures of your pocket that occur when the camera shortcut key is pressed down accidently on the Bold.

This might just be me, but on the Bold, my index finger tends to naturally get in the way of the camera when I’m taking pics. I need to be aware of it and intentionally keep it out of the way. This doesn’t happen on the 8900. Speaking of cameras… Continue reading Blackberry Bold 9000 vs Curve 8900