Wednesday, September 5, 2012

Running QUnit on Save with PhantomJS


I have started doing TDD in my CoffeeScript using QUnit. This is pretty amazing really and it has been making me pretty happy. However there is still the very repetitive cycle of save, switch to a browser run the tests and switch back to emacs. What would be amazing is if I could get emacs to do everything for me. After all I should be able to program my system to do the boring repetitive stuff 

It turns out that this is not even that hard, but it does take several parts. 

First of all we need a browser to run the tests. We could use Selenium (which I rather like actually for other things) but even better would be to use PhantomJS which is a headless browser.

What PhantomJS is is a browser based on WebKit (which is also used by Chrome and Safari) that does not display anything. But you can interact with it via JavaScript. So what I want to do is launch my web page (which is on a local web server) then have QUnit run and return the results. Thankfully the PhantomJS folks have a script do just that in the form of a QUnit Driver. (They also have one for Jasmine if you like that).

So now I can call PhantomJS like this:

phantomjs run-qunit.js http://localhost:8080/test.html

I can have it load up my page and return the results of qunit:

'waitFor()' finished in 407ms.
Tests completed in 222 milliseconds.
80 tests of 95 passed, 15 failed.

It gives me a result like that. Which is nice, it tells me exactly what I want to know, if everything passed or not. So what I want is for emacs to run it when I save a file, to do this I run this bit of emacs lisp. 



What I would really like for future is to change it so that if everything passes it will give me a line
that says "203 tests pass" or the like and if all tests do not pass then it should open a buffer to tell me exactly which tests failed. (Maybe even try to figure out which file the failing code is in to bring me to the right spot to fix it )

Monday, June 11, 2012

Orthonomics: AMI Magazine Article Review: Duped

Orthonomics: AMI Magazine Article Review: Duped: anon426 My editor is Simon St Lawrence who I don't think was around then, but I have also worked with Andy Oram. I have been an O'Reilly fan for a very long time and when the chance came to write books for O'Reilly I jumped at it. Of course I spent 3-4 years making sure that chance would come.

If my career as a programmer is flying now its because I spent the last 5 years building it up!

Monday, December 27, 2010

New Tech paradigm - LN3

So if LAMP is being replaced what is it being replaced with, I think its a combination of these:
  • Linux
  • NoSQL
  • Node.JS
  • NgineX
So what to call it, How about LN3

Saturday, December 11, 2010

Node.JS and the way forward

One issue with many web development languages such as PHP or python is that all IO is blocking. So every time a program goes to the net, disk or database the thread or process blocks. It stops what it is doing and waits until the data comes back from the disk or network.  In a heavily loaded server which is being bottlenecked by disk or network this can result in a great number of processes in disk or network wait states, this is less than ideal when trying to scale.

One novel program that is trying to deal with this is Node.JS. Node is a server side javascript enviorment that uses the Javascript event loop to work around this. Similar to the way Javascript will do AJAX on the browser Node.JS will do all its IO with a callback. In theory a single Node process can support thousands of users by never blocking on IO. I hope to play with Node.JS soon.

Tuesday, November 2, 2010

Options in NoSQL

For 90% of projects done with PHP and similar tools the database engine of choice is MySQL, (Postgress gets a large chunk of what is left). So when starting a new project using PHP, Python, Ruby etc the choice of a data store will default to MySQL and in some cases that is great. There is still the choice between myism and innodb tables but that one tends to be pretty easy.

However of late 'NoSQL' has become all the rage with new data storage engines showing up every so often.
The Developer faces a few challenges when moving from MySQL to one of these NoSQL engines.

1) Most web developers understand MySQL pretty well (we hope). We know how to index things, how to layout tables etc. This level of know how has not yet been established with the new NoSQL products.

2) The tools like phpMyAdmin and such for MySQL have been around for a while and are pretty well established

3) There are at least three big NoSQL data stores in the free software arena. (CouchDB, MongoDB and Cassandra) While competition is very much a good thing for the programmer who is not familiar with these products having to try to figure out which one to use in any given case can be a bit problematic.

I expect all three of these issues will start to go away over the next few years as the tech literature catches up to the software

Monday, November 1, 2010

LAMP: PHP is past its prime

If one part of the LAMP stack has to be the week link at this point it is PHP. PHP is a great language for doing little things but as web applications get more complex it is showing its limits.

PHP suffers from a few major problems:

  1.  The need to have a <?php tag at the top of any file, and having the script send anything outside of the <?php tag to standard output.
  2. Almost no ability to do any form of asynchronous operations 
  3. Vulnerability to injection and XSS attacks (Though many languages have this problem)

There is also the fact that as languages go PHP is just not very elegant. spend a few hours with python, ruby or javascript and PHP will feel painful. 

Sunday, October 31, 2010

Exploring New Tech

We seem to be bringing a lot of new web development tools online in the last 18 months or so. The problem is that many of these tools will require a major change in how web development is done. New tech to think about


  • Node.JS (Async I/O)
  • NoSQL (MongoDB, CouchDB, Casandra)
  • HTML 5 web workers
Part of the reason for this blog is to start the conversation on how to use these new tools.