Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Rajlich TooTallNate

View GitHub Profile
@TooTallNate
TooTallNate / foo.js
Created Aug 15, 2012 — forked from mediaupstream/foo.js
Recursive require crashes node
View foo.js
module.exports = foo;
require('./index.js')();
function foo(){
console.log('foo.js', Date.now() );
}
View obj-gc-test-fail.js
// run with "node --expose_gc"
var weak = require('weak')
, util = require('util')
var count = 0
, countGc = 0
function dec () {
count--
@TooTallNate
TooTallNate / server.js
Created Apr 14, 2012 — forked from nicokaiser/server.js
node http request leak FIX!
View server.js
var http = require('http')
, weak = require('weak')
function collectGET() { console.log('GET request collected by GC') }
function collectPOST() { console.log('POST request collected by GC') }
var server = http.createServer(function(req, res) {
if (req.method == 'GET') {
// GET
console.log('GET request')
@TooTallNate
TooTallNate / play-codestream.js
Created Apr 3, 2012 — forked from sugyan/play-codestream.js
play codestre.am video on your terminal
View play-codestream.js
var sio = require('socket.io-client')
, id = process.argv[2] || '3Y'
, socket = sio.connect('http://play.codestre.am/?id=' + id)
console.log('connecting...')
socket.on('connect', function () {
console.log('connected.')
})
@TooTallNate
TooTallNate / bbs.js
Created Mar 16, 2012 — forked from substack/bbs.js
Running a node.js REPL over `curl`
View bbs.js
/**
* Requires node v0.7.7 or greater.
*
* To connect: $ curl -sSNT. localhost:8000
*/
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
@TooTallNate
TooTallNate / strict.js
Created Oct 17, 2011 — forked from anonymous/gist:1294124
Testing if "use strict" requires functions to always return something...
View strict.js
"use strict";
function test () {
console.log('hello?')
}
test()
@TooTallNate
TooTallNate / Run.js
Created Sep 27, 2011 — forked from bored-engineer/Run.js
MobileDevice NodObjC basic example.
View Run.js
var $ = require('NodObjC')
$.import('MobileDevice');
$.import('CoreFoundation')
// Callback function that's invoked when a device is plugged in
function callback (info, foo) {
try {
console.log('inside callback!')
var i = new $.am_device_notification_callback_info(info)
View purple.js
var FFI = require("node-ffi");
var CUSTOM_USER_DIRECTORY= "/Users/santiago/tmp";
var Purple = new FFI.Library("/Users/santiago/tmp/lib/libpurple", { "purple_util_set_user_dir": [ "void", [ "string" ] ] });
Purple.purple_util_set_user_dir(CUSTOM_USER_DIRECTORY);
View getip.js
var child_process = require("child_process");
function getIPs (cb) {
child_process.exec("ifconfig -a", function (er, o) {
if (er) return cb(er);
cb(null, o.match(/inet (?:addr:)?([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})/g).map(function (i) {
return i.replace(/^inet (?:addr:)?/, '');
}));
})
}
View upnp.js
/* node UPNP port forwarding PoC
This is a simple way to forward ports on NAT routers with UPNP.
This is a not-for-production hack that I found useful when testing apps
on my home network behind ny NAT router.
-satori
usage:
You can’t perform that action at this time.