Nice bits of symfony: Web Debug Toolbar

I mentioned previously that I’d been playing with the symfony framework on a couple of projects and I have to admit to being more and more impressed as I wade in looking for things. I’ve worked with enough MVC-like frameworks to know they are all quite similar in more ways than they are dramatically different. So it’s the little bits and pieces that win you over.

One of my favourite little bits in symfony has to be the Web Debug Toolbar. When running in development mode you get a little menu floating above your application like so (top right hand corner).

Web page showing the symfony web debug toolbar in the top right corner

This gives you all sorts of useful information as you’re developing your application - from the number of database queries to the rendering time, with a full logger built in. It’s also been particularly useful in learning symfony - being able to follow the entire request through the stack from the logger is really handy when you don’t know what is going on.

Web page showing the symfony web debug toolbar fully expanded

With the increasing use of object relational mapping in web frameworks it’s quite easy to end up with a working application on your development box that turns out to absolutely hammer your database when used in the real world by only a few hundred people (I’m looking at you tagging). The database utilities, showing the number of queries and the SQL for those queries, is particularly handy for finding bottlenecks here.

Web page showing the symfony web debug toolbar SQL view

I’ve not come across something similar in other frameworks, PHP or otherwise. I’d be interested to know if similar things do exist for Rails or Django in particular.

Happy with my eeepc

I like small. I have a macbook rather than a macbook pro because it’s smaller. Especially now I’m wandering about more often with work (and play) lugging a machine around is less and less appealing. So, armed with that excuse I felt justified in going out and buying a new Asus Eee PC. I managed to just walk in to Micro Anvika in Newcastle and buy one from a bemused staff member who was pretty shocked to find one in stock and not allocated (sorry Rey).

For anyone who hasn’t seen one before, the Eee PC is a tiny linux laptop a little like the One Laptop Per Child machine but aimed more at traditional computer users (at the moment read early adopting geeks). The distro is setup to be pretty user friendly for those pesky Windows users but a little hacking turns it into a pretty darn nice machine.

My new eeepc with an apple logo on the back

And yes, I have stuck an apple sticker on back. I’m sure that should get some entertained looks next time I’m at a relevant event! I think the machine itself is actually pretty good looking, but the default desktop themes are all pretty uninspiring.

I’ve stuck with the appliance like IceWM window manager and the launcher application as it makes starting things up from the keyboard with one hand pretty fast. I then jumped into various hidden away files to get the desktop setup how I like. The wiki over on eee user has a number of useful tutorials; customising easy mode and the debian repo from a ruby tutorial were particularly handy.

Minimal IceWM desktop with Asus Launcher

Still lots more I could install (this is Linux after all) but so far have installed Ruby, Rails, Python, Django, Erlang, MySQL, SQLite, Apache2, PHP5, PEAR and symfony all without a hitch. I do love apt when it just works. I’ll try and get Mono and Java on their as well just for completeness when I get a moment.

The only thing I can think of that I’ll really miss at the moment is Keynote. It has a VGA out port (which not even the macbook has) which will support a decent resolution for presentations. But Keynote is so pretty and easy to use compared to the alternatives. We’ll have to see next time I have to do a presentation.

I can see lots of places (past the obsessive tech geeks like me) where a machine like this will be really interesting. Obviously the low cost of the machine means that schools might just get interested in Linux. For people who prefer a desktop machine as their main computer and only occasionally need a laptop it’s a pretty cost effective option. As a machine to experiment with Linux it’s pretty useful too - I’d recommend being familiar with basic commands on Linux to anyone doing web development work for instance. With so many possible audiences, and what is already a pretty nice machine, Asus might be onto something here.

CSS Uprising

For those not following along closely I thought it worth highlighting some interesting goings on around the web. Andy Clarke put the CSS cat amongst the W3C pigeons with a couple of posts; CSS Unworking Group and a following up CSSWG Proposals

How I’ve had a few ideas myself previously around what I’d like to see from the CSS3 working group. I’m now avidly following along with the comments and I’d urge anyone working even on an occasional basis with CSS to do the same.

Maciej Stachowiak said a few very interesting things in the comments I thought worth commenting on:

Being an expert user is not necessarily enough to know how to extend it. A key part of extending a technology is knowing how it works on the inside.

I think their-in lies an opportunity. The weight of comments on this issue, and the heat of the argument, would suggest people are interested. But I think a-lot of those interested parties are those working day-in with CSS (rather than on it) and lack this critical information. As a web designer how do I find this information out? Who are the interesting bloggers in the area of standardisation? Is their are good reference site? Or a wiki? Or an active friendly mailing list of people willing to answer simple questions? The web (standards) design community is used to open discussion and debate - whether from blogs or projects like microformats.

You could of course also argue that being an expert implementer is not necessarily enough to know what needs extending. A key part of extending a technology is knowing what is needed first in the real world.

But the cost of a serious mistake in a standard is much higher than the cost of an implementation bug.

I think this depends on the software in question - what about critical military systems, satellites or space shuttles, power stations, etc. - but I agree in principle. Most web designers do not have the experience of working on this sort of software project. But then Andy is not putting himself up as a project management guru.

Their are obviously strong feelings on both sides of this debate. But something I would be interested to hear - from someone with a standards focus - is whether you think their is a fundamental problem at the moment with regards CSS? If not then why not? If so then what are your ideas for moving forward?

And feel free to say you don’t know yet. I think what Andy has done is put down his ideas. If you don’t like them then suggest better ones. If that’s sticking to the status quo then say why you it feel will work out.

(I’ve posted the above in the comments to the original post, but wanted to repeat it here more in the hope of getting more interested people involved in that thread.)

I don’t really expect Andy to have the answers to this issue, but by him kicking the discussion off in such a public way the least we can all do is have the debate we need and come up with the solutions for everyone. Especially on the list of getting started with standards links and reading materials alluded to above, if someone has this information but not the time to get it online in a coherent fashion, or to present it to the wider community then please get in touch.

Using Curl to play with CouchDB

As a big big fan of all things HTTP, the new Erlang based database, CouchDB, piqued my interest. With the recent release of 0.7 it’s now intended for widespread use. Now I’m a fan of databases as long as I don’t have to go too near them. SQL, triggers and stored procedures are all a little too close to magic for me.

The reason CouchDB looks particularly good fun was it’s build around a REST API using JSON for data transport. I’m generally not an acronym guy, but REST, JSON, API and HTTP in one open source piece of code? Sounds like fun to me.

The CouchDB community have built up an already excellent wiki with all the information you need to get started and get the software installed. I just used the magic of MacPorts but the page covers all the various dependencies and setups (though nothing on their yet about the N800).

<code>sudo port install couchdb</code>

You might then need to set-up a user and some permissions. Again the wiki has more detailed installation instructions. All being well you should then be able to fire up CouchDB:

<code>sudo -u couchdb couchdb</code>

So first things first. Their are getting started code examples on the wiki in all the usual languages so you can just dive in. CouchDB also comes with a few in-build tools which are both pretty attractive and useful. You have a database browser, a full test suite and a command shell.

Curl, for those not familiar with it, is a fantastic command line utility for throwing around HTTP requests. I already use it for testing and generally prodding sites but it’s absolutely perfect for demonstrating CouchDB. Let’s start with creating a database called test:

<code>curl -X PUT http://localhost:8888/test/</code>

That should have created the database. Let’s get some information back about the database:

<code>curl -X GET http://localhost:8888/test/</code>

Everything should be returning JSON strings telling us something about what it finds. Let’s add a blank document to the database:

<code>curl -X POST http://localhost:8888/test/ \
-H "Content-Type: application/json" -d {}</code>

Note the blank JSON object {} passed as Post data. What about retrieving a list of document from the database?

<code>curl -X GET http://localhost:8888/test/_all_docs</code>

We’re now done with that database so let’s delete it.

<code>curl -X DELETE http://localhost:8888/test/</code>

I’ve just done the basics here, but the APIs are simple and nicely documented enough for you easily to find out more. This is the beauty of RESTfully designed APIs, they are just about self documenting. For the most part you just have a predefined HTTP method and a defined URL.

The Erlang base of CouchDB makes for some interesting horizontal scaling possibilities (as well as a good excuse to play with Erlang.) Even if CouchDB wasn’t cool enough already, it comes with probably the best start-up message I’ve seen in software for ages:

<code>CouchDB has started. Time to relax.</code>

Insert Dojo and YUI bookmarklets

I’ve talked about having fun with jQuery using Jash and Firebug before after seeing Simon throw the Google homepage around at barcamp. I’m no more a one javascript framework person than a one programming language person and recently I’ve seen cool things I want to play with in lots of the main contenders.

I’ve put together a couple of bookmarklets which load YUI or Dojo from their respective content delivery networks and insert them into your current browser context. You can then play around with them in Jash or Firebug or any other Javascript console.

Dojo is particularly interesting here due to it’s cunning loading mechanism for additional parts of the framework. Basically you can gain access to the entire (huge) framework simply by using the bookmarklet and then dynamically loading the rest via the command line.

Insert Dojo

<code>javascript:void(function(){
 var%20s=document.createElement('script');
 s.src='http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js';
 document.getElementsByTagName('head')[0].appendChild(s);
}())</code>

Insert YUI

<code>javascript:void(function(){
 var%20s=document.createElement('script');
 s.src='http://yui.yahooapis.com/2.4.0/build/yahoo-dom-event/yahoo-dom-event.js';
 document.getElementsByTagName('head')[0].appendChild(s);
}())</code>

The code simply inserts a script element into the page which loads the relevant framework. I’ve shown the code on multiple lines for the sake of the example, but your bookmarklet should be on one line. Alternatively you can drag the Insert YUI or Insert Dojo links to your bookmark bar.

Writing Elsewhere

As well as the eclectic ramblings on this blog I’ve taken to writing longer bits and pieces for some other nice folk, two of which went up over the last few days.

“Drew” and Brian are doing a great job of gathering together some really good articles in a silly time-scale over on 24ways.org at the moment. My little ditty on minification was day 6.

Chris Mills, in his new position as Opera mascot, has also rapidly started to build up a great collection of articles over on dev.opera. My contribution to what is looking like a great new resource is a piece on using JSON for configuration in your Javascript applications.

Writing for other people is different to just posting interesting stuff on your blog. And it wouldn’t work at all without some pretty dedicated people editing, compiling and chasing to get us all those high quality articles for sites such as alistapart, Digital Web and Sitepoint. So if you meet any of these people on your travels then pat them on the back and buy them a beer. Without the information sharing community we probably wouldn’t be doing all this for a living.

Debug web pages with Jquery and Jash

I have a new toy I’m quite enamoured with. After a double helping of jQuery first from Jon Resig at @media Ajax and then from Simon Willison at barcamp I just had to take a look. My favourite part was probably Simon showing off his Insert jQuery bookmarklet - hacking around with the Google home page design on the firebug command line. The idea of having a command line to play around with any web page I come across appeals to my geekier side.

I spend more time in Safari than Firefox these days mainly as I find it feels snappier and is generally more stable. The only real downside is the lag of Firebug. A quick look at Firebug Lite revealed it doesn’t work in Safari but a little searching later I found Jash. The Insert jQuery and Insert Jash bookmarklets now have pride of place in my bookmark bar.

"Jquery and Jash bookmarklets running on Google"

So what to do with my new toy? Let’s hide all the paragraphs! (for no other reasons than we can).

<code>$("p").hide("slow")</code>

So, redesign any web page you visit via a quick to access command line? What’s not to like?

10 Thinks you probably don&#39;t do

The resent barcamplondon3 was huge fun and particularly interesting. I might even go as far as saying it was the best yet in terms of the sessions I attended.

Particular highlights for me included discussions of (Yahoo! flavoured) web development practices and processes from Norm and Mike, Matt Biddulph on messaging, erlang a event driven programming techniques and Dan Dixon’s panel on What should we be teaching the next gen of web designers/devs?

I tried to kick off a debate regarding automation and software tools and practices in web projects. More from anecdotal evidence and experience rather than pure research I don’t think that many companies or individuals really set their projects up on a solid base. Source control, bug tracking, scripted builds, automated quality testing, etc. aren’t that common for smaller or medium web projects.

In the end I talked though everything in general terms and the audience nicely jumped in with various platform specific toolsets for unit testing, functional testing and performance measurement. All in all good fun and a subject I think will see some activity next year.

Overall a good smattering of my favourite topics at the moment (education, development process, distributed messaging), lots of fun people and the chance to ride round Google on a segway at about two in the morning. Roll on the next barcamp.

Archiving Twitter data with Python

Alex from Twitter just got round to adding the ability to export your entire archive of tweets via the API. A few people on the mailing list had been asking for this for a while so good to see it get released.

I couldn’t resist knocking together a very quick and simple Python script to go off and get all your tweets, presented here for anyone else to play around with. Note that simple, fast and works on my machine were watchwords here. Don’t expect fancy parameters, much error handling or artificial intelligence.

<% syntax_colorize :python, type=:coderay do %> import urllib2 username = ‘‘ password = ‘‘ format = ‘json’ # json or xml filename = ‘archive.json’ # filename of the archive tweets = 164 # number of tweets pages = (int(float(tweets)/float(80)))+1 auth = urllib2.HTTPPasswordMgrWithDefaultRealm() auth.add_password(None, ‘http://twitter.com/account/', username, password) authHandler = urllib2.HTTPBasicAuthHandler(auth) opener = urllib2.build_opener(authHandler) urllib2.install_opener(opener) i = 1 response = “ print ‘Downloading tweets. Note that this may take some time’ while i <= pages: request = urllib2.Request(‘http://twitter.com/statuses/user_timeline/account.'
+ format + ‘?page=’ + str(i)) response = response + urllib2.urlopen(request).read() i = i + 1 handle = open(filename,“w”) handle.write(response) handle.close() print ‘Archived ’ + str(tweets) + ‘ of ’ + username +
‘\’s tweets to ‘ + filename <% end %>

The main thing to note here though is the ideal of data portability. Let’s just say I wanted to move to Jaiku or Pownce instead of Twitter, but didn’t want to lose all that data. If I can knock up an export script in half an hour then all you need are import data API calls and a little more scripting.

As it is, I’m more interesting in seeing what I can do with my data now I can get at it. Brian just suggested a quick visualisation tool (which already eats JSON) and I’d already been thinking about language analysis and maybe having a look at APML some more. Open data is simply more fun.

Should we just learn Java?

As a wandering web designer cum developer and now occasional consultant I’m generally pretty technology agnostic. At some point or another I’ve written HTML, CSS, Javascript, PHP, C#, Python and Rails for a living - often on the same day. But something has me thinking and I thought I’d see what other people thought as well.

That thing is Java. I have books on Java. I’ve done the usual examples (hello world in 20 lines for instance). I didn’t really like it and left it at that. But a few presentations, both from Google, at both Future of Mobile and @media Ajax got me thinking. First you have Android in the mobile space which Dave Burke did a good job of making look pretty interesting. Then you had the guys from Ajaxian talking about using Java for everything.

A few other thinks to throw into the pot. Beyond Java is an interesting read - summing up with a call for more fragmentation and for small nimble languages to be used where it makes sense. Oh, and I think Tom is busy learning Java as well. Mmmmm.

Some good coverage around of both conferences and I know my first impression was basically this way lies madness. But it would have been more interesting had their been a few more Java people around to argue with.

Note that I’m not advocating a Google like disregard for the web here. Markup really matters, I happen to disagree with Douglas and think CSS rocks and I love writing Javascript. But should we just learn Java anyhow and try to subvert some of the existing tools to be more web like?