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
// calculate number of DAO tokens for MIST | |
var calcShit = function(num) { | |
return (+num).toFixed(0) + '0000000000000000' | |
}; |
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
// aliorbank login | |
var pass = prompt().trim(); | |
[].map.call(document.querySelectorAll('input[type=password]'), function(inp, i){ | |
if (!inp.readOnly) { | |
inp.value = pass.charAt(i); | |
} | |
}); |
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 memoize(func) { | |
let mem = {}; | |
return (...args) => { | |
let dest = args.reduce((mem, arg) => { | |
mem.args = mem.args || []; | |
mem.mems = mem.mems || []; | |
let idx = mem.args.indexOf(arg); | |
let obj; |
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 Alphabet = { | |
BINARY: '01', | |
OCTAL: '01234567', | |
DECIMAL: '0123456789', | |
HEXA_DECIMAL: '0123456789abcdef', | |
ALPHA_LOWER: 'abcdefghijklmnopqrstuvwxyz', | |
ALPHA_UPPER: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', | |
ALPHA: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', | |
ALPHA_NUMERIC: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
}; |
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
// calculating Fibonacci Number using Binet's Formula | |
fib = (n) => { | |
let phi = (Math.sqrt(5) + 1) / 2; | |
return Math.round((Math.pow(phi, n) - Math.pow(-phi, -n)) / Math.sqrt(5)); | |
}; |
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
// return array with unique elements | |
function unique(arr) { | |
return arr.filter((el, i) => arr.indexOf(el, i+1) === -1); | |
} | |
// return array with unique elements by property | |
function uniqueByProp(arr, sel) { | |
let filter = arr.map(sel).map((el, i, arr) => arr.indexOf(el, i+1) === -1); | |
return arr.filter((n, i) => filter[i]); |
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 resolve = (tokens, vars) => { | |
let getVal = (t, vars) => { | |
if (isIdent(t)) { | |
if (t in vars) return +vars[t]; | |
throw Error(`variable ${t} is not defined`); | |
} | |
return +t; | |
}; | |
let isOp = (str) => op.s.indexOf(str) !== -1; | |
let isIdent = (str) => !!str.match(/^[a-z_][a-z_\d]*$/i); |
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 levenshteinDistance(a, b) { | |
if (a.length === 0) return b.length; | |
if (b.length === 0) return a.length; | |
let matrix = []; | |
for (let i = 0; i <= b.length; ++i) { | |
matrix[i] = [i]; | |
} | |
for (let j = 0; j <= a.length; ++j) { |
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
// convert numbers to words up to 1e6 - 1 | |
function number2words(n) { | |
let ones = 'zero one two three four five six seven eight nine'.split(' '); | |
let tens = 'zero ten twenty thirty forty fifty sixty seventy eighty ninety'.split(' '); | |
let teens = 'thir four fif six seven eigh nine'.split(' '); | |
let w = (n) => { | |
if (n < 10) return ones[n]; | |
if (n < 13) return 'ten eleven twelve'.split(' ')[n - 10]; |
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 RomanNumerals = { | |
toRoman: (n) => { | |
let m = [ | |
['I', 'V'], | |
['X', 'L'], | |
['C', 'D'], | |
['M'] | |
]; | |
let c = ' 0 00 000 01 1 10 100 1000 02'.split(' '); | |
let res = []; |