Skip to content

Instantly share code, notes, and snippets.

function manager(tasks, worker, concurrency) {
const res = [];
function assign(w) {
return new Promise((resolve) => {
const t = tasks.shift();
if (t === undefined) {
return resolve();
}

Keybase proof

I hereby claim:

  • I am odesskij on github.
  • I am odesskij (https://keybase.io/odesskij) on keybase.
  • I have a public key ASAvwRrrj9uHlKSc60fvgUrOBqb9XyK6lp9yUFjAXufuXQo

To claim this, I am signing this object:

function fn(number) {
return parseInt(number.toString(2).split('').reverse().join(''), 2);
}
// 1000 -> 0001 (8 -> 1)
console.log('fn(8)', fn(8) === 1);
// 1100 -> 0011 (12 -> 3)
console.log('fn(12)', fn(12) === 3);
// 1110 -> 0111 (14 -> 7)
console.log('fn(14)', fn(14) === 7);
@odesskij
odesskij / qsort.coffee
Created August 20, 2015 16:30
qsort with coffee
do () ->
array = (Math.round 100*Math.random() for i in [0..9])
console.log array, '<--- input'
qsort = (array) ->
sort = (array, left, right) ->
l = left
r = right
mid = array[Math.round((l + r)/2)]
memoize = (func, hashFunc) ->
memo = {}
hashFunc = hashFunc or (n) -> n
() ->
key = hashFunc.apply @, arguments
if memo[key]? then memo[key] else memo[key] = func.apply @, arguments
fibonacci = memoize (n) ->
if n < 2 then n else fibonacci(n - 1) + fibonacci(n - 2)
fibMemoize = (n) ->
memo = [1, 1]
for i in [2...n]
memo[i] = memo[i - 1] + memo[i - 2]
memo[n - 1]
console.log fibMemoize 10
fibReq = (n) ->
if n < 2 then n else fibReq(n - 1) + fibReq(n - 2)
class Events
constructor: () ->
@events = {}
trigger: (event, args...) ->
if @events[event]?
e = @events[event]
for h in e.handlers
h.callback.apply h.context, args
return;
on: (event, callback, context) ->