Permalink
Browse files

Tidy up for merge.

  • Loading branch information...
1 parent 7c57c70 commit 2911f2718f801fae700131dbc138de6c8488db02 @creationix committed Sep 7, 2010
Showing with 15 additions and 15 deletions.
  1. +8 −8 articles/node-redis-fun.markdown
  2. +7 −7 articles/node-redis-fun/snip.js
@@ -1,6 +1,6 @@
Title: Node + Redis = Fun
Author: Nikhil Marathe
-Date: Mon Sep 06 2010 12:48:20 GMT+530 (IST)
+Date: Tue Feb 23 2010 21:20:20 GMT+530 (IST)
Node: v0.2.0
node brings asynchronous, evented I/O to the server. Redis gives you a blazing fast database with support for strings, lists and sets. Both Redis and Node.js follow certain patterns, Redis for data-storage, and node for event based programming. I hope to give an introduction to both in this article. By the time we are done, we will have built a [Pastebin][] service.
@@ -46,9 +46,9 @@ Node modules are used by importing them into the current scope using `require()`
to test our application, we will be using this shell script, so that we can directly do
- require( 'nerve' )
-
-and have it work
+ require( 'nerve' )
+
+and have it work
#!/usr/bin/env sh
export SNIP_PATH=$(dirname `readlink -f $0`)
@@ -111,10 +111,10 @@ A particularly nasty part of our code is the list of languages, generated by [ge
So this is a part of `snip.js`
<node-redis-fun/snip.js#formHtml>
-
+
var addSnippet = function() {}
var showSnippet = function() {}
-
+
<node-redis-fun/snip.js#create>
### Handling post data ###
@@ -160,15 +160,15 @@ It would have been even cooler if redis-node-client supported streaming the data
// for now just assume we magically
// got the snippet JSON parsed into obj
-
+
// get the language short code
// not that languages is an array of
// ["shortcode", "name"] elements and filter
// returns a *list* so we need the 0th element.
var shortcode = languages.filter( function(el) {
return el[0] == obj.language;
}) [0][0];
-
+
var pyg = cp.spawn( "pygmentize",
[ "-l", shortcode,
@@ -28,7 +28,7 @@ var withRedis = function( cb ) {
});
}
-var languages =
+var languages =
[["apacheconf", "ApacheConf"],
["applescript", "AppleScript"],
["as", "ActionScript"],
@@ -177,16 +177,16 @@ var formHtml = '<form action="/add" method="post">'
+ '</select>'
+ '<input type="submit" value="Paste!" /></form>';
-var getPostParams = function(req, callback){
- var body = '';
+var getPostParams = function(req, callback){
+ var body = '';
req.on('data', function(chunk){
body += chunk;
- })
- .on('end', function() {
+ })
+ .on('end', function() {
var obj = qs.parse( body.replace( /\+/g, ' ' ) ) ;
callback( obj );
});
-}
+}
var addSnippet = function( req, res ) {
getPostParams( req, function( obj ) {
@@ -217,7 +217,7 @@ var showSnippet = function( req, res, id ) {
res.writeHead( 200, { "Content-Type" : "text/html" } );
var obj = JSON.parse( data.toString() );
- var shortcode = languages.filter( function(el) {
+ var shortcode = languages.filter( function(el) {
return el[0] == obj.language;
} ) [0][0];

0 comments on commit 2911f27

Please sign in to comment.