This file contains 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
# To arrow functions | |
function ?(\(.*\)) | |
$1 => | |
function (\w*)(\(.*\)) | |
const $1 = $2 => |
This file contains 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
let _id = 0 | |
const id = () => { | |
_id++ | |
return _id | |
} | |
type Entity<Components = {}, Methods = {}> = { | |
id: number | |
} & Components & | |
Methods |
This file contains 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 * as m from 'mithril' | |
import * as stream from 'mithril/stream' | |
interface State { | |
error: boolean | |
counter: number | |
} | |
// state | |
const counter = stream(0) |
This file contains 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 n2w(n, w) { | |
n %= 100; | |
if (n > 19) { | |
n %= 10; | |
} | |
switch (n) { | |
case 1: | |
return w[0]; | |
This file contains 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 debounce(fn, delay) { | |
var timer = null; | |
return function () { | |
var context = this, args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
fn.apply(context, args); | |
}, delay); | |
}; | |
} |
This file contains 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
var curry = function(fn) { | |
var args = [] | |
return function c() { | |
args = args.concat(Array.prototype.slice.call(arguments)) | |
if (args.length >= fn.length) return fn.apply(this, args) | |
return c | |
} | |
} |
This file contains 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
// create a one-time event | |
function onetime(node, type, callback) { | |
// create event | |
node.addEventListener(type, function(e) { | |
// remove event | |
e.target.removeEventListener(e.type, arguments.callee); | |
// call handler | |
return callback(e); | |
}); |
This file contains 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
var tapEvent; | |
if (Modernizr.touch){ | |
tapEvent = 'touchstart'; | |
} else { | |
tapEvent = 'click'; | |
} | |
var animationEndEventNames = { | |
WebkitAnimation: 'webkitAnimationEnd', |
This file contains 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
ppi = (w,h,d) -> | |
dp = Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2)) | |
dp/d |