Skip to content

Instantly share code, notes, and snippets.

View gaperton's full-sized avatar

Vlad Balin gaperton

View GitHub Profile
var z = +new Date();
for( var j = 0; j < 100; j++ ){
var elements = [];
for( var i = 0; i < 1000; i++ )
elements.push(
<div key={i} className="row">
<div className="col">a</div>
<div className="col">b</div>
@gaperton
gaperton / es6models.js
Created July 29, 2015 09:35
ES6 Models
@attributes({
typeless : void 0,
num : 5,
s : "dsdsds",
count : Number.has.toJSON( false )
})
class MyModel {
doSomething(){
//...
}
@gaperton
gaperton / test.js
Last active December 10, 2015 16:56
Iteration through object hash
var keys = [],
attrs = {},
c = [];
for( var i = 0; i < 20; i++ ){
keys.push( 'a' + i );
attrs[ 'a' + i ] = i;
c.push( 'a.a' + i + '=== void 0 || f( a.a' + i + ');')
}
@gaperton
gaperton / gist:7a8a8951cc166af57c98
Created January 18, 2016 22:47
More elegant way
function match( obj ){
return function( x ){
for( var name in obj ){
if( x.get( name ) !== obj[ name ] ){
return false;
}
}
return true;
}
function State1( a, b ){
this.a = a;
this.b = b;
}
State1.prototype.msgType1 = function( c, d ){
return new State2( this.a + 1 );
}
State1.prototype.msgType2 = function( d ){
const devToolsHook = window && window.__REACT_DEV_TOOLS_HOOK__;
if( devToolsHook ){
const { addInnerStateInspector } = devToolsHook;
if( addInnerStateInspector ){
const showAsArray = x => x.toArray(),
showAsObject = x => x.toObject();
addInnerStateInspector( List, showAsArray );
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Population of the array</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
var digitsStr =
// 0 8 16 24 32 40 48 56 63
// v v v v v v v v v
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-";
var digits = digitsStr.split(''),
codes = digits.map( x => x.charCodeAt( 0 ) );
function base64id( int32 ){
const a = digits[int32 & 0x3f];
int32 >>>= 6;
@gaperton
gaperton / valuelink-1-1.jsx
Last active November 28, 2017 04:46
Managing state and forms with React. Part 1