Skip to content

Instantly share code, notes, and snippets.

View zerobias's full-sized avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile

Features

high

  • Remove jsbn
  • Remove invoke third argument
  • Simplify tl usage

medium

@zerobias
zerobias / literal-helper.js
Created March 16, 2017 16:31
Tagged template literal reduce example
function upperExpr (template, ...expressions) {
return template.reduce((accumulator, part, i) => {
return accumulator + expressions[i - 1].toUpperCase() + part
})
}
var name = 'nico'
var outfit = 'leather jacket'
var text = upperExpr`hello ${name}, you look lovely today in that ${outfit}`
console.log(text)
@zerobias
zerobias / tap-log.js
Created March 17, 2017 20:31
Debug log inside of pipe
import { tap } from 'ramda'
const tapLog = (...tags) => tap(
(...values) => console.log(...tags,...values))
//USAGE
import { pipe } from 'ramda'
const debuggedSteps = pipe(
@zerobias
zerobias / .eslintrc
Last active May 12, 2017 22:06
Modern eslint styleguide
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"extends": [
"eslint:recommended",
@zerobias
zerobias / print-stack.js
Created May 18, 2017 15:02
Print prototype stack
function pps (obj) {
let count = 1
while (obj) {
const okeys = Object.keys(obj)
const str = okeys.length > 0 ?
`[${okeys.join(', ')}]` : `[${obj.constructor.name}]`
console.log(`[${count++}]: ${str}`)
obj = Object.getPrototypeOf(obj)
}
}
@zerobias
zerobias / merge-template-args.js
Last active June 5, 2017 14:10
Merge teplate function arguments into one list
function mergeTemplateArgs(strings, ...values) {
const stringsLn = strings.length
const hasValues = stringsLn > 1
if (!hasValues) return strings
const pairsCount = stringsLn - 1
const fullLength = pairsCount * 2 + 1
const result = Array(fullLength)
result[fullLength -1] = strings[stringsLn-1]
for (let i = 0, j = 0; i < pairsCount; i++, j+=2) {
result[j] = strings[i]
@zerobias
zerobias / tco.js
Created June 29, 2017 09:28
Tail call optinisation detection and call stack depth counter
let TCO_ENABLED
let stackDepth = 0
try {
(function foo(x){
stackDepth+=1
if (x < 5E5) return foo( x + 1 )
})( 1 )
TCO_ENABLED = true
}
@zerobias
zerobias / asm.js
Created June 29, 2017 09:38
asm.js full module with heap allocation
function fooASM(stdlib,foreign,heap) {
"use asm";
var arr = new stdlib.Int32Array( heap );
function foo(x,y) {
x = x | 0;
y = y | 0;
var i = 0;
@zerobias
zerobias / rename-keys.js
Last active June 29, 2017 12:42
Rename object keys by template
import { propOr, pipe, adjust, __, map, useWith, into, toPairs } from 'ramda'
const reducePairs = useWith(into({}))
const getNameField =
keyMap => key => propOr(key, key, keyMap)
const reducer = pipe(
getNameField,
adjust(__, 0),
map
@zerobias
zerobias / flow-curry.js
Created August 14, 2017 20:41
Flowtype curry function
//@flow
function curry2<A, B, R>(fn : (A, B) => R) : A => B => R {
return function (a : A) : B => R {
return function (b : B) : R {
return fn(a, b);
};
};
};
function curry3<A, B, C, R>(fn : (A, B, C) => R) : A => B => C => R {