Skip to content

Instantly share code, notes, and snippets.

@gjohnson
gjohnson / app.js
Created September 18, 2011 06:05
Modules - NCDEVCON
/**
* See docs for path resolution...
* http://nodejs.org/docs/v0.4.12/api/modules.html
*/
var foo = require('./foo');
console.log(foo.bar());
@gjohnson
gjohnson / index.html
Created September 18, 2011 15:09
twitter stream - NCDEVCON
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<div id="tweets"></div>
<!--
Since we bound the socket.io library to our web server, it will know about this file.
-->
@gjohnson
gjohnson / cluster_plugin_1.js
Created September 30, 2011 05:01
understanding cluster plugins
var utils = require('cluster/lib/utils')
, store = {};
module.exports = function (options) {
options = options || {};
ratelimit.enableInWorker = true;
function ratelimit (master) {
var server = master.server;
utils.unshiftListener(server, 'connection', function (sock) {
sock.pause();
@gjohnson
gjohnson / app.js
Created September 30, 2011 09:15
Simple HTTP Router Idea
var micro = require('./lib/micro');
micro.get('/json', function(req, res) {
res.json({
a: 1
, b: '2'
});
});
micro.get('/text', function(req, res) {
@gjohnson
gjohnson / gist:1257708
Created October 2, 2011 18:00
vbench err
> canvas@0.7.3 preinstall /usr/share/www/analytics-engine.com/application/node_modules/vbench/node_modules/canvas
> node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
@gjohnson
gjohnson / cluster-throttle.js
Created October 5, 2011 07:40
cluster throttle idea
var utils = require('cluster/lib/utils');
var redis = require('redis');
var rc = redis.createClient();
exports = module.exports = function(options) {
ratelimit.enableInWorker = true;
options = options || {};
var interval = options.interval = (options.interval || 1);
@gjohnson
gjohnson / visitor-dev.js
Created November 4, 2011 04:48
Traversing Goodness
var tree = {
id: null,
children: [
{
id: null,
children: [
{
id: null,
children:[
{
@gjohnson
gjohnson / route.html
Created November 4, 2011 05:07
Regex Hash Router
<a href="#/hello">hello</a>
<br/>
<a href="#/bye">bye</a>
<script>
route
(/^\/hello$/, function(){ alert('hello ran'); })
(/^\/bye$/, function(){ alert('bye ran'); })
;
</script>
@gjohnson
gjohnson / stopwatch.js
Created November 4, 2011 05:10
Stop Watch
window.StopWatch = (function() {
var seconds = 0;
var minutes = 0;
var timer = null;
var events = {
second: [],
@gjohnson
gjohnson / enagement_idea.js
Created December 13, 2011 02:25
Delayed Response
var http = require('http');
http.createServer(function(req, res) {
var url = req.url;
switch (url) {
case '/engagement.js':
var timer = setTimeout(function() {
clearTimeout(timer);
console.log('client is still here after two seconds.');