Archive for January, 2011

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 jQuery.com.” 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"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
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"
 src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>

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 neversaw.us. 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…

Augmented reality translator


13 Jan

Augmented reality translator in actionFabulous! Take a look at this. Welcome to the future.

Choose your weapon


12 Jan

What CMS do you use ? What CMS do you want to use? Compare them here.

Database version control


12 Jan

I’ve been breaking my brain for some time now thinking about how to incorporate database changes into version control. Here is a helpful article that addresses database structure version control. However the question of how to apply inserts in the production database with complicated record relationships is not addressed. Consider a CMS with a highly productive production environment. It is unreasonable to require all the authors, photographers and even editors to participate in version control, it’s hard enough to get some programmers interested! Unless some action is taken the database key values in the development and production environments will diverge.

If it is acceptable to prevent modifications to the production environment for the duration of the release and deploy process then the solution comes down to just doing the work. This is unfortunately not always the case.

When it is not acceptable to lock down the production environment for the duration of the release and deploy process then a differencing tool is required that understands the semantic relationships in the data and can apply the deltas to the production tables with respect to those relationships. I’ll be looking out for such a tool and if anyone knows one please post it here.

Time to start the list of lists


10 Jan

Daniel Raffel’s Favorite New Geek Stuff Of 2010

Stuart McFarlane

Mobile Media Constructs