Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am naomik on github.
  • I am naomik (https://keybase.io/naomik) on keybase.
  • I have a public key ASAjDBN1U4ilDQA9PRSSs9BegwXOytlWMQSTtYIzOPb1Two

To claim this, I am signing this object:

@naomik
naomik / ConsCarCdr.js
Created Dec 14, 2015 — forked from bishboria/ConsCarCdr.js
JavaScript implementation of cons, car and cdr
View ConsCarCdr.js
function cons(x, y) {
return function(w) { return w(x, y) };
};
function car(z) {
return z(function(x, y) { return x });
};
function cdr(z) {
return z(function(x, y) { return y });
View gist:cebe70c2835122ea6a6c

So, you want to send a motherfucking XMLHttpRequest (XHR, or commonly and falsly known as AJAX.) Too bad, just ran out of motherfucking XMLHttpRequests; but I still have one regular. XHR is not magic. It does not autofuckinmagically send things the way you want them do be sent. It does not do the thinking for you. It just sends an Http Request.

You get a hold on such a prime beast like this:

View MyState.hs
data MyState s a = MyState (s -> (a, s))
get :: MyState s s
get = undefined
put :: s -> MyState s ()
put = undefined
modify :: (s -> s) -> MyState s ()
modify = undefined
@naomik
naomik / improvements.js
Last active Aug 29, 2015
refactoring point-free improvements
View improvements.js
// let pow = y => x => Math.pow(x, y);
// let pow = y => x => idx(y)(iterate(mult(x))(y)(1))
let pow = y => x => repeat(mult(x))(y)(1);
// let foldl = f => i => xs => xs.reduce((r, x) => f(r)(x), i);
let foldl = f => i => xs => xs.reduce(uncurry(f), i);
// let foldr = f => i => xs => xs.reduceRight((r, x) => f(r)(x), i);
let foldr = f => i => xs => xs.reduceRight(uncurry(f), i);
@naomik
naomik / point-free.js
Last active Aug 29, 2015
help me go point free!
View point-free.js
var sub = y => x => x - y;
var idx = i => xs => xs[i]
var len = idx("length");
var head = idx(0);
// this works, but can we go point free?
var last = xs => idx(sub(1)(len(xs)))(xs);
// this feels slightly closer, but i'm still trying to eliminate `xs`
var last = (xs) => compose([idx, sub(1), len])(xs)(xs)
View u-combinator.scm
(define (iterative-improve good-enough? improve first-guess)
((lambda (f) (f f first-guess))
(lambda (f guess)
(if (good-enough? guess) guess (f f (improve guess))))))
(define (iterative-sqrt x)
(iterative-improve (lambda (y) (< (abs (- (square y) x)) 0.001))
(lambda (y) (average y (/ x y)))
1.0))
View person-list_test.jsx
/** @jsx React.DOM */
var assert = require('chai').assert;
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var PersonList = require('./person-list.jsx');
describe('PersonList', function() {
View exercise.json
{
"name": "Colors!",
"author": "Sequoia McDowell <sequoia.mcdowell@gmail.com>",
"dependencies": [
"path",
"process.argv",
"Array.prototype.forEach"
],
"difficulty": 2,
"manifest": [
View modules.md
You can’t perform that action at this time.