Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
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)
@nornagon
nornagon / gist:1294723
Created October 18, 2011 06:06
Broken require
$ cat foo.js
require('share')
$ ls node_modules
share
$ head node_modules/share/package.json
{
"name": "share",
"version": "0.4.1",
"description": "A database for concurrent document editing",
"keywords": ["operational transformation", "ot", "concurrent", "collaborative", "database", "server"],
@nornagon
nornagon / atom.coffee
Created November 12, 2011 05:25
Tiny canvas game framework
window.atom = atom = {}
atom.input = {
_bindings: {}
_down: {}
_pressed: {}
_released: []
bind: (key, action) ->
@_bindings[key] = action
@nornagon
nornagon / sequence.js
Created January 8, 2012 08:38
Sequencing stuff in node.js
function getMoveFromPlayer(player_id, cb) {
process.spawn_child(whatever, cb)
}
function getNextMove() {
if (!gameStillRunning) { return }
getMoveFromPlayer(current_player, function (err, data) {
makeMove(data)
getNextMove()
})
@nornagon
nornagon / gist:2025487
Created March 12, 2012 23:49
Open related file in vim (a la Sublime Text 2's Alt-O)
" Opens a file in [path/to/current_file.*] that isn't already open.
function! RelatedFiles()
return filter(split(globpath(expand('%:h'), expand('%:t:r').'.*')), '!bufloaded(v:val)')
endfunction
function! OpenRelatedFile()
let files = RelatedFiles()
if len(files) > 0
" always open .h files on the left.
if match(files[0], "\.h$") >= 0
exec 'lefta vsplit '.files[0]
@nornagon
nornagon / server.coffee
Created March 19, 2012 11:34
Programmer nomic
coffee = require 'coffee-script'
vm = require 'vm'
connect = require 'connect'
browserChannel = require('browserchannel').server
comm = new (require('events').EventEmitter)
# TODO: sandbox
master = ((comm) ->
code = '''
<a href="http://segment.io" onclick="track('clicked on segment.io')">Yay!</a>
<script>
function track(msg) {
new Image().src = "http://segment.io/track?msg=" + encodeURLComponent(msg)
}
</script>