Skip to content

Instantly share code, notes, and snippets.

View stremann's full-sized avatar

Roman Stremedlovskyi stremann

  • EPAM Systems Inc.
  • London, United Kingdom
View GitHub Profile
// Main function
var findSymmetricNode = function(root1, root2, node) {
const path = getPath(root1, node);
return getNode(root2, path);
}
// Test cases
var root1 = document.querySelector('#root1');
var root2 = document.querySelector('#root2');
@stremann
stremann / .gitlab-ci.yml
Created March 22, 2018 11:24
GitLab config example
stages:
- build
- deploy
- migrate
cache:
paths:
- backend/node_modules/
- mobile/node_modules/
@stremann
stremann / routes.js
Created October 16, 2017 19:57
Easy Blockchain implementation for JavaScript apps https://github.com/stremann/chainpro
import express from 'express';
import chain from '../chain';
import { create } from '../block';
import sockets from '../p2p/sockets';
import { connectToPeers } from '../p2p/index';
import { broadcast } from '../p2p/handlers';
import { responseLatestMsg } from '../p2p/actions';
const router = express.Router();
@stremann
stremann / block.js
Created October 16, 2017 19:37
Easy Blockchain implementation for JavaScript apps https://github.com/stremann/chainpro
import CryptoJS from 'crypto-js';
import chain from './chain';
export const calcHash = ({index, prevHash, timestamp, data}) => {
return CryptoJS.SHA256(index + prevHash + timestamp + data).toString();
}
export const create = (data) => {
const prev = chain.last();
@stremann
stremann / chain.js
Created October 16, 2017 18:17
Easy Blockchain implementation for JavaScript apps https://github.com/stremann/chainpro
import { calcHash, isNewBlockValid } from './block';
const Chain = (function () {
let instance;
const origin = {
index: 0,
timestamp: 0,
data: 'Hello Blockchain!',
prevHash: 0,
hash: calcHash({ index: 0, prevHash: 0, timestamp: 0, data: 'Hello Blockchain!' })
@stremann
stremann / async.js
Created July 13, 2017 15:09
From callbacks to promises to async/await
import request from 'request' // for callback example
import axios from 'axios' // for promise examples
// Service
const service = {
getPeople: () => axios({url: 'http://localhost:3000/people'}),
getPlaces: () => axios({url: 'http://localhost:3000/places'})
};
// Example #1 - Callback Hell-o
@stremann
stremann / dompro.js
Created December 21, 2016 13:23
Easy Virtual DOM implementation for JavaScript apps https://github.com/stremann/dompro
import { createElement } from './createElement.js';
import { hasChanged } from './hasChanged.js';
import { updateProps } from './propHandler.js';
export function updateDOM($parent, newNode, oldNode, index = 0) {
if (!oldNode) {
$parent.appendChild(createElement(newNode));
} else if (!newNode) {
$parent.removeChild($parent.childNodes[index]);
} else if (hasChanged(newNode, oldNode)) {
@stremann
stremann / 1000-loop.js
Created December 13, 2016 09:50
Duff's Device by Jeff Greenberg (vol.2)
var items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var iterations = items.length % 8;
var i = items.length - 1;
while(iterations) {
process(i, items[i--], ' while: 1');
iterations--;
}
iterations = Math.floor(items.length / 8);
@stremann
stremann / perfloop.js
Created December 13, 2016 09:37
Loop comparison
var items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// Increase loop
for (var i = 0; len = items.length, i < len; i++) {
processUp(items[i], i);
}
console.log('----------------------------------');
// Decrease loop
@stremann
stremann / flypro.js
Created September 6, 2016 20:24
Easy Flux implementation for JavaScript apps https://github.com/stremann/flypro
export default function createStore(handler, state) {
const currentHandler = handler;
let currentState = state;
const listeners = [];
function getState() {
return currentState;
}
function getListeners() {