This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function DOMAttachWatcher(){ | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if([...mutation.addedNodes].includes(el) && onAttachCb){ | |
onAttachCb() | |
} | |
if([...mutation.removedNodes].includes(el) && onDetachCb){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CounterView(data, handlers){ | |
return div(null, | |
button({onClick: handlers.inc}, | |
'Inc' | |
) | |
button({onClick: handlers.decAsync}, | |
'Dec async' | |
), | |
span(null, | |
'Count: ', data.counter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.17; | |
/** | |
* Allows one to send EIP-20 tokens to multiple addresses cheaply. | |
* Copyright © 2017 by ABDK Consulting https://abdk.consulting/ | |
* Author: Mikhail Vladimirov <mikhail.vladimirov[at]gmail.com> | |
*/ | |
contract BatchTokenSender { | |
event BatchSent(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"parserOptions": { | |
"ecmaVersion": 2017 | |
}, | |
"env": { | |
"browser": true, | |
"es6": true | |
}, | |
"rules": { | |
"no-unused-vars": "off", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
- generate requests on timer | |
- if timer signals before request completed, then wait until request complete | |
- if timer signals multiple times before request completed then issue signle | |
request after getting response | |
Example timeline | |
timer: 0 1 2 2 | |
request made: r1 r2 r3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Весь стейт хранится в глобальной переменной. Можно использовать | |
// какие-нибудь классы, но мне кажется что хороший js-стиль - | |
// просто массивы и хэши | |
function getInitialState(){ return {counter: 0}; } | |
var AppState = getInitialState(); | |
// Бизнес-логика. Состоит из обычных функций. | |
// В реальной программе функции засунуты в модули. | |
function dec(state){ | |
state.counter--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatten(arr){ | |
var result = []; | |
function doFlatten(arr){ | |
if(Array.isArray(arr)){ | |
arr.forEach(doFlatten); | |
}else{ | |
result.push(arr); | |
} | |
} | |
doFlatten(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fromCallback = (fn) -> | |
stream = [] | |
cb = -> | |
for cb in stream | |
cb.apply @, arguments | |
fn cb | |
stream | |
map = (fn) -> (stream) -> | |
result = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
-- На международном фестивале собрались n участников. Если взять любую подгруппу | |
-- из m участников, то в этой подгруппе найдутся двое, которые разговаривают на | |
-- одном языке. | |
-- | |
-- Проверить следующее утверждение: в любой подгруппе размера k участники могут | |
-- объясниться друг с другом. | |
import Data.List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Tree<T> = {left: Tree<T>, right: Tree<T>, value: T} | |
function reduceTree<T,A>(tree: Tree<T>, initialAcc: A, reducer: (A,T) => A): A{ | |
if(tree == null){ | |
return initialAcc; | |
} | |
var withNodeValue = reducer(initialAcc, tree.value); | |
var withLeftBranch = reduceTree(tree.left, withNodeValue, reducer); | |
var withRightBranch = reduceTree(tree.right, withLeftBranch, reducer); | |
return withRightBranch; |