Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Chilton chilts

View GitHub Profile
@chilts
chilts / Output
Created May 6, 2012
Default value for 'c' doesn't proprogate to argv.concurrency
View Output
$ ./test.js -b my-bucket
Bucket=my-bucket
Concurrency=3
Bucket=my-bucket
Concurrency=undefined
@chilts
chilts / server-listening.js
Created May 14, 2012
Modified Node.js example from the front page : http://nodejs.org/
View server-listening.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1', function() {
console.log('listening');
});
console.log('Server running at http://127.0.0.1:1337/');
@chilts
chilts / test-callbacks.js
Created Aug 23, 2012
Example Node.js + Postgres tests
View test-callbacks.js
var fmt = require('fmt');
var pg = require('pg');
var conString = "pg://scroober@localhost/scroober";
pg.connect(conString, function(err, cl) {
if (err) {
console.log(err);
return;
}
@chilts
chilts / gist:3687910
Created Sep 9, 2012 — forked from twhid/gist:2648062
grunt task to deploy JS files to S3 with awssum
View gist:3687910
grunt.registerMultiTask('s3deploy', 'deploy to S3 using awssum', function () {
// dependencies
var awssum = require('awssum'),
fs = require('fs'),
path = require('path'),
aws = require('./settings').aws;
var amz = awssum.load('amazon/amazon'),
AmazonS3 = awssum.load('amazon/s3'),
s3 = new AmazonS3({
@chilts
chilts / README.md
Created Oct 4, 2012
A short and sharp explanation of streams and events (in upcoming Node.js)
View README.md

Streams

Readable Streams

Events:

  • end - once all data has been read and ...

Writable Streams

View tap.txt
$ npm test
> sound@0.1.0 test /home/chilts/src/appsattic-sound
> tap test/*.js
not ok test/basic.js .................................... 6/9
Command: "node" "basic.js"
TAP version 13
ok 1 is an object
ok 2 string passes
View sdf
models = require './'
sql = require 'sql'
crypto = require 'crypto'
Downstairs = require('downstairs').Downstairs
Table = require('downstairs').Table
env = require './../config/env'
uuid = require 'node-uuid'
logging = require './../lib/logging'
moment = require 'moment'
@chilts
chilts / different-pg-connect.js
Created Mar 5, 2013
An example of how pg.connect() behaves differently, when it probably should behave the same. :)
View different-pg-connect.js
var async = require('async');
var pg = require('pg');
var connString = "postgres://postgres@localhost/template1";
// attempt 1 - all ok
pg.connect(connString, function(err, client, done) {
// this function has a .length of 3 ... therefore done is defined
console.log('1) Connected ok');
done();
// pg.end();
@chilts
chilts / README.md
Created Apr 2, 2013
Node.js: Hints, Tips and Maybes
View README.md
View gist:5551069
// this needs to be read from the DB on startup
var userId = 1;
function putUser(user, cb) {
// am making this up for the purposes of demonstration - don't know what your use-case is
userId++;
user.id = userId;
var ops = [
{ type: 'put', key: 'sequence:userId', value : userId },