Skip to content

Instantly share code, notes, and snippets.

View animatedlew's full-sized avatar

Lewie [m80] animatedlew

View GitHub Profile
const KeyManager = {
keys: {},
setupEvents() {
if (!this.isActive) {
this.isActive = true;
document.addEventListener("keydown", KeyManager._onKeyDown);
document.addEventListener("keyup", KeyManager._onKeyUp);
}
},
removeEvents() {
function add(a, b) {
if (a >= 0) while(a--) b++;
else while(a++) b--;
return b;
}
console.log(add( 5, 2)); // 7
console.log(add(-5, 2)); // -3
console.log(add( 5,-2)); // 3
console.log(add(-5,-2)); // -7
@cvogt
cvogt / gist:9193220
Last active February 13, 2022 13:50 — forked from ruescasd/gist:7911033
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
import scala.slick.lifted.CanBeQueryCondition
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
import java.sql.Date
@animatedlew
animatedlew / unflatten.js
Last active December 27, 2015 15:29 — forked from panda01/Unflatten
function unflatten(list, count) {
return _.map(_.range(Math.ceil(list.length/count)), function(mul) {
return list.slice(mul*count, mul*count+count);
});
}
console.log(unflatten(_.range(1, 14), 3));
// [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13]]
@panda01
panda01 / Unflatten
Created November 7, 2013 03:13
Functional unflatten in js
function unflatten(list, count) {
var ret = [];
// For every group
_.range(Math.ceil(list.length/count)).forEach(function(mul) {
ret.push(list.slice(mul*count, mul*count+count));
});
return ret;
}
console.log(unflatten(_.range(1, 13), 3));