Friday, January 18, 2013

Unit testing JavaScript

I am well used to writing unit tests for java code (although most project managers don't really go for it), but had not come across something decent to do this for JavaScript. QUnit appears to be just the job. I don't think it is just me, but I seem to write pretty badly structured js. Coming from java this architectural stuff is mostly forced on you, but not in js. However once you start to write unit tests for your code you start to think about laying this all out better.
I read through the intro.
Then I read this simplified getting started.
And then I wrote some tests for my own code. Altogether this took me just over an hour. A worthwhile investment. This was of course the point where I realised that my code was not particularly testable. Ah well, I will refactor it from now on with this purpose in mind.
Next off I am going to go through the cookbook as it seems to address some of the issues that I want cleared up before I commit fully to this - things like manipulating the DOM.
Once I have some basic tests running I think I will give grunt.js a spin and see if this is a more practical way to launch and manage these tasks.

Thursday, January 17, 2013

Code Academy

There are a bunch of new online learning tools becoming available at the moment. Some are based around the idea of a university style education (http://www.udacity.com/ and http://en.wikipedia.org/wiki/MIT_OpenCourseWare for example), others have a more hands one goal of teaching you how to program. One of the nice programming ones is Code Academy. They have a short list of courses based around programming. They cover areas like JavaScript and JQuery. They have a nice online editor where you carry out the practice questions. There is a clever engine behind this which allows you to get the answer right in a number of ways - it is not just making sure you did exactly as instructed. Useful messages when you go wrong and the whole thing is gamified  To make the rat brain in us all happy :)
Well worth a try if this is you thing - or if you would like it to be.

Monday, December 3, 2012

Filtering a list of MySql Stored procedures

I used to work with SQL server a lot and got a lot of value out of using queries on the system catalogs to show lists of stored procedures, tables etc. I mainly use MySql now and had not really managed to get this power user feature going. This line pretty much does what I want in mysql:

show procedure status where name like '%image%'

Sort of like a query, but with weird initial syntax. Does what I need it to do anyway.

Tuesday, August 7, 2012

Keeping your hits out of your Google Analytics reports

There is a bunch of stuff written about how to do this. Easy if you have a static IP (what work at home developer does?), doable with a cookie if you are on the old synchronous code snippet for GA, but if you are on the new asynch stuff (recommended) v tricky. After spending(wasting) 3 hours on this I finally just clicked the AVG do not track icon in chrome and unchecked GA. This is a bit of a sledgehammer approach as it switches off GA for all your browsing. Not quite what I was after, but it is more important to me to avoid treading on my GA reports than it is to keep other site owners - and indeed Google -  happy.

Great front end dev tools slides

These slides are from Paul Irish. I thought I knew quite a few front end tools (maybe too many), but this  uncovered a heap more. It took me about 2 hours to watch the associated video and take a brief look at each some of the technologies mentioned. The vid is just over 30 minutes long, so info rich.


Monday, August 6, 2012

Zen Coding speeds up your workaday typing

If you find yourself typing a lot of angle brackets in a text editor as you manually create html, then Zen Coding is a big help. All the details are here.
I have the plugin working on eclipse now and it really speeds things up.
Type div#content and hit tab and the text is replaced with <div id="content"></div>
Obviously a trivial example, but there are many more speedups made possible with this.
There is a handy cheat sheet (well 7 sheets) of hints here.

Looking forward to getting proficient at this so that I can speed up my normal daily editing.

There are plugins for a load of editors besides eclipse. A note for eclipse users: the stated shortcut of ctrl+E does not work out of the box. This is because tab is in its place (handier it is too). I discovered this even after unbinding switch editor (which is also ctrl+E).

Zen coding is just one of the handy hints I got from watching this video from Paul Irish.
http://paulirish.com/2012/talk-tooling-the-webapp-development-stack/
He never disappoints.
Happy coding.

Monday, July 9, 2012

Very handy extension of unique function in JQuery

This is a good post by Paul Irish on how to take existing functionality and amend it. Bit like overloading. I like the way he has extended the unique function in JQuery - which only works for DOM elements and made it work for any type - strings for example.