Skip to content

Instantly share code, notes, and snippets.

View kombuchamp's full-sized avatar
💭
[object Object]

Konstantin Belousov kombuchamp

💭
[object Object]
  • Microsoft
  • Serbia
  • 00:37 (UTC +02:00)
View GitHub Profile
@kombuchamp
kombuchamp / index.js
Created January 19, 2021 14:26
Array methods ponyfills UX utilities
// Assume we have ponyfilled versions of array methods
const map = (arr, cb) => [].map.call(arr, cb);
const reduce = (arr, cb) => [].reduce.call(arr, cb);
// What we wanna do without ponyfills
const res = [1,2,3]
.map(x => x * 10)
.reduce((cur, prev) => cur + prev);
// What we can do with ponyfills
@kombuchamp
kombuchamp / index.js
Created January 19, 2020 13:24
JS await pitfall
let result = 0;
const sleep = (ms) => new Promise((resolve)=>{
setTimeout(resolve, ms);
});
const mult = async(val) => {
await sleep(200);
return val * val;
}
#include <future>
#include <vector>
#include <iterator>
#include <thread>
/// <summary>
/// Maps collection using function f1, then reduces resulting collection using f2 on defined number of threads
/// </summary>
/// <param name="p">Iterator pointing at the start of collection</param>
/// <param name="q">Iterator pointing at the end of collection</param>