Skip to content

Instantly share code, notes, and snippets.

View joyrexus's full-sized avatar

J. Voigt joyrexus

View GitHub Profile
@joyrexus
joyrexus / gists.coffee
Last active December 16, 2015 14:20
List gists of a user and select one to open.
#!/usr/bin/env coffee
###
gists - List gists of a user and select one to open.
`gists USER` will enumerate the most recent gists of USER:
$ gists joyrexus
0 Decorator for aliasing class methods.
1 Powerset implementations in coffeescript.
@joyrexus
joyrexus / y.coffee
Created April 23, 2013 22:51
Y-combinator
# http://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator
#
# λf . (λx . x x)(λy . f (λv . ((y y) v)))
Y = (f) -> ((x) -> x x)((y) -> f ((v) -> (y y) v))
@joyrexus
joyrexus / ready.min.js
Created May 8, 2013 17:18
$(document).ready( ... ) sans jquery.
// see https://github.com/ded/domready and http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
!function(a,ctx,b){typeof module!="undefined"?module.exports=b():typeof
define=="function"&&typeof define.amd=="object"?define(b):ctx[a]=b()}("domready",this,
function(a){function m(a){l=1;while(a=b.shift())a()}var b=[],c,d=!1,e=document,f=e.
documentElement,g=f.doScroll,h="DOMContentLoaded",i="addEventListener",
j="onreadystatechange",k="readyState",l=/^loade|c/.test(e[k]);return e[i]&&e[i](h,
c=function(){e.removeEventListener(h,c,d),m()},d),g&&e.attachEvent(j,c=function(){/^c/.
test(e[k])&&(e.detachEvent(j,c),m())}),a=g?function(c){self!=top?l?c():b.push(c):
function(){try{f.doScroll("left")}catch(b){return setTimeout(function(){a(c)},50)}c()}()}:
function(a){l?a():b.push(a)}})
@joyrexus
joyrexus / leap.pipe.coffee
Last active December 17, 2015 04:28
Pipe samples from the Leap's websocket stream to stdout.
#!/usr/bin/env coffee
###
Pipe samples from the Leap's websocket stream to stdout.
USAGE
leap.pipe.coffee [no. of samples]
leap.pipe.coffee 1000 > hand.data
@joyrexus
joyrexus / leap.rec.coffee
Last active December 17, 2015 05:09
Pipe/save a specified number of frames streamed from the Leap's websocket.
#!/usr/bin/env coffee
###
leap.rec - save a set of frames streamed from the Leap's websocket.
USAGE
leap.rec.coffee [no.-of-frames [file.json]]
leap.rec.coffee # stream 100 frames to stdout
leap.rec.coffee 1000 # stream 1000 frames to stdout
@joyrexus
joyrexus / README.md
Last active October 23, 2019 23:32
Partition a list into N chunks of nearly equal size.

UPDATE: Use the method in this gist instead.

List Partitioning

We want to partition a list into N chunks where we use every item in the original list and the resulting chunks differ in size by at most one element.

We devised a chunk method for this, admittedly kinda hackish ... but it works.

@joyrexus
joyrexus / chunk.py
Last active December 17, 2015 07:19
Partition a list into N chunks of nearly equal size.
def chunk(L, n):
'''
Partition L into n chunks using every item in L and
such that the resulting chunks differ in size by at
most one element.
>>> L = ['a', 'b', 'c', 'd']
['a', 'b', 'c', 'd']
>>> chunk(L, 2)
[['a', 'b'], ['c', 'd']]
@joyrexus
joyrexus / Makefile
Created May 15, 2013 16:06
Phony target for listing all targets in a Makefile.
.PHONY: list
list:
@perl -ne'print "$$1\n" if /^([^\.][\w\.]*):/' Makefile
@joyrexus
joyrexus / README.md
Last active December 17, 2015 13:19
Query script and report for NORC request.

README

NORC is requesting counts of word types and tokens for each student (for each story) as well as MLU (mean length of utterance).

NOTE: MLU was requested, but I'm not sure how to obtain it given that there are often multiple utterances per row/field and these utterances are not reliably/consistently delimited.)

@joyrexus
joyrexus / maybe.coffee
Created May 24, 2013 20:17
Maybe monad in CoffeeScript.
MONAD = (modifier) ->
prototype = Object.create null
unit = (value) ->
monad = Object.create prototype
monad.bind = (func, args...) -> func(value, args...)
modifier(monad, value) if typeof modifier is 'function'
monad
unit.lift = (name, func) ->
prototype[name] = (args...) ->