Skip to content

Instantly share code, notes, and snippets.

@skatenerd
skatenerd / parallel_http.js
Created April 3, 2015 06:48
parallel http
var ParallelHttp = {
forkjoin: function(requests, join_handler){
var results = [];
var identity = function(i){return i};
$.map(requests, function(request){
var old_success = request.success || function(){};
var old_error = request.error || function(){};
var old_complete = request.complete || function(){};
request.success = function(data) {
old_success(data);
@skatenerd
skatenerd / bird_wadler.txt
Last active June 16, 2024 11:41
A gem from Bird and Wadler's Introduction to Functional Programming
"A good way to tackle such problems is to consider a simpler problem first.
There is, of course, no guarantee that solutions obtained for simpler problems
can be used directly in the problem which inspired them; they may only serve
to familiarise the solver with some of the features and difficulties involved.
Even so, the work is not wasted; familiarity with a problem is one of our most
important tools for solving it. And often we will be able to use the solution
directly or by adapting it."
!!!
def generate_inverse_transformations(left,right):
#?????
return (lambda x: x, lambda x: x)
left_form = {
'key': 'abc123',
'name': {'first': 'joe', 'last': 'stein'},
'triples': {1: 3, 2: 6, 3: 9, 4: 12, 5: 15},
'opposites': [('low','high'),('big','small')]
}
@skatenerd
skatenerd / lift_and.py
Created March 23, 2015 02:25
Lifting "&" to apply to functions
class CombinableFunction(object):
def __init__(self, function):
self.function = function
def __call__(self, *args):
return self.function(*args)
def __or__(self, other):
def new_function(*args):
return self.function(*args) | other(*args)
@skatenerd
skatenerd / fibonacci.hs
Last active August 29, 2015 14:15
watbonacci
statefulSequence state transformstate plop = plop state : statefulSequence (transformstate state) transformstate plop
fib = statefulSequence [1, 1] (\[first, second] -> [second, first + second]) (!! 0)
main = print $ take 9 fib
@skatenerd
skatenerd / gotcha.py
Created January 4, 2015 16:53
python gotcha
def make_adder():
grand_total = 0
def adder(to_add):
print "Grand total moved from: %s" % grand_total
grand_total += to_add
print "To: %s \n" % grand_total
return grand_total
return adder
adder = make_adder()
import Data.Bool
import qualified Data.Map.Lazy as Map
data Encoding = Encoding (Bool, Bool, Bool) deriving (Eq, Ord)
data Assignment = Assignment { initial::Encoding, subsequent::[Encoding]}
data Letter = A | B | C | D deriving (Show, Enum, Eq, Ord)
type Solution = Map.Map Letter Assignment
@skatenerd
skatenerd / tables.js
Created November 12, 2014 14:23
angualr-style table filtering
<!DOCTYPE html>
<html lang="en" ng-app="temperature-converter" class="no-js">
<head>
<meta charset="utf-8">
<script src="./x.jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var TableController = function(search_box, table) {
this.search_box = search_box;
this.table = table;
@skatenerd
skatenerd / main.html
Created November 12, 2014 14:21
databinding
<!DOCTYPE html>
<html lang="en" ng-app="temperature-converter" class="no-js">
<head>
<meta charset="utf-8">
<script src="./x.jquery-1.8.3.min.js"></script>
<script src="./temperature.js"></script>
<script type="text/javascript">
var TemperatureController = function(fahrenheit_input, celsius_input) {
var controller = this;
@skatenerd
skatenerd / clump.py
Last active August 29, 2015 14:06
python clump
from random import shuffle
to_clump = [0, 0.2, 5, 9, 9.1, 100, 100.2]
shuffle(to_clump)
def clump_same(comparables, distance_threshold):
def do_clump(so_far, current):
last_clump = so_far[-1]
lowest_in_last_clump = last_clump[0]
if (current - lowest_in_last_clump) < distance_threshold: