Skip to content

Instantly share code, notes, and snippets.

View davidchambers's full-sized avatar

David Chambers davidchambers

View GitHub Profile
@jethrolarson
jethrolarson / future_example.js
Last active August 29, 2015 14:23
Playing with Future
var R = require('ramda');
var Future = require('ramda-fantasy').Future;
//Wrap ajax in a future
//:: String -> Future String
var fetch = function(url) {
return new Future(function(rej, res){
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", res, false);
oReq.addEventListener("error", rej, false);
oReq.addEventListener("abort", rej, false);
@raine
raine / index.js
Last active September 23, 2015 05:58
const { Future, IO } = require('ramda-fantasy');
const join2 = curryN(2, require('path').join);
const npa = require('npm-package-arg');
const ALIAS = /:([^!]+)/;
const EXTEND = /!$/;
const parseAlias = pipe(
S.match(ALIAS), chain(nth(1)));
const parseExtend = pipe(
S.match(EXTEND), map(T));
@adrusi
adrusi / open_in_hashify.rb
Created May 15, 2011 19:46
TextMate command to open a markdown document in hashify.me
#!/usr/bin/env ruby
require "base64"
data = STDIN.read
%x[open http://hashify.me/#{Base64.encode64(data)}]
=begin
+-[ COMMAND SETTINGS ]------------+
| Save: nothing |
| Input: entire document |
@sandfox
sandfox / npm_install_out.md
Created September 25, 2013 10:45
Why I hate grunt....

This is just the dependency output from npm install

FML

karma-script-launcher@0.1.0 node_modules/karma-script-launcher

karma-firefox-launcher@0.1.0 node_modules/karma-firefox-launcher

karma-chrome-launcher@0.1.0 node_modules/karma-chrome-launcher
var Option = require('fantasy-options')
var Some = Option.Some;
var None = Option.None;
var Compose = function(x){
this.val = x;
}
Compose.prototype.map = function(f){
return new Compose(this.val.map(function(u){return u.map(f); }));
--dropWhereRepeated [1, 2, 2, 3, 3, 5, 7, 10]
--[1,5,7,10]
dropWhereRepeated :: (Eq a) => [a] -> [a]
dropWhereRepeated [] = []
dropWhereRepeated [x] = [x]
dropWhereRepeated (x : y : xs)
| x == y = dropWhereRepeated (dropWhile (== x) (xs))
| otherwise = x : dropWhereRepeated (y : xs)
@jethrolarson
jethrolarson / _usage.js
Last active April 25, 2016 01:10
xface - Functional Interface library for typed common apis
//Some fantasy implementations
const Just = require('./just')
const Cant = require('./cant')
const List = require('./list')
//Spec file that defines what arguments are used for type identification
const fantasy = require('./fantasy')
//The magic.
const {chain, map, index} = require('../../src/xface')(fantasy, [Just, Cant])
@jethrolarson
jethrolarson / exampleUsage.js
Last active June 26, 2016 21:05
AGeneric interface fantasy-land objects
var Maybe = require('./maybe.js')
var List = require('./list.js')
//Pass fantasy implementations to it
var {concat, map} = require('fantasy')({Maybe, List})
mapDouble = map(a => 2 * a)
mapDouble([1, 2])
//[2, 4]
@safareli
safareli / Array.chainRec.js
Last active December 27, 2016 01:03
Implementation of ChainRec from Fantasy Land specification for Array
var flatten = Function.prototype.apply.bind([].concat, [])
Array.prototype.chain = function(f) {
return flatten(this.map(f))
}
var stepNext = function (x) { return {value: x, done: false }; };
var stepDone = function (x) { return {value: x, done: true }; };
Array.chainRec = function _chainRec(f, i) {
var todo = [i];
var res = [];
const after = t => x => cont => {
const id = setTimeout (cont, t, x)
return () => clearTimeout (id)
}
const map = f => run => cont => run(x => cont (f (x)))
const chain = f => run => cont => run(x => f (x) (cont))
const run = chain (x => after (2000) (`${x}C`))
(map (x => `${x}B`)