Skip to content

Instantly share code, notes, and snippets.

View b2whats's full-sized avatar
🎯
Focusing

Akimov Vladimir b2whats

🎯
Focusing
View GitHub Profile
@b2whats
b2whats / tmux-cheatsheet.markdown
Last active September 2, 2015 01:19 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@b2whats
b2whats / parser.js
Last active September 2, 2015 01:32 — forked from matthieubulte/parser.js
parser combinator - hutton
let slice = Array.prototype.slice;
let str = s => slice.call(s)
let unstr = cs => cs.reduce((c, cs) => c + cs, "")
let concat = xss => xss.reduce((xs, ys) => xs.concat(ys), [])
let id = x => x
let negate = x => -x
let add = (x,y) => x + y
let sub = (x,y) => x - y
// type Parser a = () -> [Char] -> a
@b2whats
b2whats / producer-consumer.js
Created April 13, 2016 23:06 — forked from narqo/producer-consumer.js
"Producer-Consumer" example implementation using generators. See http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators for more about coroutine
/* jshint esnext:true */
/**
* "Producer-Consumer" implementation using generators.
* @see http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators
*/
var SIZE = 3,
queue = newQueue();
@b2whats
b2whats / functional-utils.js
Created April 13, 2016 23:06 — forked from bendc/functional-utils.js
A set of pure and immutable ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
/* jshint esnext:true */
// native generators
function* random() {
var i = 0;
while(i++ < 1e5) {
yield Math.random();
}
}
@b2whats
b2whats / recursion.js
Created April 13, 2016 23:13 — forked from bendc/recursion.js
Functional loop
const loop = (() => {
const recur = (callback, count, i=0) => {
if (i == count-1) return callback(i);
callback(i);
return recur(callback, count, i+1);
};
return (callback, count) => {
if (count > 0) return recur(callback, count);
};
})();
@b2whats
b2whats / expression-only.md
Created April 13, 2016 23:16 — forked from DmitrySoshnikov/expression-only.md
ES: Expression only

"Everything is an expression"... since ES1?

Many languages support "expression-only" semantics, allowing to use any construct in an expression position.

NOTE: the difference between expressions and statements is that the former produce a value, while the later don't.

For example, Ruby's if-expression:

x = 10
@b2whats
b2whats / React-universal-structure.md
Created April 29, 2016 00:24 — forked from zeakd/React-universal-structure.md
react universal structure with ignore pattern - render for client only components

react universal application - Ignore pattern

In React universal application, there is problem when render client-side only components like Devtools, fetching components and webpack style require (require css) Two solution for this.

dynamic module import isomorphic500

check js is running on browser

server side build

use webpack also on serverside, or if you are using requirejs, you can map client modules to null

But serverside build look like overkill to me, I choose dynamic module import. However in es6, import doesn't support dynamic import. So you should use commonjs require for it.

@b2whats
b2whats / How_Require_Extensions_Work.md
Created April 29, 2016 00:25 — forked from jamestalmage/How_Require_Extensions_Work.md
Breakdown of How Require Extensions Work

Why

Doing require extensions correctly is essential, because:

  1. Users should be able to install multiple extensions in succession, and have them work together.
  2. Coverage tools like nyc need it to reliably supply coverage information that takes into account sourcemaps from upstream transforms.
  3. Because non-standard, un-predictable behavior causes hard to solve bugs, and major headaches for project maintainers.

What is a require extension anyways?