Coding in your sleep.

Pithy words of wisdom, often appear mundane. So I’m going to be quick. The secret of successful coding is sleep.

I recently found myself in the hazardous situation of having too much work booked at the same time. My post-summer holiday bank balance allowed me to become seduced by the dark side. I counted that twilight world after 1:00AM as a friend. In reality the hours between 1:00 AM and 5:30 AM are cruel and the full of mischief. Time becomes distorted, decisions become unreliable. The walls between illusion and reality become a thin and fragile membrane through which errors of judgment can seep. When coding this can be dangerous. Sometimes it results in the odd harmless typo, here and there; easy enough to correct. Sometimes, it can lead to a full fledged haemorrhage.

It strikes me that our culture doesn’t much like sleep. I spent a few minutes trying to find pro-sleep quotations on Google and yet from the greatest minds and thinkers throughout history, it seems that sleep is rarely given the credit it deserves. Most references appear to offer the opinion that the fool / peasant sleeps while the genius works through the night. I remember hearing a labour politician talking admiringly about Tony Blair’s work ethic, indicating how impressed we should all be in the meagre two hours sleep Tony allowed himself when he was Prime Minister. Is this a good thing? Oh the irony, of John Prescott sleeping like a baby during a health debate at the Labour Party conference in 2005.

We all accept that healthy minds and bodies depend on a good night’s sleep and yet how often we feel compelled to push ourselves beyond comfort into late nights and fatigue.

Whether it be a result of capitalism or some kind of “propaganda without portfolio”, the reality is obvious. We cannot think clearly without sleep. Not only does our productivity and efficiency drop to very low levels as the night wears on but we are often robbed of the following day as well.

I almost lost a good client, not because I couldn’t do the work or deliver it on time, but because I was too knackered to programme properly.

So the next time you find yourself burning the midnight oil remember that a lot more than a deadline may be at stake. One all-nighter can ruin a week and if you are unlucky enough like me to have spent a week from hell vainly trying to repair the damage caused by decisions made during such a session, be warned, you may loose a lot more than sleep if you persist in burning the candle at both ends.

Flash on the iPhone

There may be times when it is essential that a Flash animation is available to users on Apple devices such as the iPhone and the iPad. Here is a technique that addresses this requirement using Google’s rather wonderful open source project Swiffy.

Firstly, your Flash movie should be no larger than 1MB and ideally exported for Flash Player 5 although Swiffy supports most of the AS2 specification. For those of you who don’t remember, you can do a great deal with Flash 5 and AS2. Probably a great deal more than Safari on the iPhone will allow us to do.

Under the hood, Swiffy processes the SWF file and generates a JSON file. A client-side JavaScript runtime loads that JSON file and renders it using HTML, SVG and CSS which is supported by Webkit-based browsers such as Safari running on Apple devices.

When you process your swf, Swiffy outputs an html page that you can place on your page using an iFrame. I know, I know an iFrame! However we’re only using our iFrame to serve alternative content to less than 5% of our visitors. There’s nothing for Google to index so it makes very little difference to the end user. I’ve added an alternative version to the header of this page, making the animation, podman cursor follower and all, viewable to iPhone users, for what it’s worth. It’s pretty clunky, probably only making 8 frames a second on my iPhone, but it’s a pretty complex multilayered animation, with lots of bitmaps and transparency. While the animation in the header of this page may not have been designed for WebKit, it could probably be optimised quite easily. A little trial and error goes a long way. Maybe I’ll follow this article up with a sequel.

Montage of motion

Here’s a montage of some of the After Effects, Motion, Combustion stuff I’ve done. I’m sure if Warren Zevon were still alive he’d be okay with me using Werewolves of London as a backing track.

Installing an SSH key

If your developer passes you an SSH bundle containing a couple of files to give you access to a web server.

webSSH.pub
webSSH

Don’t panic.

Open terminal type:
open ~/.ssh

drop the files into this directory.

Back in terminal type:
ssh-add ~/.ssh/webSSH

Now you can type:
ssh root@xxx.xxx.xxx.x

Voila!

Joomla! Install: Display Errors: On / Off

This one always catches me out and I find myself looking up the same thing time and time again. So for future reference I thought I’d make a note.

When you install Joomla there’s an setting check that lists any problems with your set-up that may effect the running of Joomla! In my case (both on 1&1 AND on MediaTemple) the Recommended Settings have flagged Display Errors as “On” when it should be set to “Off” – The solution is pretty simple.

Open the htaccess.txt file installed with Joomla! add:

php_flag display_errors “0”

save it to your server and rename it .htaccess

Voilà!

My Flash strokes look blurry.

This is a tip that I’m sure most people who’ve used Flash will appreciate.  Try drawing a few strokes on the stage – all a pixel thick. They may look fine and dandy in the Flash IDE but try exporting the swf and prepare to be shocked. There’s a fair chance that one, some or all of your lines look blurred and fuzzy. How annoying!

Well here’s a few things you can try to ensure that your strokes remain crisp and perfect, just the way you intended.

First, check the X and Y co-ordinates of your strokes and round them up or down to a round number.

If things don’t improve go into your stroke width setting and change the number from 1 to 0.9

If thing’s still don’t improve try reducing the width of your stroke incrementally from 0.9 to 0.8, 0.7 etc.

It worked for me:

I swear that this is a genuine screen grab of the offending lines – before and after.

Good luck!

Glow filter clipping on text.

Ever noticed that a line of text in a movie clip gets clipped by about 3 pixels at the end of the line? Rather an annoying bug, I tried everything, rounding the positioning up to exact pixels, adjusting the glow, checking tweens but nothing worked. I finally solved the problem by changing the font display quality to ‘animation’ instead of ‘readability’ worked fine!

Spam!

I’ve been simply bombarded by spam recently – I had over 3,000 comments in the last 24 hours – none of them genuine. This blog’s pretty low profile and I haven’t spent much time looking after it but it’s up there to help anyone who’s interested. If you arrive here and find anything interesting please comment good, bad or indifferent, it’ll be such a refreshing change.