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 / w.js
Last active February 21, 2016 04:15
/*eslint-disable no-console, radix*/
import webpack from 'webpack';
import path from 'path';
import writeStats from './writeStats';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CleanPlugin from 'clean-webpack-plugin';
import autoprefixer from 'autoprefixer-core';
import webpackStripLoader from 'strip-loader';
import { host, webpackPort, buildDir } from '../config';
@b2whats
b2whats / Many-handler-xxx.js
Created December 1, 2015 08:53
Много VS Один
import * as NotificationAction from 'actions/NotificationActions'
импортов может и не быть, если мы в обработчике нативно обрабатываем запросы
export default function 404({ status, statusText }, dispatch, getState) {
if (status === 404) {
dispatch(NotificationAction.send({message: statusText}))
}
}
Таких файлов будет ровно столько сколько будет обработчиков
@b2whats
b2whats / js
Last active July 31, 2016 16:10
a
typeof NaN == 'number';
42 == [[[[[[[42]]]]]]];
'foo' > 'bar';
NaN != NaN;
null >= 0 // true, т.к. null преобразуется к 0
null > 0 // false т.к. null преобразуется к 0
null == 0 // false
5 - '3' === 2
@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);
};
})();