Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivan Kleshnin ivan-kleshnin

View GitHub Profile
View flattenObj.md

My code from: https://gist.github.com/penguinboy/762197

let isPlainObj = (o) => Object.prototype.toString.call(o) == "[object Object]"
// this ^ is enough. If you check prototypes – you're doing it wrong. If somethings pretends to be plain – we have to accept that
// e.g. this: https://github.com/jonschlinkert/is-plain-object is an entirely WRONG approach 

let flattenObj = (obj, keys=[]) => {
  return Object.keys(obj).reduce((acc, key) => {
    return Object.assign(acc, isPlainObj(obj[key])
View idris-first-impression.md

Idris: first impression

Language

Likes

Dependent types

The idea and approach is brilliant. I hope it's the next big thing in programming.

View shims.md

Map

JS Map can be usable once you augment it.

Map.prototype.map = function (fn) {
  let m2 = new Map()
  for (let [k, v] of this) {
    m2.set(k, fn(v, k))
  }
View pascal's-triangle.js
/*
Pascal's Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of
the two numbers above it. Write a procedure that computes elements of Pascal's triangle by means of
View cc.txt
Parallel – 2+ processes (or cores)
Concurrent – whatever
Parallel is for increasing throughput
Concurrent is for decreasing latency
Parallel is for non-interactive (performance) (few inputs, deterministic or non-deterministic)
Concurrent is for interactive (experience) (many inputs, non-deterministic)
Parallel – how fast it gets result
View emitter.js
// Publish-Subscribe
// Observable – Observer
// Publisher - Listener
// Emitter - Handler
/*
Updates:
0) off
1) once
2) raise event on add listener
@ivan-kleshnin
ivan-kleshnin / clickNth.js
Created Aug 5, 2016
NightmareJS `clickNth` custom action
View clickNth.js
Nightmare.action("clickNth", function (selector, n, done) {
debug(".clickNth() on " + selector + ":" + n)
this.evaluate_now(function (selector, n) {
document.activeElement.blur()
var element = document.querySelectorAll(selector)[n]
if (!element) {
throw new Error('Unable to find element by selector: ' + selector)
}
var event = document.createEvent('MouseEvent')
event.initEvent('click', true, true)
View rx.derivables.js
let R = require("ramda")
let {Observable, Subject} = require("rx")
let scanFn = function (state, updateFn) {
if (typeof updateFn != "function" || updateFn.length != 1) {
throw Error("updateFn must be a function with arity 1, got " + updateFn)
} else {
return updateFn(state)
}
}
View faq.md

Free port after manual kill

$ lsof -i :$PORT -- set desired port, e.g. 3000
$ kill $PID -- set discovered PID, e.g. 2227
View npm.release-commands.md

release-patch

git checkout master && npm version patch && git push origin master --tags

release-minor

git checkout master && npm version minor && git push origin master --tags