As any developer that has to build web applications you will love and hate JavaScript. It provides you with a powerful way to build an application online. But the code can easily become extremely chaotic, long, complicated and unreadable. And these things are a developers worst nightmare. This is were Coffeescript comes in.
The developers of Coffeescript describe it best with:
Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.
Coffeescript offers a way to make JavaScript code better to read and maintain. It does this by introducing a new syntax style to structure existing JavaScript code. It does this by reducing clutter of brackets and creating a more human readable language.
I’ll give a simple example demonstrating how Coffeescript can make you’re code better readable. Where we used to have to write huge amounts of code for simple things, like:
function test() {
var data;
var my_class = {
init: function(my_data) {
data = my_data;
this.doStuff();
},
doStuff() {
alert('Stuff is done');
}
};
return my_class;
}
With Coffeescript you can reduce this to a few simple lines:
test = ->
init: (my_data) ->
@data = my_data
@doStuff()
doStuff : ->
alert 'Stuff is done'
As this simple example shows Coffeescript not only reduces the number lines of code, but it also removes the overly complicated and unreadable brackets as well as introducing more context aware code. The CoffeeScript compiler will translate that code to some actual JavaScript that the browser can understand. So how does all off this magic work you might be wondering.
Well Coffeescript eliminates the use of brackets by parsing a tab as if it is a code block. So all code with the same indentation level will be in a set of brackets. Keep in mind that your source files will have to be TAB oriented to achieve this.
Using Coffeescript will require you as developer to install a few extra tools into your editor of choice. Being the Coffeescript compiler plug-in. This will convert the *.coffee files into regular *.js files.
A little while ago I decided it was time to buy a new mouse to work with. My last mouse is a 5 year old Logitech mouse that works sorta, but is starting to show its age. Whilst there are many different mice which you could select I opted to buy a Microsoft Touch mouse. Its one of those new fancy mice with a touch surface that is suposed to make it easier to manipulate windows.
Before anything else I need to mention that the mouse is specially designed for use in Windows 7, it’ll work for other OS-es. But the special features are only available in Windows 7.
So what is that amazing promise that Microsoft is giving us. Well basically that this is an entire new way of using a mouse, easier and more control over Windows 7. But is it really??
The good
It has been a long time since I did any kind of decent system upgrade on my VPS debian system. So I decided to be bold yesterday and attempt an upgrade from Debian Lenny to Squeeze. Shouldn’t be that complicated you would think? Right! Oh how I was wrong.
As with anything I wanna do right I first lookup on how to upgrade from Lenny to Squeeze, which according to some blog posts I found should be relatively easy. All it required were a few simple steps. So I was told to first make sure my Lenny system is up to date by running:
apt-get update apt-get upgrade
Well not a problem so far. That is something I’ve done regullary to keep up to date. Then I changed my ‘/etc/apt/source.list’ file to contain the following lines:
deb http://ftp.uk.debian.org/debian/ squeeze main non-free deb http://security.debian.org/ squeeze/updates main contrib
This should have set everything for the upgrade. Now all you should have to do is run the apt-get update again to refresh the database off applications. Followed by a simple upgrade of the update tool by running:
apt-get install apt dpkg aptitude apt-get dist-upgrade
So far everything went OK, and I didn’t discover any issues. Granted I had to double check every single configuration file just to make sure that the various applications (Apache / Subversion / postfix & dovecot) still worked.
But the next day I started getting automated e-mails by a verification script I had setup that the number of blog posts here started doubling every hour or so???? When I finaly had some time to check in on my VPS I found that all of the ‘draft’ posts and ‘deleted’ posts had suddenly re-appeared. Not to mention that WordPress started creating hundreds of ‘Auto Draft’ posts and automatically publishing them.
A further check on all my websites quickly revealed similar problems accros all websites and all databases running on that VPS system. So for now I rolled back all changes I did, restoring a backup of the server. Maybe if I feel more adventoures later on this week I’ll try a proper upgrade, but for now it is Lenny all the way baby!
As part of the new theme I’ve been developing I’m including some richer user features. Like on the spot loading of comments and better mobile device support. One of the things I need to figure out during the development is how to use Ajax in WordPress, preferably native support. I know it should be possible, but have yet been unsuccessful to get it working.
So what I’ve been doing is setting up a new action using add_action for the following two action types:
According to the documentation that should generate a hook to support both registered users (wp_ajax_<myaction>) and unregistered users (wp_ajax_nopriv_<myaction>). Which sounds great, since my theme should work for both type of users
.
On the front-end I’ve created a Javascript method that should call the ajax command using the ‘wp-admin/admin-ajax.php’. With as action parameter the name of my ajax method. So in theory I should be setup correctly to handle ajax, but this is where the theory and actual situation start to differ.
To test my new theme I’ve been using the preview mode of WordPress, after all I don’t want to kill any existing feature or activate the theme before it is done. But for some reason my nicely setup Ajax hooks aren’t working as advertised.
Just like many other website’s Narnio will go black on the 18th to protest against SOPA. For those that don’t now about it SOPA is Amerika’s way to oppress the free Internet as well as completely legal websites. Here are some of the reasons why SOPA sucks:
A lot of big Internet sites are opposing SOPA, including:
Below is a quote from the SOPA Strike.
On January 18th, 2012 the internet is going on strike to stop the web censorship bills in Congress! Now is our moment— we need you to do everything you can, whether you have a website or not.