Skip to content

Instantly share code, notes, and snippets.

@pre1ude
pre1ude / io.js
Created August 22, 2021 01:09
a pattern which handle the req, res relation
const res = f =>
(req, res) =>
f(req, data => {
res.send(data)
res.end()
})
const inq = db_name =>
(req, cb) =>
io.engine(db_name, data => cb(data))
@pre1ude
pre1ude / Chain.js
Created January 22, 2019 09:40
simplest chain operation with async enabled
const Chain = f => ({
f,
write: v => {
f(() => console.log(v))
return Chain(f)
},
wait: ms => Chain(next => setTimeout(() => f(next), ms))
})
let obj = Chain(next => next())
const curry = f => (...args) =>
args.length < f.length
? curry(f.bind(undefined, ...args))
: f(...args)
// : f(...args.slice(0, f.length))
const add = (a, b, c) => a + b + c
const cAdd = curry(add)
@pre1ude
pre1ude / create-class-like-functions.js
Created October 5, 2018 15:04 — forked from babakness/create-class-like-functions.js
Helpers for creating class like functions that can be invoked without new
const assoc = ( prop, value, obj ) =>
Object.assign( {}, obj, { [prop]: value })
const reducer = ( $values, accumulate, [key,val] ) => assoc( key, val.bind( undefined, ...$values ), accumulate )
export const bindValuesToMethods = ( $methods, ...$values ) =>
Object.entries( $methods ).reduce( reducer.bind( undefined, $values ), {} )
export const prepareInstance = (instanceMethods, staticMethods = ({}) ) => Object.assign(
@pre1ude
pre1ude / create-remote-from-local-git.md
Last active September 14, 2017 03:02
create a remote git repository from your local git repository

on your local machine:

cd my_project
git init
git add *
git commit -m "Initial commit"
git remote add origin example.com:my_project.git
// add your remote url to your local git repository
git pull -r origin master
// fetch from origin and rebase on master, which will rewind to HEAD and reapply your local commits on top of it
@pre1ude
pre1ude / regression1.md
Created June 23, 2017 09:16
regression test result

Starting benchmark context.js

EventEmitter3@0.1.6 x 12,223,752 ops/sec ±0.98% (88 runs sampled)
EventEmitter3(master) x 11,959,501 ops/sec ±1.66% (91 runs sampled)
EventEmitter3(now) x 12,161,424 ops/sec ±0.52% (95 runs sampled)
Fastest is EventEmitter3@0.1.6

Starting benchmark emit.js

EventEmitter3@0.1.6 x 12,280,807 ops/sec ±0.52% (94 runs sampled)
@pre1ude
pre1ude / perf4.md
Created June 23, 2017 06:37
no breaking change to removeListener()

Starting benchmark context.js

EventEmitter1 x 2,816,703 ops/sec ±0.32% (93 runs sampled)
EventEmitter2 x 5,946,394 ops/sec ±8.87% (93 runs sampled)
EventEmitter3@0.1.6 x 12,038,564 ops/sec ±0.50% (94 runs sampled)
EventEmitter3(master) x 12,025,654 ops/sec ±0.79% (95 runs sampled)
Drip x 6,160,659 ops/sec ±1.75% (89 runs sampled)
fastemitter x 4,694,990 ops/sec ±0.85% (93 runs sampled)
event-emitter x 2,413,553 ops/sec ±0.90% (92 runs sampled)
contra/emitter x 277,935 ops/sec ±2.43% (93 runs sampled)
@pre1ude
pre1ude / perf3.md
Created June 23, 2017 03:33
less else

Starting benchmark context.js

EventEmitter1 x 2,648,453 ops/sec ±4.02% (86 runs sampled)
EventEmitter2 x 5,922,249 ops/sec ±1.12% (92 runs sampled)
EventEmitter3@0.1.6 x 11,909,281 ops/sec ±0.55% (93 runs sampled)
EventEmitter3(master) x 12,097,280 ops/sec ±0.49% (93 runs sampled)
Drip x 6,257,389 ops/sec ±1.00% (91 runs sampled)
fastemitter x 4,642,172 ops/sec ±0.63% (92 runs sampled)
event-emitter x 2,403,077 ops/sec ±0.57% (94 runs sampled)
contra/emitter x 277,707 ops/sec ±0.94% (93 runs sampled)
@pre1ude
pre1ude / perf2.md
Created June 22, 2017 11:13
clearEvent(emitter, evt)

Starting benchmark context.js

EventEmitter1 x 2,727,388 ops/sec ±0.40% (94 runs sampled)
EventEmitter2 x 5,827,554 ops/sec ±7.26% (92 runs sampled)
EventEmitter3@0.1.6 x 12,169,908 ops/sec ±0.83% (94 runs sampled)
EventEmitter3(master) x 12,008,076 ops/sec ±0.66% (93 runs sampled)
Drip x 6,036,697 ops/sec ±1.75% (91 runs sampled)
fastemitter x 4,745,159 ops/sec ±1.33% (93 runs sampled)
event-emitter x 2,325,200 ops/sec ±2.02% (92 runs sampled)
contra/emitter x 274,006 ops/sec ±1.13% (94 runs sampled)
@pre1ude
pre1ude / perf1.md
Last active June 22, 2017 10:50
situation: clearEvent.call(this)

Starting benchmark context.js

EventEmitter1 x 2,842,470 ops/sec ±0.28% (92 runs sampled)
EventEmitter2 x 6,000,977 ops/sec ±2.10% (91 runs sampled)
EventEmitter3@0.1.6 x 12,020,458 ops/sec ±1.00% (93 runs sampled)
EventEmitter3(master) x 11,804,074 ops/sec ±2.23% (91 runs sampled)
Drip x 6,121,632 ops/sec ±2.41% (90 runs sampled)
fastemitter x 4,738,150 ops/sec ±1.98% (93 runs sampled)
event-emitter x 2,395,223 ops/sec ±1.91% (93 runs sampled)
contra/emitter x 280,920 ops/sec ±1.80% (92 runs sampled)