Skip to content

Instantly share code, notes, and snippets.

View mlsteele's full-sized avatar

Miles Steele mlsteele

View GitHub Profile
@mlsteele
mlsteele / interceptMethod.js
Created July 5, 2012 07:32
Intercepts and wraps a method of a js object.
// function interceptor
var interceptMethod = function(object, methodName, newMethodGen) {
previousMethod = object[methodName]
object[methodName] = newMethodGen(previousMethod)
}
// where newMethodGen is of the form
foo = {x: function() {console.log('foo.x')}}
interceptMethod(foo, 'x', function(f) {
from lib601.sm import *
def LTISM(cCoeffs, dCoeffs):
def parallelAddMany(machines):
return reduce(lambda a,b: ParallelAdd(a,b), machines, Gain(0))
def CascadeMany(machines):
return reduce(lambda a,b: Cascade(a,b), machines, Gain(1))
def RPower(power):
import this
import string
print '\n'.join([''.join([(this.d[c] if c in string.letters else c) for c in line]) for line in this.s.split('\n')])
def f(x, y, z):
print x + y
print z
def f(int x, int y, string z):
print x + y
print z
# pre-apply this to an object's method definition to make it return the
# context and thus be chainable.
# example:
# class FOO
# addThing: make_chainable (e) -> @stuff.push e
make_chainable = (f) -> ->
f.apply this, arguments
this
@mlsteele
mlsteele / IntervalManager.coffee
Created August 6, 2013 17:55
Helper class for managing the execution of javascript interval tasks.
# (written for edX)
# Helper class for managing the execution of interval tasks.
# Handles pausing and restarting.
class IntervalManager
# Create a manager which will call `fn`
# after a call to .start every `ms` milliseconds.
constructor: (@ms, @fn) ->
@intervalID = null
# Start or restart firing every `ms` milliseconds.
@mlsteele
mlsteele / mshw.cls
Created September 8, 2013 18:20
Homework documentclass LaTeX (draft)
%=====================================================================
% mshw.cls
% Provide mshw.cls class
% Derived from jhwhw.cls
% https://gist.github.com/jhwilson/1278588
% http://tex.stackexchange.com/questions/31183/class-file-for-homework-assignments
%=====================================================================
%=====================================================================
% Identification
@mlsteele
mlsteele / fes.sh
Last active August 29, 2015 14:01
file extension histogram
#!/usr/bin/env bash
find . -type f | grep "." | grep -v ".git" | sed "s/.*\.\(.*\)/\1/" | sort | uniq -c | sed "s/^[ \t]*//" | sort -n
@mlsteele
mlsteele / script
Created May 31, 2014 04:22
Created by shoutcode
ag fofo
@mlsteele
mlsteele / script
Created May 31, 2014 04:26
Created by shoutcode
ag fofo