Skip to content

Instantly share code, notes, and snippets.

View mine.js
// ------------------------------------------------------------------
// function is now reusable
// better stacktrace errors because it has a name
// much flatter code
function fadeOutAndRemove(event) {
var $elem = $(this);
$elem.fadeOut(300, function() {
$elem.remove();
});
}
@naomik
naomik / restore.php
Last active Aug 29, 2015
Haters gonna hate
View restore.php
#!/usr/bin/env php
<?php
// set descriptors
$desc = array(
0 => array("file", "php://stdin", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
@naomik
naomik / after.php
Last active Aug 29, 2015
static variables in functions make things nice sometimes.
View after.php
<?php get_header() ?>
<div class="row">
<?php if (have_posts()) {
// dividers helper
$display_dividers = function() {
static $i = 0;
$i++;
View authorisation.pro
type_person(bigco_it_guy).
type_person(bigco_big_boss).
type_person(bigco_web_manager).
type_person(bigco_web_worker_1).
type_person(bigco_web_worker_2).
type_person(bigco_web_worker_3).
type_person(bigco_mobile_manager).
type_person(bigco_mobile_worker_1).
type_person(bigco_mobile_worker_2).
type_person(bigco_mobile_worker_3).
View modules.md
View exercise.json
{
"name": "Colors!",
"author": "Sequoia McDowell <sequoia.mcdowell@gmail.com>",
"dependencies": [
"path",
"process.argv",
"Array.prototype.forEach"
],
"difficulty": 2,
"manifest": [
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 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))
@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)
@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);
You can’t perform that action at this time.