Skip to content

Instantly share code, notes, and snippets.

View capaj's full-sized avatar
🏠
Always working-be it from home or elsewhere

Jiri Spac capaj

🏠
Always working-be it from home or elsewhere
View GitHub Profile
@capaj
capaj / component.js
Last active June 22, 2016 12:40
react stateful function component
import React from 'react'
import {observer} from 'mobx-react'
import {observable} from 'mobx'
const state = observable({
value: 0
})
const Comp = (props) => {
return <div onClick={() => state.value++}>click to increase counter value: {state.value}</div>
make[1]: Entering directory '/home/capaj/git_projects/koa/benchmarks'
1 middleware
18730.10
5 middleware
17620.69
10 middleware
16914.27
make[1]: Entering directory '/home/capaj/git_projects/koa/benchmarks'
1 middleware
12657.20
5 middleware
11990.98
10 middleware
12123.40
mobX create observable, autorun and dispose x 357,481 ops/sec Β±5.15% (72 runs sampled)
proxevable create observable, autorun and dispose x 79,279 ops/sec Β±4.75% (71 runs sampled)
Fastest is mobX create observable, autorun and dispose
Community Packages (43) /home/capaj/.atom/packages
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]

This rule should only be enforced for node.js > 0.12 There is no point in declaring a module as var. Module should always be a const if assigned on the same line as the require statement is. If you want to require module "A" or module "B" into a single variable, it should be done like this:

var aOrB
if (cond) {
  aOrB = require('A')  
} else {
  aOrB = require('B')
}
@capaj
capaj / onDidSave-atom.js
Created October 27, 2015 19:10
onDidSave atom editor
atom.workspace.observeTextEditors(function(editor){
editor.onDidSave(function(){console.log('saved')})
})
@capaj
capaj / stack
Created October 24, 2015 02:58
angular 2 when bootstrapping again
browser_adapter.js:64 TypeError: Cannot read property 'insertBefore' of null
STACKTRACE:
TypeError: Cannot read property 'insertBefore' of null
at BrowserDomAdapter.insertAfter (http://localhost:9089/jspm_packages/npm/[email protected]/src/dom/browser_adapter.js:172:18)
at DomRenderer._moveViewNodesAfterSibling (http://localhost:9089/jspm_packages/npm/[email protected]/src/render/dom/dom_renderer.js:277:25)
at DomRenderer.attachViewInContainer (http://localhost:9089/jspm_packages/npm/[email protected]/src/render/dom/dom_renderer.js:125:12)
at AppViewManager.createViewInContainer (http://localhost:9089/jspm_packages/npm/[email protected]/src/core/compiler/view_manager.js:116:20)
at ViewContainerRef.create (http://localhost:9089/jspm_packages/npm/[email protected]/src/core/compiler/view_container_ref.js:44:29)
at NgIf.Object.defineProperty.set [as ngIf] (http://localhost:9089/jspm_packages/npm/[email protected]/src/directives/ng_if.js:37:28)
at Bin
@capaj
capaj / cssToJs.js
Created September 9, 2015 14:00
utility for converting a copied style from chrome dev tool to an object syntax which react.js expects
function camelCase(string) {
return string.replace(/-([a-z])/ig, function(all, letter) {
return letter.toUpperCase();
});
}
function cssToObj(css) {
var res = {};
// split css by line
var css_rows = s.split('\n');
for (var i=0; i<10; i++) {
var prepareVariableScope = function(num){
return function() {
console.log(num);
};
};
setTimeout(prepareVariableScope(i), 1);
}
for (var i=0; i<10; i++) {