<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title>degrunt.net</title><link>http://degrunt.net</link><description>degrunt.net</description><pubDate>Sat, 14 Jan 2012 01:01:00 GMT</pubDate><lastBuildDate>Sat, 14 Jan 2012 01:01:00 GMT</lastBuildDate><generator>Pop</generator><item><title>batman.js</title><link>http://degrunt.net/2012/01/14/batmanjs</link><pubDate>Sat, 14 Jan 2012 01:01:00 GMT</pubDate><guid>http://degrunt.net/2012/01/14/batmanjs</guid><description>&lt;p&gt;Quite some time ago (May 2011), I first heard about batman.js. It's &lt;a href="http://batmanjs.org/"&gt;homepage&lt;/a&gt; was still a bit empty, but gave a pretty good example of we're the framework was headed.
It's written in CoffeeScript and so far it's been pretty amazing. It's concise and once you understand how it works, pretty simple to use. 
This is also where some of the pain is: the documenation leaves a lot to desire, but the development team's helpfulness more than compensates for it.
I'm planning to put some useful snippets on this site as I go about discovering and continue working with batman.js.
I'll start off with a small snippet for a Regular Expression Validator I wrote:&lt;/p&gt;

&lt;script src="https://gist.github.com/1611897.js?file=reg_exp_validator.coffee"&gt;&lt;/script&gt;

&lt;p&gt;Use with:&lt;/p&gt;

&lt;script src="https://gist.github.com/1611897.js?file=validate_usage.coffee"&gt;&lt;/script&gt;</description></item><item><title>BitSets and Metrics</title><link>http://degrunt.net/2011/12/04/bitsets-and-metrics</link><pubDate>Sun, 04 Dec 2011 01:12:00 GMT</pubDate><guid>http://degrunt.net/2011/12/04/bitsets-and-metrics</guid><description>&lt;p&gt;After reading an article on &lt;a href="http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/"&gt;Fast, easy, realtime metrics using Redis bitmaps&lt;/a&gt; and seeing they used a Java implementation of BitSet, I really wanted a native JavaScript implementation.&lt;/p&gt;

&lt;p&gt;Looking at what they did for &lt;a href="http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/Collections-Jar-Zip-Logging-regex/java/util/BitSet.java.htm"&gt;Java&lt;/a&gt; it wasn't too difficult to implement this for JavaScript. The result is up on &lt;a href="https://github.com/tdegrunt/bitset"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Some example JavaScript code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var bs = new BitSet();

for(var n = 0; n &amp;lt; 12; n++) {
  bs.set(n);
}

console.dir(bs);
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Ported Aristo to stylus</title><link>http://degrunt.net/2011/05/19/ported-aristo-to-stylus</link><pubDate>Thu, 19 May 2011 02:05:00 GMT</pubDate><guid>http://degrunt.net/2011/05/19/ported-aristo-to-stylus</guid><description>&lt;p&gt;&lt;a href="http://cappuccino.org/aristo/"&gt;Aristo&lt;/a&gt; or on github &lt;a href="https://github.com/madebysofa/aristo"&gt;Aristo&lt;/a&gt; is a beautiful theme
for web applications. 
I had seen a &lt;a href="https://github.com/hpoydar/compass-aristo-plugin"&gt;Compass plugin&lt;/a&gt; for it, but I wanted a "native" node.js port.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://learnboost.github.com/stylus/"&gt;Stylus&lt;/a&gt; seemed like the right tool for the job, so I just did it.
The result is called &lt;a href="https://github.com/tdegrunt/stylus-aristo"&gt;stylus-aristo&lt;/a&gt; and available on github.&lt;/p&gt;

&lt;p&gt;A small demo can be found &lt;a href="/media/2011/05/Aristo/"&gt;here&lt;/a&gt;&lt;/p&gt;</description></item><item><title>node.js and zeromq, part 4 (XRequest/XReply)</title><link>http://degrunt.net/2011/05/06/node-js-and-zeromq-part-4</link><pubDate>Fri, 06 May 2011 02:05:00 GMT</pubDate><guid>http://degrunt.net/2011/05/06/node-js-and-zeromq-part-4</guid><description>&lt;p&gt;Today, after a long wait is part 4 of the node.js and ZeroMQ series. This part is about XRequest and XReply sockets also called XREQ and XREP sockets.&lt;/p&gt;

&lt;p&gt;There isn't a lot of documentation about this. As I understand it, these socket types allow you to asynchronously implement the request response pattern. Pretty much like REQ/REP actually, but I've found XREQ/XREP to be more stable.&lt;/p&gt;

&lt;p&gt;Without further ado, here's xrequest&lt;em&gt;xreply&lt;/em&gt;client.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

var counter = 0;
var socket = zeromq.createSocket('xrequest');
socket.identity = "client";

socket.connect("tcp://127.0.0.1:5502");
console.log("Connected to port 5502!");

setInterval(function(){
  var value = Math.floor(Math.random()*100);
  socket.send('', ''+value);
}, 10);

socket.on('message', function(data) {
  console.log("Answer data: "+data);
  counter += 1;
});

socket.on('error', function(error) {
  console.log("Error: "+error);
});
&lt;/pre&gt;

&lt;p&gt;Here's xrequest&lt;em&gt;xreply&lt;/em&gt;server.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

var socket = zeromq.createSocket('xreply');
socket.identity = "server";

socket.bind("tcp://127.0.0.1:5502", function(err) {
  if (err) throw err;
  console.log("bound!");

  socket.on('message', function(envelope, blank, data) {
    console.log("Received: "+envelope+" - "+data.toString('utf8'));
    socket.send(envelope, ''+data*2);
  });

  socket.on('error', function(err) {
    console.log("Error: "+err);
  });
});
&lt;/pre&gt;

&lt;p&gt;Here again the server part is actually a value duplication service (times two service).&lt;/p&gt;</description></item><item><title>Moving to static site</title><link>http://degrunt.net/2011/05/05/moving-to-static-site</link><pubDate>Thu, 05 May 2011 02:05:00 GMT</pubDate><guid>http://degrunt.net/2011/05/05/moving-to-static-site</guid><description>&lt;p&gt;Though Wordpress is a good product, I decided to move away from it for this site. I'm still using it on other sites of mine though.
This site is now generated from a series of Markdown files, currently using a product called &lt;a href="http://jekyllrb.com/"&gt;Jekyll&lt;/a&gt;. Currently it provides pretty much the same functionality website wise, ofcourse I now lost the administration interface.
The site is content wise complete, though the theme could use a little more.&lt;/p&gt;</description></item><item><title>Using VirtualBox with the command line</title><link>http://degrunt.net/2011/05/04/using-virtualbox-with-the-commandline</link><pubDate>Wed, 04 May 2011 02:05:00 GMT</pubDate><guid>http://degrunt.net/2011/05/04/using-virtualbox-with-the-commandline</guid><description>&lt;p&gt;For quite a while now I use VirtualBox as the virtualization software of my choice. I've used others, but the fact that it's free is a big benefit. It's also possible to use VirtualBox from the commandline. 
Assume that I have a VM called 'ubuntu-server', which uses 'ubuntu' as hostname. To start the VM I do the following:&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
alias vbm=VBoxManage
vbm startvm --type headless ubuntu-server
ssh ubuntu
&lt;/pre&gt;

&lt;p&gt;To shut the VM down you can do the following:&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
shutdown -H now
exit
vbm controlvm ubuntu-server poweroff
&lt;/pre&gt;

&lt;p&gt;Note that I've aliased VBoxManage to vbm, so that it's a little easier to use.&lt;/p&gt;</description></item><item><title>Installing nodejs on Ubuntu without compiling</title><link>http://degrunt.net/2011/04/16/installing-nodejs-on-ubuntu-without-compiling</link><pubDate>Sat, 16 Apr 2011 02:04:00 GMT</pubDate><guid>http://degrunt.net/2011/04/16/installing-nodejs-on-ubuntu-without-compiling</guid><description>&lt;p&gt;Since I wanted to run a nodejs site on a small Ubuntu machine, without any compile tools installed, I had two options: pre compile it and try to transfer it binary, or see if someone already did this. Browsing for a solution for the latter I came across this &lt;a href="https://launchpad.net/~chris-lea/+archive/node.js"&gt;launchpad&lt;/a&gt; page.&lt;/p&gt;

&lt;p&gt;All in all it's as simple as:&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo aptitude install nodejs
&lt;/pre&gt;

&lt;p&gt;The only thing to note, is that the executable it installs is called nodejs, so I made a softlink as follows:&lt;/p&gt;

&lt;pre class="prettyprint lang-sh"&gt;
cd /usr/bin
ln -s nodejs node
&lt;/pre&gt;

&lt;p&gt;All done!&lt;/p&gt;</description></item><item><title>node.js and zeromq, part 3 (Request/Reply)</title><link>http://degrunt.net/2011/04/05/node-js-and-zeromq-part-3</link><pubDate>Tue, 05 Apr 2011 02:04:00 GMT</pubDate><guid>http://degrunt.net/2011/04/05/node-js-and-zeromq-part-3</guid><description>&lt;p&gt;Today, in part 3 of the series on node.js and zeromq: Request &amp;amp; Reply. This pattern is meant for clients asking multiple requests to (multiple) servers. Contrary to TCP/IP, in zeromq it doesn't matter whether the server or the client does the bind. In the below case, the servers do the connect and the client does the bind. The most stable part of your architecture needs to do the bind. &lt;/p&gt;

&lt;p&gt;request&lt;em&gt;reply&lt;/em&gt;server.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

// reply = server/service
var socket = zeromq.createSocket('reply');
socket.connect("tcp://127.0.0.1:12345");

socket.on('message', function(data) {
  console.log("Received: "+data.toString('utf8'));
  socket.send(""+2*data);
});
&lt;/pre&gt;

&lt;p&gt;The server in the above example will multiply every received value with two. In real life situations this doesn't make sense, so use this for expensive operations. &lt;/p&gt;

&lt;p&gt;request&lt;em&gt;reply&lt;/em&gt;client.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

// request = client 
var socket = zeromq.createSocket('request');
socket.bind("tcp://127.0.0.1:12345", function(err) {
  if (err) throw err;
  console.log("bound!");

  setInterval(function() {
    var value = Math.floor(Math.random()*100);
    socket.send(""+value);
    console.log("Asking: "+value);
  }, 100);

  socket.on('message', function(data) {
    console.log("Answer data: "+data);
  });

});
&lt;/pre&gt;</description></item><item><title>node.js and zeromq, part 2 (Publish/Subscribe)</title><link>http://degrunt.net/2011/04/04/zeromq-and-node-js-part2</link><pubDate>Mon, 04 Apr 2011 02:04:00 GMT</pubDate><guid>http://degrunt.net/2011/04/04/zeromq-and-node-js-part2</guid><description>&lt;p&gt;While I'm at it, evaluating zeromq that is, I might as well publish examples for all usage patterns, so today follows Publish/Subscribe. The pattern is used to distribute data from one publisher to many subscribers. Both sockets are again uni-directional.&lt;/p&gt;

&lt;p&gt;publish&lt;em&gt;subscribe&lt;/em&gt;server.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

// publisher = send only
var socket = zeromq.createSocket('publisher');

var stocks = ["AAPL", "GOOG", "YHOO", "MSFT", "INTC"];

socket.bind("tcp://127.0.0.1:12345", function(err) {
  if (err) throw err;
  console.log("bound!");
  setInterval(function() {
    var symbol = stocks[Math.floor(Math.random()*stocks.length)];
    var value = Math.random()*1000;
    socket.send(symbol+" "+value);
    console.log("Sent: "+symbol+" "+value);
  }, 100);
});
&lt;/pre&gt;

&lt;p&gt;The server sends out messages, for five different stock symbols and their value (all random).&lt;/p&gt;

&lt;p&gt;publish&lt;em&gt;subscribe&lt;/em&gt;client.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-js"&gt;
var zeromq = require("zeromq");

// subscriber = receive only
var socket = zeromq.createSocket('subscriber');
socket.connect("tcp://127.0.0.1:12345");
socket.subscribe("AAPL");
socket.subscribe("GOOG");

console.log("connected!");

socket.on('message', function(data) {
  console.log("received data: " + data.toString('utf8'));
});
&lt;/pre&gt;

&lt;p&gt;The client subscribes only to receive updates for GOOG (Google) and AAPL (Apple) stock. Please note that the data consists of both the stock symbol and the stock value, exactly what was sent.&lt;/p&gt;

&lt;p&gt;zeromq.node is available from &lt;a href="https://github.com/JustinTulloss/zeromq.node"&gt;GitHub&lt;/a&gt;&lt;/p&gt;</description></item><item><title>node.js and zeromq (Push/Pull)</title><link>http://degrunt.net/2011/04/03/node-js-and-zeromq</link><pubDate>Sun, 03 Apr 2011 02:04:00 GMT</pubDate><guid>http://degrunt.net/2011/04/03/node-js-and-zeromq</guid><description>&lt;p&gt;While trying to evaluate zeromq and it's use with node.js, I quickly put together the following small experiment, which shows two unidirectional sockets. One is a "server" and can only push (send) messages, the other is a "client", which can only pull (receive) messages:&lt;/p&gt;

&lt;p&gt;pipeline_server.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-javascript"&gt;
var zeromq = require("zeromq");

// push = downsteam = send only
var socket = zeromq.createSocket('push');
socket.bind("tcp://127.0.0.1:12345", function(err) {
  if (err) throw err;
  console.log("bound!");
  setInterval(function() {
    socket.send(new Date().toString());
  }, 500);
});
&lt;/pre&gt;

&lt;p&gt;The server creates the push socket, connects to port 12345 of localhost and sends a message every half a second (containing the current date/time).&lt;/p&gt;

&lt;p&gt;pipeline_client.js:&lt;/p&gt;

&lt;pre class="prettyprint lang-javascript"&gt;
var zeromq = require("zeromq");

// pull = upstream = receive only
var socket = zeromq.createSocket('pull');
socket.connect("tcp://127.0.0.1:12345");
console.log("connected!");

socket.on('message', function(data) {
  console.log("received data: " + data.toString('utf8'));
});
&lt;/pre&gt;

&lt;p&gt;Mind you that these specific socket types are used in the pipeline pattern. The pushing socket will load-balance requests over the pulling sockets. If you start more clients, you'll see that the messages are fairly distributed over all clients.&lt;/p&gt;</description></item></channel></rss>

