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
| // 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'); |
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
| stages: | |
| - build | |
| - deploy | |
| - migrate | |
| cache: | |
| paths: | |
| - backend/node_modules/ | |
| - mobile/node_modules/ |
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
| 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(); |
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
| 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(); |
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
| 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!' }) |
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
| 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 |
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
| 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)) { |
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
| 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); |
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
| 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 |
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
| export default function createStore(handler, state) { | |
| const currentHandler = handler; | |
| let currentState = state; | |
| const listeners = []; | |
| function getState() { | |
| return currentState; | |
| } | |
| function getListeners() { |