May 2012
2 posts
The Module Pattern and Inheritance: A Better Way
Recently I blogged about how I like to build my JavaScript “classes”. I personally prefer the module pattern: it provides true encapsulation and doesn’t expose unnecessary methods and properties, which you get when you use the typical prototype pattern. One of the downsides of it, I’ve been told, is that it doesn’t easily allow to build classes that you can inherit...
May 28th
Some JavaScript Functional Sugar
I used to do a lot of Ruby, and now I’m doing only JavaScript. I really like Node and JavaScript, but since I’m lazy, I miss some of the niceties of the Ruby language. One of these niceties is that you can use a method reference when iterating over an Enumeration. For instance, if you had a collection of User objects, you can extract all the name attributes by using: users.map(...
May 11th
1 note
April 2012
1 post
4 tags
WatchWatch
Transcript: Some two and a half years ago a friend told me about Node.js. “It’s JavaScript on the server, and it’s making a buzz, you should totally check it out”. At the time I was doing Ruby dev work. I knew JavaScript, I kind of liked it, so I gave it a try. Downloaded node, installed it, did my first “hello world” script in 20 seconds, and bam! I had...
Apr 17th
December 2011
1 post
3 tags
Banzai - Document Processing Pipelines in Node.js
Banzai is a document processing framework for Node.js. You define a set of pipelines into which you push documents. Each document in a pipeline has a given state. A state transition triggers a state entry handler that can transform the document and interact with the outside world. The documents ends in a defined or in an “error” state. Rollback and Playback You can roll-back the...
Dec 8th
31 notes
October 2011
1 post
2 tags
Dump "this" and "prototype"
(How I like to build classes in Javascript) When developing server-side Javascript for Node.js, generally I tend to encapsulate classes inside CommonJS modules and expose the constructor function as module itself. As an incomplete example of how I used to do it, let’s build a module that exposes a rectangle class: function Rectangle(x, y, width, height) { this.x = x; this.y = y; ...
Oct 21st
2 notes
September 2011
3 posts
1 tag
"Javascript classes, prototypes and closures".... →
Sep 26th
1 tag
HTTP Mocking made easy with nock
I love testing and I love small easily testable modules in Node. Recently I had to build a library module that interacts with some web services via HTTP. To test this module as it was would mean that I would have to have a sandboxed account on the other end. I also would have to have setup and teardown routines that would reset the sandbox to a known state, etc, etc. What I really wanted for...
Sep 23rd
1 note
1 tag
Configuration files in Node.js made easy with...
Configuration is always a chore, a simple thing you have to do, and keep reinventing every time you start a new project. I usually have the following setup: I have one configuration file per domain and several domains. A domain may be “www”, “couchdb” or a remote service that requires some parametrization like Postmark. These are JSON files that lie in some directory. ...
Sep 22nd
1 note
July 2011
2 posts
1 tag
Job queue using Node.js, Redis and Kue →
Jul 27th
4 tags
Latest Node Tuts is out: "Starting with everyauth" →
Jul 18th
May 2011
1 post
1 tag
Hands-on Node.js e-book →
May 5th
1 note
April 2011
2 posts
WatchWatch
teamcoco: The Kills - “Pull U A” (Backstage @ CONAN)
Apr 20th
98 notes
Freezing and bundling your dependencies with node... →
Apr 1st
March 2011
1 post
The news
Today, a young man on acid realized that all matter is merely energy condensed to a slow vibration - that we are all one consciousness experiencing itself subjectively. There’s no such thing as death, life is only a dream, and we’re the imagination of ourselves. Here’s Tom with the weather - Bill Hicks
Mar 17th
1 note
February 2011
5 posts
1 tag
Asynchronous iteration patterns in Node.js - part...
This is a follow-up to my previous article “Asynchronous iteration patterns”. The latest feedback has been great, some corrections and remarks were sent my way. Also, some node.js hate was spread around because of what I think is the added complexity some times needed to handle asynchronous IO. It was not my intention to spread fear about handling asynchronous IO, but to gather and...
Feb 28th
1 note
Node Nerd: Durable Sessions →
nodenerd: GitHub Commit Monitor currently uses the default, in-memory session provider, which will mostly work for development, but has some downsides: When the app restarts or is updated all of the session data is lost If the session data is large or there are a large number of sessions, the amount of…
Feb 27th
4 notes
Feb 23rd
Feb 18th
10 notes
Node Tuts #19 is out - Asynchronous iteration... →
Feb 3rd
1 note
January 2011
2 posts
1 tag
Asynchronous iteration patterns in Node.js
Some patterns are hard to grasp, specially when programming asynchronously like you have to when you’re doing IO on node.js. For example, let’s suppose you had to program the following routine: Insert a collection of objects on the database and then, when finished, call a callback. So, if you had to write this in a synchronous fashion you would do something like this: So,...
Jan 9th
17 notes
1 tag
Introducing Alfred.js - a node.js in-process...
On November 2010 I blogged about wanting to have an in-process key-value store for node.js. I was displeased with the impedance mismatch between external datastores and node.js, and soon noticed there was nothing really similar to what I wanted. Following the advise from Tom Preston Werner, I created my own BOMTYCC problem. Two months and a lot of long nights later, Alfred.js emerges. To...
Jan 7th
1 note
November 2010
10 posts
1 tag
My almost perfect in-process node.js key-value...
Lately I have been looking into node-dirty and nStore. Both are in-process key-value stores for node.js. nStore is a bit more complex that node-dirty - it allows query results streaming, for instance - , but both are fairly simple approaches. I like the power of these databases, since they allow for javascript-function-based queries. And since everything is in-process, there is no over-the-wire...
Nov 19th
Just out - Node Tuts episode 9 - "Express" →
Nov 16th
node.js - a deep dive - my codebits presentation... →
Nov 15th
Codebits - the aftermath
After sleeping two nights after the last day of codebits and posting this, and finally back to reality, there are some aspects of the event I would like to review. The green lights inside codebits must have induced some kind of subliminar hipnose state from which only now I’m starting to recover. Still I think it was, as always, a wonderful event, one of the best - if not the *the* best -...
Nov 15th
Codebits 2010 - first impressions
I was fortunate to have been selected to participate in the codebits 2010 event. Codebits is all-is-free invitation-only event occurring in Lisbon. I also went in 2009, and by then I was blown away by the quality of it all. We had great speakers (portuguese and international) on four parallel tracks, one main stage and 3 secondary ones. We had lots of things to play with like gaming consoles,...
Nov 13th
1 note
WatchWatch
My “node.js - a deep dive” talk at Codebits video is online. The slides are here: https://github.com/pgte/node_js_deep_dive_presentation
Nov 13th
Node Tuts #7 is out - Node.js and Socket.IO →
Nov 9th
Nov 6th
2 notes
Node Tuts #6 is just out - Node.js and websockets... →
Nov 4th
Nov 2nd
October 2010
6 posts
Javascript ECMS 5 features implemented in V8 →
Oct 29th
Oct 29th
Oct 28th
Oct 28th
Node Tuts - Node.js screencasts
Recently I have been experimenting with node.js and since the beginnig I found that node.js material for beginners was scarce. I dug into HowToNode, but most of all I was stuck with the Node.js official API docs. Respecting the scratch-your-own-itch principle, I decided to record some screencasts - something I’m quite new at - during the off hours - and here is the result: Node Tuts - free...
Oct 26th
Introduction to Fugue - Unicorn for node.js
Unicorn has implemented some UNIX old-school techniques with some clever wiring and delivered a solid Rails / Rack server that provides zero-downtime-app-restart, OS-level load balancing between workers and restarts a worker when it’s hanging or dies. I needed something similar to this for node.js, and after some searching I found Spark and Multi-node. Spark was the one that caught my eye...
Oct 6th
September 2010
3 posts
fugue
Fugue is the node.js equivalent of Unicorn. Fugue supports any node.js TCP server as long as it descends from net.Server (http.Server, connect.Server, …). Fugue provides the following features: Supports and type of Node.js server as long as it inherits from net.Server (http.Server, connect.Server, …) Failover - when a worker dies it is restarted. Zero downtime app reload. Set gid,...
Sep 27th
Rails send_file with temporary files
If you are using the send_file command inside your controller to send a temporary file, you cannot delete that file after, or Rails will complaint the file is missing. That is because send_file works asynchronouly. If that file is a temporary file you just created to serve that request, you’re in trouble, because you can’t remove it. One solution is to get a cron job to...
Sep 15th
Sapo codebits 2010
Gladly, I have been accepted to the Sapo Codebits 2010 conference. It’s a free conference with limited access, so I’m very honored I proposed a talk on node.js. Let’s see if I’m accepted, fingers crossed… Here is some more info about the event: http://codebits.eu
Sep 1st
May 2010
1 post
Zero width ExtJS HTMLEditor on IE7
Do you have a zero width HTMLEditor on IE7 only? Don’t waste hours like I did trying to figure it out. Pass in a ‘width’ argument to the HTMLEditor constructor. That did it for me. Using ExtJS 3.2.1.
May 5th
April 2010
1 post
Will_paginate and AJAX
I have been using will_paginate ever since I started on Rails. It’s a great plugin for classic page rendering, but what if you want to use it with AJAX, so it updates a document element (a floating window layer, for instance) with the results instead of reloading the page? Well, inspired on Redline’s blog post (which almost worked for the latest version of the will_paginate plugin),...
Apr 12th
March 2010
1 post
How to paginate outside of the database with...
will_paginate is a great plugin. I have been using it since I started on Rails. If you want to paginate records that are inside your database it works great. But what if you want to paginate records that come from, say an external webservice? Well, you can use the WillPaginate::Collection class. This class will let you mimic the collection that will work on a pager, so you can use the view...
Mar 31st
1 note
December 2009
1 post
New year resolutions
Happy new year to everyone! I haven’t posted for a while - had a busy end-of-year… Things I want to look into early 2010: Haml Rails 3 Node.js Erlang Hadoop Scala EJB 3 Ruby alteranative VMs (JRuby, MacRuby, LevMag) …and more cool blog posts!
Dec 30th
November 2009
1 post
Tools for the job
Here are some tools / gems / plugins I can’t live without: IDEs: Aptana Rad Rails - very good at Rails and Ruby. It’s based on Eclipse - Java - so it tends to bloat gedit- Tiny footprint, simple. Great for web and PHP with the right plugins and conf tweaks Ruby / Rails plugins: will_paginate - ActiveRecord pagination made easy fleximage - online image processing Rails plug-in...
Nov 4th
1 note
October 2009
6 posts
sweepy - Distributed and scalable file caching...
Followin up on my post about Rails cache on a distributed environment, I recently published a Rails plugin called sweepy. Sweepy allows you to expire file-based cache (page cache and fragment cache) on Rails on multiple boxes. If you don’t want or don’t need to setup memcached, and just want to simply use Rails page and / or fragment caching, sweepy automatically handles page expiration. You...
Oct 28th
How to alias_method_chain a class method on Rails
Sometimes, when building a plugin, you have to extend Rails behaviour using alias_method_chain. So you do, on the included module: [ruby] … def self.included(base) base.send :include InstanceMethods base.class_eval do alias_method_chain :method_i_want_to_extend, :my_feature end end module InstanceMethods def...
Oct 16th
Tutorial - advanced styled_objects on Rails
Following the building and styling a Rails app with styled_objects tutorial, we will learn how to use some advanced features of styled_objects and also some best practices to keep your CSS code maintainable while using styled_objects. Use CSS variables On styled_objects you can define global variables to be used throughout your CSS. Declare variables on one place: app/views/globals.css Example...
Oct 13th
Tutorial: building and styling a Rails app with...
How to keep your stylesheets clean and organized using Rails This tutorial covers building a web application from scratch using Rails with the styled_objects plugin. As an example we will be building a very static front-end website, mainly to focus on stylesheets. Everything you get from can be applied to more complex applications. Because this is such a simple application, we won’t be...
Oct 12th
styled_objects Rails plugin
Yesterday I released the styled_objects Rails plugin. styled_objects is a Rails plugin for simplifying stylesheet management on your application. Instead of having one or more large stylesheets on your public folder, have many. Keep your CSS close to their respective templates. styled_objects will compile them into one file per page. Why do I need styled_objects? Because It’s hard to keep order...
Oct 10th