Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@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 / 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 / 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 / where.js
Created February 13, 2014 02:52
where: create a matching predicate from an object
function where(matchThis) {
var keys = Object.keys(matchThis);
return function(testObj) {
var match = ramda.all(function(key) {
return testObj[key] === matchThis[key];
}, keys);
return match ? testObj : false;
};
}
@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 / solver.js
Last active August 29, 2015 13:58
recursive backtracker
// solver
var R = require('ramda');
function configure(isLeaf, isGoal, getChildren) {
return function recursiveSolve(node, sideEffects) {
return (isLeaf(node)) ? isGoal(node) && sideEffects(node):
R.any(function(child) {
sideEffects(child);
return recursiveSolve(child);
}, getChildren(node));
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
function lazy(f) {
return function () {
var self = this, args = arguments;
return function () {
var data = f.apply(self, args);
return typeof data === "function" ?
data.apply(this, arguments) : data;
};
};
@buzzdecafe
buzzdecafe / xf.js
Created October 17, 2014 13:23
thinking about transducers
var R = require('ramda');
// cf. http://thecomputersarewinning.com/post/Transducers-Are-Fundamental/
function inc(n) {
return n + 1;
}
function meanReducer(acc, x) {
var newAcc = {};
function cond2() {
var cs = [].slice.call(arguments, 0, arguments.length - 1);
var ow = arguments[arguments.length - 1];
return function() {
var i = -1;
while(++i < cs.length) {
var value = cs[i].apply(this, arguments);
if (value) {
return value;
}