Skip to content

Instantly share code, notes, and snippets.

class R<P,S> {
state:S;
props:P;
static instance;
refs:{ [ref: string]: React.ReactComponent<any, any>; };
getDOMNode():Element {
return null
}
@cevek
cevek / tsc.js
Created January 30, 2015 16:05
atom name
var name = '';
if (node.expression.text === 'Atom'){
var exps = [];
var n = node;
var ns = [];
var isReturn = false;
var isThis = false;
var ex = false;
while (n = n.parent){
if (n.name && n.kind !== 128){
@cevek
cevek / tsc.js
Created February 8, 2015 15:50
observe every property
function emitMemberFunctions(node) {
ts.forEach(node.members, function (member) {
//console.log(member.kind, member);
if (member.kind === 126){
writeLine();
emitStart(member);
write("Object.defineProperty(");
emitStart(member.name);
emitNode(node.name);
var memberName = member.name.text;
@cevek
cevek / tsc.js
Created February 8, 2015 16:03
atomExpression
function atomExpression(node){
var name = '';
var atomNames = 'Atom|AtomFormula|List|ListFormula';
if (atomNames.indexOf(node.expression.text) > -1){
var exps = [];
var n = node;
var ns = [];
var isReturn = false;
var isThis = false;
@cevek
cevek / tsc.js
Created February 8, 2015 18:21
fixed observable
function emitMemberFunctions(node) {
ts.forEach(node.members, function (member) {
if (member.kind === 126){
writeLine();
emitStart(member);
var memberName = member.name.text;
var owner = node.name.text;
var ownerName = node.name.text;
if (!(member.flags & 128 /* Static */)) {
owner = 'this';
@cevek
cevek / tsc.js
Created February 9, 2015 10:02
update emitMemberFunctions
function emitMemberFunctions(node) {
ts.forEach(node.members, function (member) {
if (member.kind === 126){
var par = member.parent;
while(par.parent && (par = par.parent));
var txt = par.text.substr(member.pos, member.end).trim();
var observable = '//@observable';
if (txt.substr(0, observable.length) !== observable)
return;
writeLine();
@cevek
cevek / tsc.js
Created February 9, 2015 10:02
emitConstructorOfClass
function emitConstructorOfClass() {
var saveTempCount = tempCount;
var saveTempVariables = tempVariables;
var saveTempParameters = tempParameters;
tempCount = 0;
tempVariables = undefined;
tempParameters = undefined;
ts.forEach(node.members, function (member) {
if (member.kind === 129 /* Constructor */ && !member.body) {
@cevek
cevek / random.md
Last active December 30, 2015 11:50

Collisions count of random uid generator

insert count x 1.000.000 4 bytes uint 5 bytes uint 6 bytes uint
0.1 3 0 0
1 130 1 0
2 500 5 0
3 1000 9 0
4 2000 18 0
5 3000 30 0
6 4200 41 0
@cevek
cevek / array_diff.js
Created April 14, 2016 10:46
fast array diff
var tests = [
[[], [1, 2, 3], [1, 2, 3], [], 0, 0],
[[1, 2, 3], [], [], [1, 2, 3], 0, 0],
[[1, 2, 3], [1, 2, 3], [], [], 3, 0],
[[1, 2, 3, 4], [1, 2, 3], [], [4], 3, 0],
[[1, 2, 3], [1, 2, 3, 4], [4], [], 3, 0],
[[1, 2, 3], [1, 3], [], [2], 3, 1],
[[1, 3], [1, 2, 3], [2], [], 3, 0],
[[1, 2, 3], [3, 2, 1], [], [], 6, 0],
[[1, 2, 3], [3, 2], [], [1], 5, 2],

create package.js

npm init -y

create tsconfig.json

tsc --init

install deps