Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@nornagon
nornagon / require.js
Created January 23, 2010 04:45
asynchronous require() for JavaScript. Uses prototype.js.
var require = (function () {
var _required = {};
return (function (url, callback) {
if (typeof url == 'object') {
// we've (hopefully) got an array: time to chain!
if (url.length > 1) {
// load the nth file as soon as everything up to the n-1th one is done.
require(url.slice(0,url.length-1), function () {
require(url[url.length-1], callback);
});
from foo import *
initialise()
print my_var
<html>
<head>
<title>blah</title>
<script src="../socket.io/socket.io.js"></script>
<script src="jquery-1.4.4rc2.js"></script>
<script src="main.js"></script>
<style>
canvas#canvas {
position: absolute;
left: 0;
@nornagon
nornagon / foo.test.js
Created February 21, 2011 03:15
Run node.js tests, each in their own node process.
var assert = require('assert')
, path = require('path')
function some_helper(foo) {
assert.equal(foo, 4)
}
module.exports = {
'test array length': function (test) {
some_helper([1,2,3,4].length)
@nornagon
nornagon / .vimrc
Created May 3, 2011 22:55
My .vimrc
" duh
syn on
filetype plugin indent on
" the only TRUE tab settings
set ts=2 sw=2 noet tw=79 ai smarttab
" keep 4 lines between the cursor and the edge of the screen where possible
set so=4
@nornagon
nornagon / thing.vim
Created May 13, 2011 08:04
threads, python, vim
function! Thing()
py << EOF
import vim, thread, time
def go():
time.sleep(2)
vim.current.buffer[0] = "foo"
thread.start_new_thread(go, ())
EOF
endfunction
test.deepEqual ['x',4], type._transformPath(['x',3], {p:['x',0], li:0})
test.deepEqual ['x',3], type._transformPath(['x',3], {p:['x',5], li:0})
test.deepEqual ['x',3], type._transformPath(['x',3], {p:['x',0,'x'], li:0})
test.deepEqual ['x',3,'x'], type._transformPath(['x',3,'x'], {p:['x',5], li:0})
test.deepEqual ['x',4,'x'], type._transformPath(['x',3,'x'], {p:['x',0], li:0})
[56 of 58] Compiling Distribution.Simple.Configure ( Distribution/Simple/Configure.hs, dist/build/Distribution/Simple/Configure.o )
[57 of 58] Compiling Distribution.Simple.Install ( Distribution/Simple/Install.hs, dist/build/Distribution/Simple/Install.o )
[58 of 58] Compiling Distribution.Simple ( Distribution/Simple.hs, dist/build/Distribution/Simple.o )
Registering Cabal-1.8.0.6...
Installing library in /Users/nornagon/.cabal/lib/Cabal-1.8.0.6/ghc-7.0.3
Registering Cabal-1.8.0.6...
<command line>: cannot satisfy -package Cabal-1.10.1.0:
Cabal-1.10.1.0-49678efb6bfc399545e2b61629b900e2 is unusable due to missing or recursive dependencies:
process-1.0.1.5-107ac5b78a5845608025ca13d328fdc5
(use -v for more information)
obj = sharejs.open('http://foo:3300/', 'doc_name', 'json')
obj.on('changed', function (ev) {...})
obj.at().set({}) // initial document
foo = obj.at('foo')
foo.set([0]) // { p: ['foo'], oi: [0] }
foo.push(3) // { p: ['foo', 1], li: 3 }
foo.insert(0, ['bar']) // { p: ['foo', 0], li: ['bar'] }
foo.get() // => [['bar'],0,3]
foo.at(0).push('baz') // { p: ['foo',0,1], li: 'baz' }
@nornagon
nornagon / network-traffic.js
Created July 2, 2011 03:37
Monitor network usage with SNMP
var exec = require('child_process').exec
function howManyOctets(cb) {
child = exec('snmpwalk -v 2c -c admin 192.168.0.1 IF-MIB::ifHCInOctets.1', // change to .32 to measure external usage
function (error, stdout, stderr) {
var numOctets = 0
stdout.split('\n').forEach(function (line) {
numOctets += parseInt(/: (\d+)/.exec(stdout)[1])
})
cb(numOctets)