Skip to content

Instantly share code, notes, and snippets.

@thecodedrift
thecodedrift / common.js
Created December 21, 2011 18:56
dependency injection
var foo = require("foo"),
bar = foo.bar;
exports.bar = bar;
#!/bin/bash
NODE_VERSION=0.4.10
NODE_FILE=node-v$NODE_VERSION
apt-get -y update
apt-get install -y aptitude
aptitude install -y unattended-upgrades build-essential libssl-dev libexpat1-dev pkg-config git-core nginx
wget http://nodejs.org/dist/$NODE_FILE.tar.gz
tar -zxvf $NODE_FILE.tar.gz
pushd $NODE_FILE; ./configure && make; make install; popd
rm -rf $NODE_FILE.tar.gz $NODE_FILE
Seq = require("seq")
Seq()
.seq_ (next) =>
fs.readFile(__filename, next);
.seq_ (next, text) =>
this.ok text.toUpperCase();
.seq_ (next, newText) =>
console.log(newText);
.catch (err) =>
web: node server.js
{
"name": "private-module-name",
"version": "0.0.1",
"private": true
}
npm install express
@thecodedrift
thecodedrift / class_klass.js
Created October 6, 2011 17:49
Class and Klass
/*
The below two objects are nearly identical. They both demonstrate inheritance
The top one is using klass by Dustin Diaz
The bottom one is using an extraction of Prototype's class method
Their pros and cons are listed with their executions
BOTH PROS
* Support super() through their own means
* can add additional methods via .implements (klass) and addMethods (pt)
BOTH CONS
$(function() {
$.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
IN.init({
api_key: "<your api key>"
});
});
});
/*
JavaScript CSS will change the way developers write CSS for their nodejs
applications. In apps like express, you're already stepping away from
HTML / CSS with SASS and LESS, so why not keep everything to a single language?
JSSS allows you to write CSS using chained methods familiar to JavaScript
developers. The CSS will then be optimized and written to the page (in browser).
Server side, the most optimal configuration for your stylesheet will be
determined, and rendered using epic awesome nodejs power and the help of a Ninja
Turtle.
@thecodedrift
thecodedrift / adoptnode.js
Created June 15, 2011 01:21
BLOG: adoptNode()
try {
document.adoptNode(window.opener.$("#my-iframe"))
}
catch(exc) {
// performance hit. Either importNode, or load the frame contents with appendChild()
document.importNode(window.opener.$("#my-iframe"))
}