Archive for the ‘Development’ Category

GIT command line coloring

17 Jan

PS1='\[\e[1;32m\]$(__git_ps1 " (%s)")\[\e[m\]'
PS1="\[\e[1;36m\]\h:\W\[\e[m\]$PS1\[\e[1;36m\]> \[\e[m\]"

Mobile html5 compatibility matrix

14 Sep

Here is a list of html5 features and their implementation status on various mobile devices

On version control, automated builds and continuous integration and web development

14 Feb

Most web developers don’t know the first thing about version control. That’s probably not entirely fair. They’ll download the latest version of their CMS, plugins, extensions and whatever from GitHub or even from some subversion repository. But ask them if they keep their own code in version control and you’ll  probably just get a blank stare. When I started in the this branch I was initially shocked to see my mentor editing a live site online. Well I got over that, put on my new cowboy hat and got down hacking out code, throwing at a server and forgetting about it.

But recently a client stated that they wanted their new TYPO3 website to done just like their java based sites with version control, automated builds and continuous integration.

Version control

Quite liberating really. I mean really, what’s all the fuss about? Pft. There are backups of the live site (well if I host them there are). If you have to work further on the site you can just tar it up copy it to your development machine and get cracking on the new code. Most of the time we are coding alone so there is no need merge our code with that of another. If the changes are significant then we can just make periodic backups of the work in progress… Ah. That last point. Periodic backups of the work in progress. That’s actually a good reason to use version control. That’s actually what you are doing by making backups.

By using formal version control you get all sorts of tools to help you track your changes, retrieve versions that did work (if you lost the plot after coding a bit too deep into the night), compare files and all sorts of other handy things. The thing is that lots of people do this every day and some of those people have thought long and hard about how to provide general and effective solutions to problems related to version control.

Once you’ve got your sources into a subversion or Git repository and you’re happily making branches, commiting changes and merging back to the trunk you might want to think about an automated build process.

Automated builds

Automated build scripts define the process required to convert your source code to a working deployable program, website or whatever other deliverable software. I like to use Apache Ant for build automation. There are other tools and you can read all about them here.

Now I have to admit that the build process for a website written in PHP is more or less trivial. The source code is all ready to run. If you really want to knock yourself out you can let your build produce a tar but that’s about it as far as building is concerned. There is nothing to compile, except maybe minify some javascripts and remove whitespace from stylesheets but that’s really about it.

On thing that an automated build really helps with configutation management. If you have factored out all the configuration in yours site then you can incorperate the application of the correct configuration into your build process. That means that you can isolate the configuration of all your environments into one file (or one set of files) and chose which configuration set to use when running an automated build of your site.

Continuous integration

Once you have version control and an automated build you can hang it all in a continuous integration environment. A continuous integration environment runs in the background or on a dedicated machine and performs a build based on some trigger. It can be used manually by using the build now button. If can be confugured to run periodically to produce a nightly build for example. Or it can be configured to run whenever changes are committed to the version control system.

Using a continous intergration environment is a nice way to glue your version control, build scripts and configuration management together to produce hassle free repeatable build results.

Selected tools

I’m using Git for version control, Apache Ant t for my build scripts and Hudson as my continuous integration environment.

On version control, automated builds and continuous integration

Test your browser’s HTML5 support

02 Feb

Busy busy busy. New contract at the BKWI for four months building a large TYPO3 site, a little bit of work still to do on AHK’s Beroepkunstenaar, couple of weeks work still to do on the 9-box iPhone app, new site for Casting Consultants v2.0, WordPress site in exchange for a photo shoot… Not much time keep up my blog and pet projects 🙁

Oh well. No rest for the wicked!

Anyway here is a link to a handy site that will check the HTML5 support of your browser.

Old school meets new school

21 Jan

Here is blog post from what looks like a twitters developer. He’s telling us to be careful when adding event handlers for events that can fire a lot (like window scroll). The problem is that if you load up the event handler with lots of code then the system will become unresponsive because the event is fired too often.

If you have ever written a device handler (once upon a time you may have written a mouse handler just for fun) then you will know that in your interrupt handlers you should do the absolute minimum (like saving the mouse x and y deltas and nothing else). Then on a timer (or even better when when mouse coords are queried) you should do the CPU intensive(r) processing.

I am pleased to see that these old school skill are being invented by the new school programmers.

Google CDN

20 Jan

I often find myself writing the following

<script type=”text/javascript” src=”/js/jQuery.min.js”></script>

and thinking, “this is silly, why don’t I fetch it from” Without really having a good reason to choose either way I just kept on with what I knew, “if it aint broke…” right? Well today I came across this article and now I do have a reason to change my ways. Ok, ok, I’m a bit slow maybe (the article if from 2008) but better late than never.

<script type="text/javascript"
This is better for two reasons. 1) My server doesn't have to do any work to provide the file. 2) As more people use this method the chance that the file is cached increases, with a bit of luck jQuery will already be available on the client.

A follow up article on the same site makes it clear that there are are a few gotchas and explains how to handle them. Particularly the effect of using http: links in https: pages. Turns out that if you exclude the protocol specification in the link URL then the browser’s underlying protocol will be used instead.

<script type="text/javascript"

Then I started to wonder what other javascript resources were lying about Google’s CDN. Here are Google’s own contributions and here are some third party libraries like jQuery. Take a look at Google’s visualization library, I am particularly impressed by the suggestion that Google docs spreadsheet can be used as input for a visualization! Bit of a shame that it embeds a flash object thought :/

CSS background image hacks

19 Jan

All pretty obvious stuff but here’s a concise article about the ins and outs of using image sprites.

Things to do…Check out appcelerator

19 Jan

No time to check it out now. Might be interesting. I suspect it is a HTML5/javascript development environment with browser bootstraps for each target device but a colleague suggests that it’s a C++ environment. I’ll have to download it and check it out before I start on my next mobile app.

Javascript best practices

18 Jan

Well I guess if I’m going to write any code then I should write it well. In an attempt to address my aversion to using javascript to do anything more complex than mucking about with the DOM and spicing up the interaction layer I’ve been looking around at how other folks are doing it.

Many of the blogs, discussions and  articles I found had a lot to say about old school client side javascript but that’s not what I’m looking for. I did come across this article on It discusses javascript best practices in a server side context and address one of my javascript bug bears. Specifically “what is this“, meaning what is the this that is currently in scope and how can I write my code so that this will be what it to be? By using the bind method when returning functions or passing functions as parameters the context in which they are called (their this) can be determined.

My mistrust of javascript as the sort of language you would want to do complex things with has decreased a little. In my next post I hope to describe the tools and environment needed to solve my pet problem described in  this article.

Server side JavaScript – what’s that good for then?

17 Jan

I used to hate Javascript. All those ugly unreadable DOM manipulations based on getElementById. Yuk.

But then I discovered jQuery and javascript was suddenly not only usable but also fun. I haven’t implemenbted a website since then without using jQuery. There are a few jQuery plugins that I regularly use, typically sliders, calendar clickers, that sort of thing but the real fun starts with coding up your own custom DOM manipulations and interaction layer bells and whistles. In the beginning I would pack all the code into $(document).ready(...) but these days I typically try to generalize the functionality and write a plugin.

But what’s all this fuss about server side javascript? Is it really a language that you want to use to create complex software? I’m not so sure about that. We’ll have to see. Despite my reservation about the prospect of using javascript to implement complex software I have an example where the ability to use in a server environment is at the least helpful and possibly essential.

Recently a collegue asked me to help him a with a problem he was having with a web scraping backend component. Certain information was being scraped form another site that was protected by a login. He had an account on the site so that with a bit of curl and a cookie jar he could fetch the information to incorporate into his own site. The problem arose when the site in question started using a login form that had a session specific identifier that was generated using jQuery after the page was ready. So the curl output did not contain the login form with its session specific login identifier and his POSTs to the login form’s URL were being ignored. This is where server side javascript comes into play. If I can run the DOM manipulation contained in the javascript in the page (and in linked js files) then when all is done I’ll have the login form with session specific identifyer that I need to make the login request.

Now that I think about it the session specific identifier probably comes from an ajax call. All I really need to do is find the call in the page’s linked js files and duplicate it with a curl request and I’ll have everything I need. Ignoring this (probably better) solution I’m going to press on and see what it takes to get jQuery (or whatevery other client site library, mootools, etc) running on a server.

Stay tuned for the next installment…

Stuart McFarlane

Mobile Media Constructs