Here it is.

Coding, Humans and where it all goes wrong.

8 randomly useful php tricks

In keeping with my series of 8’s.

1 ) debug_print_backtrace() - I use this one a lot, print a debug-style list of what was called to get the the point where this function is called. Very, very useful.

2 ) __autoload() – Called when you attempt to load a class that hasn’t been defined. Example: I try load class xyz, the class has never been imported, I use the autoloader to attempt an import of xyz.php. Probably not the best technique for readability or clarity in code, but has it uses.

3 ) ip2long() - Don’t store IP addresses as strings on a db use this to store them as a long.

4) __toString() – If an object is ever used as a string, you can define what’s returned here. Again you can find it’s uses once you realise these things are possible. :)

5) get_browser() – Easily get your hands on the users browser-type. Some leave this process to the browser end but can be useful to get this info server side.

6) More of a total dirty hack(come on, it’s PHP). Having problems with that annoying ‘headers already sent’ error. Don’t bother to fix the underlying problem, just omit the closing php tag! It’s totally valid(this list is really becoming things I hate about PHP….)

7) natsort() – This will sort lists of things in ways humans will understand. Good idea when displaying drop-down lists etc for users. Again, you might find a use. :)

8) metaphone() – Again one of those random things PHP does, you may never use this but this will return how a word sounds. EX: Bomb->BM. Might be useful for comparing words that sounds similar, this one’s really obscure and I honestly haven’t actually found a use for it yet. :)

Take a look at the PHP magic methods for some other ideas. :)

Top 8 Vim Plugins

vim-plugins-surround-vimWhy 8? Because after much tidying I figured out there’s 8 I only use. :)

1 ) CheckSyntax – Check the syntax of the current file. Handy it automatically runs on save.

2 ) SearchComplete – Type part of a variable name, press tab and it will auto-complete the name.

3 ) MatchIt – Extends % with more than going to the matching brace.

4 ) Project – Allow managing of source folders, sorta like an IDE.

5 ) Surround – Delete, change and add surrounds(XML tags, bracket, quotes etc) with ease.

6 ) TagList – Using exuberant ctags it provides an overview of your source code structure.

7 ) SuperTab – Provides better tab completion.

8 ) Get Latest Plugins – Possibly the handiest of them all, :GetLatestVimScripts and all yours scripts are up to date(after some configuration).

Top 10 webapps for programmers

1 ) Evernote Evernote_Icon_256


Although I use evernote as my brain online for everthing, it is incredibly useful for programmers too. Where I work things like requirements can be captured on almost anything, so snapping photos of whiteboards/notepads/beer mats that become OCR searchable is very handy. On top of that it’s nice to have all notes auto stored up on the web(I’d have a fit if I lost my developer diary over a hard drive crash). The client application for evernote could be better and I’d consider Microsoft’s OneNote a much better application but Evernote does everything I need it too. The killer feature being the iPhone app that lets me capture text, voice and snapshots everywhere. Coupled with JotNot it gives me a very powerful information capturing device that I simply cannot live without. This is one of the truly killer apps for my iPhone.

dropbox-icon2 ) Dropbox

Why does my hard-drive always die the evening I forget to push my code up to the git server? Store all code/config files/documents up on a server always. The benefits are stupidly obvious. It’s soon after this realise you can start adding free little tricks that you didn’t think possible. See my previous example for why dropbox rocks for vim/linux users. Another plus, I don’t have a static ip with my broadband at home(dyndns doesn’t work due to my isp’s infrastructure, a massive mesh NAT) so here’s a cool trick for easily torrenting(or in my case usenetting) files remotely. There’s also something very nice about being all to pull up any of my important files anywhere there’s a web browser.

gmail3 ) Gmail

Yes it rocks, despite Buzz.. Filters, label and keyboard shortcuts have made this such an obvious choice it’s not even funny. I’d almost forgotten to add Gmail to the list it’s become such an integrated part of my web-use. The programmer related benefits are dissimilar to general user benefits, but thing extended features like keyboard shortcuts etc I probably only of real benefit to the techies who are the only ones bothered to read up on these features. Other than that there’s little to say, odds are I’d mostly be preaching to the converted anyway.

stackoverflow_glossy_14 ) Stackoverflow

Not exactly a web-app but something most programmers cannot live without and it’s web-based. Arguably this could be number one , but personally I don’t use this resource as much as the above three. Have a programming question, odds are insanely high it’ll be answered here.

google-reader-logo2

5 ) Google Reader

We’ve all got to keep up with the lastest developments in our industry. This is simply the easiest way to do it. Some good subscriptions: Coding Horror, A list apart, trivium, proggit and Bertrand Meyer’s blog. Also reader has a new feature that supports updates on sites that don’t actually support RSS(some might question the point in RSS with features like this….). This feature’s very handy for one of my favorite programmer sites.

mindmeister6 ) Mindmeister

I use a hell of a lot of mindmaps for storing programming related knowledge. Almost every technical book I read has mindmaps associated. I like building mindmaps, it forces me to have a 2nd thought on the content I’m reading and I have a less painless way of reviewing what I’ve read. To be honest, mindmeister as an application isn’t perfect. It doesn’t have folders or any decently readable way of labelling mindmaps. Very annoying when you’ve got tons of mindmaps to sort through. I’d love to say that the fairly expensive iPhone app makes up for this(not sure why it couldn’t be free considering it’s a subscription based service), but the app for me is almost worthless. There’s nothing wrong with the app in itself it’s just not a pleasant experience browsing/editing mindmaps on your iPhone. It seems like I’m singing the praises of mindmaps over mindmeister itself but other than these few issues mindmeister is a solid application. As it’s online sharing mindmaps is also a very handy feature. See here and here for examples of how I’ve used mindmeister. But if sharing/accessibilty anywhere doesn’t matter to you I’d recommend something like FreeMind for all your mindmapping needs, even keeping your local mindmaps synced on Dropbox could suit you just fine.

p-42b9e7e9be3e48c59d15b6cada841494-large-10007 ) Pinboard

Pinboard is a very nice online bookmark storage. Very, very simple bookmarking/to-read lists, fantastically simple tagging features and the ability to add bookmarks from emails makes this a great service. I keep all my tech articles up on this service. For an extra charge all my bookmarks become archived, meaning if I bookmark a site using pinboard and the site in question goes down the page is still accessible from pinboard forever. I could do the same using archive.org but having this feature included in a bookmarking service really makes sense. On top of that adding bookmarks from google reader, twitter, instapaper and delicious really adds to the service. Highly recommended bookmarking service for techies.

remember_the_milk_icon8 ) Rememberthemilk

Remember the milk takes the simple idea of todos lists, adds a set of complex features(due dates, repeating tasks, tagging, folders, sharing and a lot more). Adds in the ability to add tasks from almost anywhere. IM, email, phone(if supported), widgets for almost anything(including gmail), and many apps that support it(tasque/gnome do for linux or a dashboard widget for osx) and you’ve got RTM. Yet the application itself never gets bogged down in it’s complexity. ‘Buy milk today’ or ‘Buy milk tueday’ or ‘Buy milk tue’ or the many other variants of dates and rtm will likely be able to parse a date out of it. Other nice little tweaks like this makes RTM a great application for the programmer, as I mentioned in books like Passionate and Pragmatic Programmer Programmer there’s a lot of  ’Act On It’s’ some of them have different contexts, for example I might need to do a task weekly at home or do a task everyday in work. Using RTM to handle the adding of all these tasks makes things a lot easier. I also use the pomodoro technique with RTM, using the tagging features I add estimates to my todos (e1,e2,e3) via tags. On top of all the other programming related todos I intend to do(including this post!) this service has made life a lot easier.

grooveshark9 ) Grooveshark

It’s up for debate whether programmers should listen to music at work or not. Personally I find music listening to music fine when I actually have to code, but when it comes to creating a specification or stepping through code listening to music is a very annoying distraction. When I do listening to music I always use grooveshark. The UI leaves a lot to be desired but there’s a music selection that’s 2nd to none, the playlists are handy too depending on the mood you in. Feeling tired in the morning? I have a wake-up playlist. Need some background music, there’s a playlist for that! All very painless.

nsm10 ) NutshellMail

NutshellMail is a service that combines twitter, facebook, linkedin and myspace updates into a single email that’s sent to you on a daily basis. I questioned whether I’d use this service when signed up but I’ve come to love this application. I follow a lot of developers on twitter and some through facebook and it’s really nice to know your updates will arrive at a certain time everyday. Instead of jumping on every few hours, negatively impacting on my productivity, I have a focused time to get myself updated on all the latest trends. The linkedin support is handy too for keeping up to date on your professional news also. I could have added twitter/linkedin to this top ten but at this stage I think these websites go without saying(and they’re not exactly web applications in the obvious sense).

Sync config files over dropbox

dropbox-iconOne of the many reasons for my love of linux is the idea of keeping config information in simple texts files in the home directory of each user. It all very painless. And now with Dropbox I can have a set of application configurations stored via the web.

Using dropbox add a folder(I’ve called mine dotfiles) and add in all the useful config files you have.

For me it’s my

.bashrc (sets up environment stuff, can be iffy with multiple machines however)

.bash_aliases (sets up all my command line aliases)

.vimrc (my vim configuration)

.vim/ (my vim plugins and documentation)

.muttrc (my mutt config)

.screenrc (my screen config)

.irssi (my irssi config)

Move all the files you wish to sync with Dropbox into your dotfiles(or equivalent) folder then simply:

1) cd ~

2) ln -s /home/username/Dropbox/dotfiles/.bashrc

And bingo! Your bashrc files is now synced over Dropbox. Any changes you make on your current machine will be propagated over all machines use this Dropbox config and visa-versa. On top of that the prospect of maintaining profiles over multiple machines become a lot less painful. Even setting up a new machine is handy. Setup your os, download dropbox, execute ln -s a few times and you’re done, and this can be extended to any application that supports these plain-text config files. It’s really awesome!

Disable jQuery autocompleter cache

For anyone wondering how to disable the autocompleter cache in jQuery(meaning you always poll the server each time a letter is entered).

Simply set cacheLength: 0, in the autocompleter’s settings. Seems obvious but my googling told me never set this value below 1 or the whole thing would explode. Tried matchSubset etc and nothing else worked.

Simple solutions eh?

Php Beautifier

php code

Why?

When you’re faced with an ugly PHP file(or files) with little to do but trawl through it, there is a solution.

Php beautifier is a pear package that will process PHP files and reformat them in a (hopefully) nicer format.

Installation

You can install it using pear with a very simple

pear install PHP_Beautifier

Usage

Usage is pretty dependent on your needs. What’s nice is, it takes formatting rules as arguments, so if you pass in Pear() as an argument your code will be formatted to the pear standard.

Here’s a bash alias I used to fire an entire folder(and recursively through all sub-folders) through the beautifier with the Pear standard coding conventions and outputted to a src2 folder.

alias beautify="php_beautifier -l \"Pear()\" -r \"*.php\" ./src2/"

Or if your using vim here is a mapping to call the beautifier on the current file when Ctrl-F2 is pressed(all my function keys are currently mapped to vim’s xdebug plugin).

map <C-F2> :% ! php_beautifier<CR>

Results

The results are pretty nice actually. The author of it notes that on 40,000 lines of PHP it hasn’t broken a single file. I have noted that it can make certain files look like crap however. An example would be our locales file, that has large array mappings of terms to languages. Unless you’re totally certain your whole project is going to look awesome I would suggest using this on a file by file basis, as I have with vim.

The Pomodoro Technique

Pomdoro PicThe Pomodoro Technique promises to get things done.

I bought a book , basically because it was a GTD technique that came off the pragmatic bookshelf so I figured I’d give it a shot.

Explanation:
To give a very brief explanation of the technique.
You have a sheet with Today’s Todos, each time you do 25 minutes of work towards your todos you mark a ‘pomodoro’ and take a 5 minute break. You then clock up pomodoros everyday.

Then every morning you pick from your activity inventory(an unsorted list of todos), and pick the highest priority tasks, beside each task should be an estimate of how many pomodoros it should take. For example I had estimated 2 pomdoros for this blog post. So when selecting your pomodoros for the day you take your pomodoro average (sum of all the pomodoros you’ve ever done divided by the number of days), and don’t add more estimated pomodoros than your averages. So for example my average could be 11 and I could have 3 high priority tasks each estimated to take 5 pomodoros each, well clearly I would have to add 2 and find a third that only took 1 pomodoro.

Now clearly there’s more to it(they have managed to get several books out of it). What you log all metrics on is called a report sheet, so things I log are completed pomodoros, how far off my estimates were, how many tasks did I fail to do today etc.

How I used it

I fully commited to the technique both at home and at work. So in work I have a large diary and some extra sheets, for my ‘personal’ stuff I use a small moleskine diary to do the job. There have been dramatic results on both accounts. In work I noticed a better structure coming around my day. When people asked me for things I now always delay till I’ve finished my pomodoro(the book explains how to handle interruptions), then weight how important the new task was over what I’m currently working on. I also find myself looking back very satisfied with the work I’ve done for the day, a personal sense of accomplishment. On top of that I like the fact if anyone did ask ‘what did you do all last week?’, I could very easily give a breakdown on what tasks I was working on.

Like everything else discipline is key. I’ve even noticed myself slipping the odd time. Say I finish a task in 20 minutes, the technique calls for 25 minutes of focused work, so you should now focus on how you could do the task better or just improve on the task in some way. This is fine depending on some tasks but some just can’t be done any better. Going to the bathroom also becomes an interesting game as if you need to go to the bathroom you should cancel the pomodoro, very annoying when your bursting to go 22 minutes in. But you do begin to relish maintaining an average of sorts. It’s something you work towards and try increase.

It’s flexible!

Now however a problem has become apparent and this is where the flexibility of the technique comes in. As a programmer I noticed a ‘flow’ that stops as soon as the timer does(that’s the point), I’ve noticed 25 minutes is not nearly enough time so, as a compromise I can now alter how my pomodoro works. For this week I’m going to try 2*25 minute programming pomodoros followed by a ten minute break. I could increase the time of the pomodoro itself (say 25 to 50 minutes) but I’d rather keep it 25 (busy work such as replying to emails etc doesn’t take 50 minutes).

Kaizen

In essence the point of the technique is not the 25 minute burst is actually something called Kaizen, meaning make small improvements everyday. The constant reviewing of priorities and the daily review of work done is the real value in this technique. I find measuring metrics on your own productivity very powerful. If I find I’m doing more with 2*25 minute pomodoros, maybe I’ll try 4 and take a 20 minute break.

To be honest I’ve actually found more use for this technique at home than at work. With work there is structure to your day and deadlines looming that will always motivate you. At home that project or that programming language that you’ve wanted to do for months has no deadlines and just doesn’t magically get done. With my moleskine(and calendar reminders) I’ve got a constant motivator to get things done and do them better next time.

I can only recommend this technique for anyone. To get started all it takes is 3 sheets of paper(the activity inventory, the report sheet and today’s todos) and some willpower. The book itself is great and would highly recommend a purchase.

Resources

A decent Online Cheatsheet.

A free book written by the inventor of pomodoro(not the prag prog one I’ve read)

A mindmap I’ve done.

This one may read very strangely and how I do the technique may not work for you, but the hats represent a different ‘focus’ and when my productivity starts to wane imagining the hats works well. I would suggest using the mindmap after reading the prag programmer book.

Enjoy!

Crayon Deluxe 1c or over till 15 of Jan

Crayon Physics Deluxe from Petri Purho on Vimeo.

Basically it’s pay what you want to get your hands on this innovative little game till Jan 15th. It’s a lot of fun for a short while. Though their servers are getting pretty hammered at the moment.

http://www.crayonphysics.com/

Vim!

vim-editor_logo

For a while now vim has been my editor of choice and only up until recently have I began to unearth it’s potential. My reasoning before was that it was so cross-compatible(even working in ssh terminals) that this would always be my go-to editor. Now it’s become so much more! Running regexes across all working files with bufdo, crazy window manipulation and crazy editing tricks have made this editor truly fantastic. I’ve started using wherever possible, even trying out the vimperator firefox plugin.

3 reasons to learn Vim are

  1. Edit text far more efficiently(I as a programmer do this more than a little)
  2. Not look like an idiot by saying you “know” vim then head straight for the arrow keys
  3. The ladies

I felt if I was ever going to learn it I would have to see someone use it. Luckily I found a guy who clearly only has love for VIM. Before I watched the videos I basically knew a couple of shortcuts but still used the arrows key and ‘i’ to do 95% of my work. Things have changed drastically since then.

So I would suggest:

  • Play with vim
  • Watch all of these vim tutorials, a guy who has likely changed me forever!
  • Feel free to use the mindmap I made, I find it easier to traverse quickly over the flat cheatsheet(but that’s just me)

You’ll find yourself working at a slow pace(even slower than normal) but fight through this as the productivity rewards are worth it!

Also it may be a little annoying but add these to your .vimrc to disable the arrow keys, this helped me a lot in using the editor correctly.

You’ll find yourself working at a slow pace(even slower than normal) but fight true this as the productivity rewards are worth it!
Also if may be a little annoying but add these to your .vimrc to disable the arrow keys, this helped me a lot in using the editor correctly.
noremap “”
noremap!
noremap “”
noremap!
noremap “”
noremap!
noremap “”
norema!

noremap “”

noremap!

noremap “”

noremap!

noremap “”

noremap!

noremap “”

norema!

Google Wave Server Admin

Download here.

What it does

Execute commands from google wave on your remote server.

How to set it up

Server End: Simply download and run the python server script, on the server obviously. Note: You need python2.6 or greater, which sucks for a lot of debian users but I need it to be able to kill processes nicely.

Wave End: You have 2 options

Easy option: Create a new wave and add waveserveradmin@appspot.com, then fill in the details required.

Hard option: Download the source from here. Deploy it to your own google app engine deployment and continue on the easy option.

How it works

Using google wave’s api and google’s datastore, when a blip is submitted an xmlrpc request is sent to your server, along with your hashed password for authentication. The python code running on the server is then executed as a sub process and the output is returned. If the server subprocess lasts more than 3 seconds it is killed and that output is returned, I can’t seem to be able to wait any longer before the request times out.

As I mentioned the data is stored on google datastore. All passwords are hashed as soon as they’re entered.

If you need any further details, check the source.

Why

Generating ideas with what you can do with wave mostly. Obviously this script needs locking down to be useful, I’m doubting very many want to run ls -alh from google wave a lot. But if you start extending the code you can write some cool things into waves.

Example: On my server I use a tool called o2sms it allows me to send text messages from the command line for free using my mobile phone operator’s web-account(this tool only works in Ireland however). So for me to send a text message I would type. o2sms sender_in_phonebook -M ‘a message’

o2sms mum -M ‘Hi I am sending you a message’

So with a few changes to my script I can create a new wave add the robot participant and type

mum Hi I am sending you a message

And presto I’m sending texts from my google wave, for free.

Happys Days!

And I’m sure there is a truck load of ideas that can be done around this, the project itself is purely a proof of concept that I hope will generate some cool stuff.

Note:I did this project to learn both python and google wave’s api, so apologies if the code sucks/is very PHPish.