Skip to content

Instantly share code, notes, and snippets.

View groundwater's full-sized avatar
:electron:
Performing Alchemy

Groundwater groundwater

:electron:
Performing Alchemy
View GitHub Profile
var http = require('http');
var crypto = require('crypto');
var PORT = process.env.PORT || 8888;
var MAGIC_STRING = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
function Frame(buffer){
this.buffer = buffer;
@groundwater
groundwater / config
Created April 28, 2013 15:17
SSH Config Files
# SSH Key Search Order
# ids/$HOST/$USER/id_XXX
IdentityFile ~/.ssh/ids/%h/%r/id_rsa
IdentityFile ~/.ssh/ids/%h/%r/id_dsa
# ids/$HOST/id_xxx
IdentityFile ~/.ssh/ids/%h/id_rsa
IdentityFile ~/.ssh/ids/%h/id_dsa

Application deployment should compliment rapid development, and continuous integration. It should be so easy that developers look forward to deploying updates.

The Application Bundle model is a robust method for running and developing server applications.

The constraints of deployment affects development. A good deployment should make development easy.

Application Bundle

  1. Do not use Makefiles to run application/server processes. Instead, use them to build/configure/setup your processes such than they can be invoked by a single command.
  2. Be idempotent. Running a make command twice in a row should be identical to running it once.
  3. Provide cleanup methods to delete generated content.
  4. Be habitual. You should use make commands constantly, otherwise your Makefile will drift out of sync from your application.
  5. Be complete. After a git-clone, the application should be usable after a single make command.
# Do comprehension chains Monads together
var x = do
a <- maybe_null( 'Hello World' ) # If returns null/None, none of the following is executed
b <- async_call_1( a ) # Returns a Promise
c <- async_call_2( b ) # Only executed once the preceding promise is fulfilled
d <- async_call_3( c )
return d
x.get(function(err,ok){
# function called with err if the above comprehension failed
GET /socket.io/1/?t=1360136617252 HTTP/1.1
User-Agent: node-XMLHttpRequest
Accept: */*
Host: localhost:9999
Connection: keep-alive
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Wed, 06 Feb 2013 07:43:37 GMT
Connection: keep-alive
function Database(mysql,config){
this.mysql = mysql;
this.config = config;
// setup mysql connection based on config
}
Database.prototype.get = function(){
// return an open mysql handle

A Typical Module Layout

package.json
  {
    "main": "index.js"
    ...
  }
index.js
  var lib = require('lib');
// you can omit DI for _light_ dependencies
var async = require('async');
module.exports.inject = function( dependencies ){
// no direct require of _heavy_ dependencies
var mysql = dependencies.mysql;
var redis = dependencies.redis;
// do whatever
@groundwater
groundwater / keypress.js
Created October 30, 2012 03:08
Capture a Single Key Press Event
process.openStdin()
process.stdin.setRawMode(true)
process.stdin.on('data',function(key){
console.log(key.toString())
})