Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@buzzdecafe
buzzdecafe / s2.js
Last active December 7, 2017 22:44
const S = {
fromArray: xs => sink => {
for (let i=0; i<xs.length; ++i)
if (sink(xs[i]))
return true
},
map: fn => stream => sink => stream(x => sink(fn(x))),
@buzzdecafe
buzzdecafe / curry.js
Last active November 19, 2017 15:00
decorated curry
const meta = Symbol('@@ramda-meta');
const initMeta = f => ({ func: f, arity: f.length, seenArgs: [] });
const getMeta = f => f[meta] || initMeta(f);
const setMeta = (arg, f) => {
const fMeta = getMeta(f);
f[meta] = {
func: fMeta.func,
@buzzdecafe
buzzdecafe / Lazy.js
Created May 27, 2017 12:36 — forked from i-am-tom/Lazy.js
A Fantasy Land-compliant type for lazy computation.
const fl = require('fantasy-land')
//- Lazy holds a vaue in a thunk, effectively delaying
//- evaluation until required. This is useful when we're
//- in a situation with either very large data set or
//- cyclical data.
//@ make stack-safe.
//> type Lazy a = Unit -> a
function Lazy(run) {
@buzzdecafe
buzzdecafe / compose.js
Last active March 27, 2017 16:22
curried binary compose
// first try:
R.cc = R.curry(function cc(f, g) {
return R.curryN(g.length, function() {
var gargs = Array.prototype.slice.call(arguments, 0, g.length);
var fargs = Array.prototype.slice.call(arguments, g.length);
return f.apply(this, [g.apply(this, gargs)].concat(fargs));
});
});
// so this works:
@buzzdecafe
buzzdecafe / gridstyle.css
Last active January 1, 2016 07:51
sudoku solver
#grid {
border: 1px solid #000;
border-spacing:0;
}
#grid tr:nth-child(3) td,
#grid tr:nth-child(6) td {
border-bottom: 1px solid #000;
}
@buzzdecafe
buzzdecafe / pointer-events.html
Last active December 28, 2015 14:29
pass pointer events through an svg to its parent element
<!doctype html>
<html>
<head>
<style>
#wrapper {
height: 200px;
padding: 20px;
background-color: #ddeeff;
}
#vector {
@buzzdecafe
buzzdecafe / db.js
Created October 4, 2013 00:38
indexedDB API exercise
// assuming we have indexedDB
var version = 3;
var dbConn = indexedDB.open("db", version);
var db;
dbConn.onerror = function(e) {
console.log('error connecting to be');
};
dbConn.onsuccess = function(e) {
@buzzdecafe
buzzdecafe / composition.js
Last active December 20, 2015 21:09
working out composition problems in Ramda
// currently in Ramda:
var compose = R.compose = function() { // TODO: type check of arguments?
var fns = slice(arguments);
return function() {
return foldr(function(fn, args) {return [fn.apply(this, args)];}, slice(arguments), fns)[0];
};
};
//...
var useWith = R.useWith = _(function(fn /*, tranformers */) {
@buzzdecafe
buzzdecafe / generators.js
Last active December 19, 2015 12:18
generators again. tweaking scott's generators for ramda (cf. https://github.com/CrossEye/ramda/blob/master/examples/generators.js)
// require("ramda");
var gens = (function() {
var trampoline = function(fn) {
var result = fn.apply(this, tail(arguments));
while (typeof result == "function") {
result = result();
}
return result;
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.