Skip to content

Instantly share code, notes, and snippets.

View a-x-'s full-sized avatar
🛩️

Alexander a-x-

🛩️
View GitHub Profile
@a-x-
a-x- / onEvent.sample.js
Created March 5, 2016 14:40
синтаксический сахар для установки модификаторов по событиям [i-bem.js] — https://ru.bem.info/forum/907/
/**
* Как сейчас. Это пример, где упрощённый синтаксис всё сильно упростит.
* Но есть и много других примеров, где, кажется, декларация модификаторов на события будет полезна
*/
BEM.DOM.decl('b-page', {
bindEvents: function() {
this.__base.apply(this, arguments);
BEM.blocks['pane2-api']
@a-x-
a-x- / iterations.es6
Created March 7, 2016 13:06
Differencies: for of, for in, for in hasOwnProperty. arrays and objects.
(()=>{'use strict';
let iterable = [3, 5, 7];
iterable.foo = "hello";
console.log('# iterable', iterable)
console.log('## access prop in array')
console.log(iterable.foo) // hello
console.log('## for in arr')
@a-x-
a-x- / sample.xjt.js
Last active March 8, 2016 00:10
XJT/BEMS - Xtendable js/json Transformation (BEMTREE killer) based on `Block Elem Mod State` concept
// TOC
// Intro
// # New BEM based blocks concept — BEMS
// # New 3-step templating concept
// Example
/**
# New BEM based blocks concept — BEMS
## Нейминг: Не мода, а поле
@a-x-
a-x- / sample-server-stack.xjt.js
Last active March 8, 2016 00:06
XJT/BEMS concept sample
'use strict';
import {Priv as Bempriv, Html as Bemhtml, XJT as xjt} from 'bem-server'
// menu.priv.js - es6priv
Bempriv.decl('menu', class menu extends Bempriv {
constructor() {
this.prop('items', this.getItems());
}
getItems() {
// Выдуманная, но близкая к реальности логика маппинга данных
block('viewer-controls')(
def()(function() {
return applyNext({
params: this.ctx.params
});
}),
content()(function() {
return [
@a-x-
a-x- / fuzzysearch.js
Created April 3, 2016 09:26
stupid fuzzysearch O(m). Have not distance limit
function fuzzysearch (sub, str) {
var l1 = sub.length, l2 = str.length;
var i = 0, j = 0;
if (l1 > l2) return false;
for (; i < l1; ++i, ++j) {
if (sub[i] == str[j]) continue;
do {
++j;
if (j >= l2) return false;
@a-x-
a-x- / table-from-ajax-json.es6
Created April 3, 2016 09:51
Built simple table from json via ajax
(() => {'use strict';
let table, tr, td, div, _el, cl;
document.body.innerHTML = 'loading...';
$.get('http://yitv.herokuapp.com')
.then((data) => {
let rows = data.body.reduce((prev, item)=>{
let title = div(item.title, 'title');
let vals = div(item.add_values.join(', '));
let row = td(item.value, 'value') + td(title + vals, null, { title: item.detail });
@a-x-
a-x- / sum-tree.es6
Created April 3, 2016 10:05
Sum tree with data stack (no call stack). Breadth first traversal
function sumTree (tree) {
var sum = tree.value;
var root = tree;
var stack = [root.next];
while(stack.length) {
sum = stack.pop().reduce((sum, root) => {
stack.push(root.next);
return sum + root.value;
}, sum);
@a-x-
a-x- / summary-through-tuples.es6
Last active April 3, 2016 11:06
summarize active and total browsers by its names
var summary = hubs => _(hubs)
.groupBy('browserName')
.mapValues((data, bro) =>
_(data).mapTuple(['active', 'total']).sumTuple().value()
)
.value();
var hubs = [{
host: 'hub01',
browserName: 'firefox',
var cloneObj = obj => {
var newObj = {};
Object.keys(obj).forEach((key) => {
newObj[key] = obj[key];
});
return newObj;
};
var appendTrace = (trace, key, val) => {
var newTrace = cloneObj(trace);