Skip to content

Instantly share code, notes, and snippets.

@alexpsi
alexpsi / asyncChunkedMap.js
Created February 25, 2017 20:31
Like Promise.all but executed in chunks, so you can have some async concurrency control.
const chunks = (arr, chunkSize) => {
let results = [];
while (arr.length) results.push(arr.splice(0, chunkSize));
return results;
};
module.exports = (xs, f, concurrency) => {
if (xs.length == 0) return Promise.resolve();
return Promise.all(chunks(xs, concurrency).reduce(
(acc, chunk) => acc.then(() => Promise.all(chunk.map(f))),
@alexpsi
alexpsi / keybase.md
Created October 20, 2016 14:00
keybase

Keybase proof

I hereby claim:

  • I am alexpsi on github.
  • I am alexpsi (https://keybase.io/alexpsi) on keybase.
  • I have a public key whose fingerprint is A848 8F9A 1E2B 21B8 8A3A 0BBF 306D 71A6 4ACD 37EA

To claim this, I am signing this object:

@alexpsi
alexpsi / socket-cheatsheet.js
Created September 25, 2016 16:20 — forked from alexpchin/socket-cheatsheet.js
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender