Skip to content

Instantly share code, notes, and snippets.

View koozdra's full-sized avatar

Dimitri Tishchenko koozdra

View GitHub Profile
@koozdra
koozdra / fb.md
Last active November 16, 2015 19:47
Facebook Graph Api Bug Description
var positioned = ['x', 'y'];
// an parameter object is full if the domain does not contain any falsies
function isFull(object) {
return _(object)
.omit(_.identity)
.keys()
.value()
.length;
}
@koozdra
koozdra / anim.js
Last active March 13, 2016 21:07
Animation loop
// don't have to declare frame, purer
function animate(fn) {
function anim(frame) {
fn(frame);
requestAnimationFrame(_.partial(anim, frame + 1));
}
requestAnimationFrame(_.partial(anim, 0));
}
@koozdra
koozdra / draw.js
Last active February 16, 2016 05:54
var circle = (function() {
// all shapes should show by default at the center of the canvas
var x = 10,
y = 10,
radius = 10;
return {
at: function(x, y) {
this.x = x;
this.y = y;
// haskell
// sort [] = []
// sort (x:xs) = sort lte ++ [x] ++ sort gt
// where lte = [a | a <- xs, a <= x]
// gt = [a | a <- xs, a > x]
var data = [4,5,8,9,1,2,3,9,1,5,1,9,5,3,3,3,8,9];
function sort(data) {
if (data.length === 0) return [];
function mandelbrotRank (timeout, x, y) {
var i = 0,
zx = x,
zy = y;
while (zx*zx + zy*zy < 4 && i < timeout){
var tx = zx*zx - zy*zy + x,
ty = 2*zx*zy + y;
zx = tx;
@koozdra
koozdra / anyall.js
Last active August 6, 2016 22:25
Any and All
function any() {
return _.reduce(arguments, function(sum, n){ return sum || n; }, false);
}
function any() {
return _.some(arguments);
}
function all() {
return _.reduce(arguments, function(sum, n){ return sum && n; }, true);
@koozdra
koozdra / weightedRandom.js
Created October 17, 2016 23:20
Modification free selection of random weighted element
const d = {
share: 5,
promote: 6,
engage: 11,
discover: 1
}
const total = _(d).values().sum();
const buckets = _(d)
@koozdra
koozdra / compose.js
Created November 6, 2016 15:39
Javascript compose using reduce
function compose(...fns) {
return x => _.reduceRight(fns, (acc, f) => f(acc), x);
}
const square = x => x * x;
const double = x => x + x;
const squareDouble = compose(square, double);
const test = compose(); // empty compose acts like identity
@koozdra
koozdra / hashCurry.js
Last active May 4, 2017 16:46
hash parameter functions with partial application
const _ = require('lodash');
function Point(x, y) {
return {x, y};
};
const Color = {
black: {r: 255, g: 255, b: 255, y: 1}
}