Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@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 / S.js
Last active April 18, 2024 11:55
S Combinator
/*
S : \x y z -> x z (y z)
*/
// S :: (z -> (a -> b)) -> (z -> a) -> z -> b
function S(x, y, z) {
return x(z)(y(z));
}
// example:
// add :: a -> a -> a
@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.
@buzzdecafe
buzzdecafe / Functor.js
Last active October 18, 2023 07:28 — forked from CrossEye/Functor.js
(function(global) {
global.Functor = function(conf) {
Functor.types[conf.key] = {
obj: conf.obj,
fmap: conf.fmap
};
};
Functor.types = {};
function fail(x) { return []; }
function succeed(x) { return [x]; }
function disj(f1, f2) {
return function(x) {
return f1(x).concat(f2(x));
}
}
function conj(f1, f2) {
@buzzdecafe
buzzdecafe / generator.js
Last active December 16, 2015 13:39
infinite stream fibonacci generator
/*
Fibonacci infinite stream generator. Not hugely exciting yet
*/
var fgen = (function() {
var fn1 = 0, fn2 = 1;
f = function f() {
var curr = fn2;
fn2 = fn1;
fn1 = fn1 + curr;
return fn1;
/*
Factorial of course. Can't talk about recursion without factorial.
*/
function basicFactorial(n) {
return n === 0 ? 1 : n * basicFactorial(n-1);
}
/*
Define a *non-recursive* function that has the factorial function as a fixpoint.
*/