Skip to content

Instantly share code, notes, and snippets.

@etale
etale / .bash_profile
Last active February 17, 2016 08:08
my .bash_profile for Windows
alias ls='ls --show-control-chars --ignore={NTUSER*,ntuser*} '
@etale
etale / math-number.js
Last active February 26, 2016 01:47
copy Math properties to Number.prototype
Object.getOwnPropertyNames(Math).map(p=>Object.defineProperty(Number.prototype,p,Math[p].constructor!==Function?{value:Math[p]}:Math[p].length<2?{get(){return Math[p](this)}}:{value(a){return Math[p](this,a)}}))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@etale
etale / ycombinator.js
Created November 4, 2015 07:18
ycombinator.js
var Y = f => (x => _ => f(x(x))(_))(x => _ => f(x(x))(_))
var fac = f => x => x < 2 ? 1 : x * f(x - 1)
var fib = f => x => x < 2 ? x : f(x - 1) + f(x - 2)
var a = Array(10).fill().map((_, i) => i)
console.log(a.map(Y(fac)))
console.log(a.map(Y(fib)))
@etale
etale / digest.js
Created October 23, 2015 05:20
Web Cryptography API Sample
var b2hex = buf => Array.from(new Uint8Array(buf)).map(a => {a = a.toString(16); return '00'.slice(a.length) + a }).join('')
, digest = buf => crypto.subtle.digest({name: 'SHA-256'}, buf)
@etale
etale / genArray.js
Created September 17, 2015 05:29
generate the array [0, ..., 999999]
Array(1e6).fill(0).map((a, i) => i)
@etale
etale / numbers.js
Last active August 29, 2015 14:19
numbers.js
Object.prototype.eql = function (a) {
return this.__proto__ === a.__proto__ && this._eql(a)
}
Object.prototype._eql = function (a) {
return this === a
}
Array.prototype._eql = function (a) {
return this.length === a.length && this.every(function (e, i) { return e === a[i] })
}
Number.prototype._eql = function (a) {
@etale
etale / makeId.js
Created September 4, 2014 08:53
makeId.js
var pw = function () {
var arr = new Uint32Array(8)
crypto.getRandomValues(arr)
return Array.apply([], arr).map(function (x) {
x = x.toString(16)
return ['00000000'.slice(x.length), x].join('')
}).join('')
}