This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const KeyManager = { | |
| keys: {}, | |
| setupEvents() { | |
| if (!this.isActive) { | |
| this.isActive = true; | |
| document.addEventListener("keydown", KeyManager._onKeyDown); | |
| document.addEventListener("keyup", KeyManager._onKeyUp); | |
| } | |
| }, | |
| removeEvents() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); |