Skip to content

Instantly share code, notes, and snippets.

View obenjiro's full-sized avatar
🎯
Focusing

Alexey Okhrimenko obenjiro

🎯
Focusing
View GitHub Profile
var React = require('react/addons');
var ReactIgnore = {
displayName: 'ReactIgnore',
shouldComponentUpdate (){
return false;
},
render (){
return React.Children.only(this.props.children);
}
@obenjiro
obenjiro / treetoarray.js
Created January 14, 2015 16:53
Tree to array
// parent links only
function treeToArray(tree, parent){
if (!tree) return;
tree.parent = parent;
if (!tree.children) return [tree];
var children = tree.children;
delete tree.children;
if (!Array.isArray(children)) return [tree].concat([children]);
return [].concat.apply([], [tree].concat(children.map(function(c){ return treeToArray(c, tree) })))
}
@obenjiro
obenjiro / computed-model-field.extjs.js
Last active August 29, 2015 14:17
Bringing computable model fields to ExtJS
// All creadits gouse to
// http://flexblog.faratasystems.com/2012/02/07/computed-fields-in-extjs-models-via-convert-functions
Ext.define('Sample.model.User', {
extend: 'Ext.data.Model',
fields: [
{ name:'id', type:'string' },
{ name:'firstName', type:'string' },
{ name:'lastName', type:'string' },
{
name:'fullName',
@obenjiro
obenjiro / visitor.js
Last active August 29, 2015 14:18
Visitor Pattern in JavaScript
var calc = {
add: function (node) {
return visit(node.l) + visit(node.r);
},
sub: function (node) {
return visit(node.l) - visit(node.r);
},
val: function (node) {
return node.val;
}
@obenjiro
obenjiro / autocurry.js
Last active June 6, 2016 14:43
One lame autoCurry implementation
function auto_curry(f) {
return function() {
var args = [];
args.push.apply(args, arguments);
var next = function() {
args.push.apply(args, arguments);
if (f.length === args.length) {
return f.apply(this, args);
@obenjiro
obenjiro / composition.js
Last active August 29, 2015 14:22
smallest multifunctional composition
var compose = function(array) {
return array.reduce(function(a,b) { return function(c) { return b(a(c)) } })
}
var get = function(prop) {
return function(obj) {
return obj && obj[prop]
}
}
@obenjiro
obenjiro / debuggin.md
Last active August 29, 2015 14:24
All links for Mobile Frontend Meetup at Avito - Mobile FrontEnd Debugging
@obenjiro
obenjiro / parasitic_constructor.js
Created August 18, 2015 19:37
Croc's parasitic constructor
function Person(self) {
self = self || {};
var name = 'test';
self.setName = function(n){name = n;};
self.getName = function(){return name;};
return self;
}
@obenjiro
obenjiro / jsdoit.css
Last active June 25, 2018 00:22
Canvas Conical Gradient
body {
margin: 0;
padding: 0;
background-color: #fff;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAANUlEQVQ4jWM8c+bMfwY8wNjYmBGfPBM+SWLAqAGDwQDG///xJgOGs2fP4lUw8F4YNYAKBgAA2NYKfxDn4ZUAAAAASUVORK5CYII=);
overflow: hidden;
}
@obenjiro
obenjiro / d3-template.js
Last active September 28, 2015 13:29
d3 template gist
/**
* Шаблонная функция для работы с D3
*/
function act(scenario) {
// устанавливаем сцену
var stage = d3.select('body');
// выбераем актеров
var actors = stage.selectAll('div');
// раздаем роли актерам
var awroles = actors.data(scenario, function(d){ return d });