Skip to content

Instantly share code, notes, and snippets.

@arvitaly
arvitaly / gist:0814c1ac9dc28d4ff717524fd48ef65e
Created September 7, 2016 19:20
Не происходит асинхронная подписка на ячейку cellx?
var cellx = require('cellx');
var a = cellx(55);
var x = cellx((push) => {
//a() //Если раскомментировать эту строку, то x начинает пересчитываться!
setTimeout(() => {
push("test" + a());
}, 100)
})
x('addChangeListener', () => {
console.log("addChangeListener, x:: ", x());
@arvitaly
arvitaly / js
Created September 7, 2016 19:20
Не происходит асинхронная подписка на ячейку cellx?
var cellx = require('cellx');
var a = cellx(55);
var x = cellx((push) => {
//a() //Если раскомментировать эту строку, то x начинает пересчитываться!
setTimeout(() => {
push("test" + a());
}, 100)
})
x('addChangeListener', () => {
console.log("addChangeListener, x:: ", x());
@arvitaly
arvitaly / gist:8ae581f94650d5a9369f91421641cdfa
Created September 9, 2016 18:57
Расширение прототипа cellx
var cellx = require('cellx');
var x = new cellx.Cell
cellx.Cell.prototype.if = function (trueCondition) {
this.subscribe(function () {
this.get() && trueCondition()
});
this.get() && trueCondition()
}
@arvitaly
arvitaly / composition.js
Created September 20, 2016 09:57
Example of change state in js-modules
var state = require('./state');
var f1 = require('./f1');
var f2 = require('./f2');
try{
f1();//Change state, really bad
var newState = f2();// pure function
//await f3
//yield* f4
}catch(e){
var Fib = {
[Symbol.iterator]() {
var n1 = 1, n2 = 1;
return {
// make the iterator an iterable
[Symbol.iterator]() { return this; },
next() {
var current = n2;
n2 = n1;
n1 = n1 + current;
@arvitaly
arvitaly / index.ts
Created November 27, 2016 04:28
React own element
import jsdom = require("jsdom");
import React = require("react");
import ReactElementSymbol = require("react/lib/ReactElementSymbol");
import ReactDOM = require("react-dom");
const window = jsdom.jsdom(`<div id="root"></div>`).defaultView;
global['window'] = window;
global['document'] = window.document;
class A extends React.Component<any, any>{
render() {
@arvitaly
arvitaly / log.js
Created December 14, 2016 07:00
HTTP-log debug
(function(){var LOG = "Hello, world";var req = require("http").request({hostname: '127.0.0.1', port: 9999, path: '/', method: 'POST',});req.write(LOG);req.end();})()
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
void setup()
@arvitaly
arvitaly / class_decorator.ts
Created May 19, 2017 19:26 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@arvitaly
arvitaly / tcp
Last active December 29, 2020 09:39
const net = require("net");
const server = net
.createServer(function(socket) {
socket.on("data", function(data) {
if (data.toString() === "close") {
socket.end();
} else {
socket.write(data.toString());
}
});