Skip to content

Instantly share code, notes, and snippets.

@gjohnson
gjohnson / tail.js
Created March 18, 2011 15:33
web interface for tail
var sys = require('sys');
var child = require('child_process');
var http = require('http');
var filename = process.ARGV[2];
if (!filename) {
return sys.puts('usage: node tail.js filename');
}
var tail = child.spawn("tail", ["-f", filename]);
@gjohnson
gjohnson / jquery.ga.js
Created July 28, 2011 22:14
fun with jquery, functions, and being too lazy to track google analytic events
$.ga
('use')
('setAccount', 'UA-83919101')
('trackPageview')
('trackPageLoadTime')
('setCustomVar', 1, 'OrderID', 1)
('events')
('click', 'h2', ['Label 1', 'Action 1', 'Value 1'])
('click', '#breadcrumbs', function(){ return ['Label 1', 'Action 1', this.value]; })
;
@gjohnson
gjohnson / testy.php
Created September 6, 2011 05:07
idea for a php 5.4 micro testing framework
<?php
/**
* concept for a new testing framework
*/
Testy\Test::describe('Addition')
->before(function() {
})
@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 / hello.js
Created September 18, 2011 06:01
HTTP Server - NCDEVCON
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.write('Hello');
res.end('NCDevCon');
});
server.listen(8000);
@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 / 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);