Skip to content

Instantly share code, notes, and snippets.

View Oikio's full-sized avatar

Oikio Oikio

  • Germany, Munich
View GitHub Profile
@Oikio
Oikio / ppi.coffee
Last active December 19, 2015 05:49
Calculate ppi.
ppi = (w,h,d) ->
dp = Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2))
dp/d
@Oikio
Oikio / EventNames.js
Last active December 20, 2015 13:19
Animation and transition events naming in coffee with modernizr.
var tapEvent;
if (Modernizr.touch){
tapEvent = 'touchstart';
} else {
tapEvent = 'click';
}
var animationEndEventNames = {
WebkitAnimation: 'webkitAnimationEnd',
@Oikio
Oikio / onetime
Created December 6, 2013 13:10
One time event setter.
// 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);
});
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
}
}
function debounce(fn, delay) {
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
function n2w(n, w) {
n %= 100;
if (n > 19) {
n %= 10;
}
switch (n) {
case 1:
return w[0];
@Oikio
Oikio / counter.ts
Created November 15, 2017 19:42
Thoughts about reactive architecture
import * as m from 'mithril'
import * as stream from 'mithril/stream'
interface State {
error: boolean
counter: number
}
// state
const counter = stream(0)
let _id = 0
const id = () => {
_id++
return _id
}
type Entity<Components = {}, Methods = {}> = {
id: number
} & Components &
Methods
@Oikio
Oikio / list
Last active February 7, 2018 10:36
Usefult regexps for TS/JS refactoring
# To arrow functions
function ?(\(.*\))
$1 =>
function (\w*)(\(.*\))
const $1 = $2 =>