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 row = "word".split(""); | |
| // splice modifies original array | |
| function pull (row, i) { | |
| var arr = []; | |
| row.forEach(function (item, j) { | |
| if (i!=j) arr.push(item); | |
| }); | |
| return 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
| var Bacon = require('baconjs'); | |
| var Rx = require('rx'); | |
| var Kefir = require('kefir'); | |
| var EE = require('events').EventEmitter; | |
| var ee = new EE; | |
| var sum = function (prev, cur) {return prev+cur}; | |
| Bacon.fromEvent(ee, 'event1').scan(0, sum).onValue(console.log); // 0, 4, 9 | |
| Rx.Observable.fromEvent(ee, 'event1').reduce(sum, 0).subscribe(console.log); // doesn't work |
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
| let x = 1; | |
| let sum = (a, b) => a + b + x | |
| sum(1, 2); // 4 | |
| x = 2; | |
| sum(1, 2); // 5 |
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
| const http = require('http'); | |
| // Swagger-like API description | |
| const api = { | |
| '/users': { | |
| 'get': { | |
| 'parameters': { | |
| 'role': { | |
| 'in': 'query' | |
| }, |
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 schemaLoaded = kefir.fromEvents(app, 'server:schema').take(1); | |
| var serverListening = kefir.fromEvents(app, 'server:running').take(1); | |
| return kefir.merge([schemaLoaded, serverListening]).toPromise(); |
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
| /** | |
| * @param val {*} | |
| * @returns {Boolean} | |
| */ | |
| function isNothing(val) { | |
| return val === undefined || val === null; | |
| } | |
| /** | |
| * @param val {*} | |
| * @return {Number} |
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
| app.post((req, res) => { | |
| const user = db.getUserByName(req.headers.name); | |
| const user = db.getUserByName(req.query.name); | |
| const user = db.getUserByName(req.path.name); | |
| const user = db.getUserByName(req.body.name); | |
| }); |
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
| factorial 0 = 1 | |
| factorial n = n * factorial (n — 1) |
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
| class ZeroValue extends Error {} | |
| class OtherValue extends Error {} | |
| function resolveValue(val) { | |
| return Promise.resolve().then(() => { | |
| if (!val) throw new ZeroValue(); | |
| throw new OtherValue(val); | |
| }); | |
| } |
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 bash | |
| TAG="kafka-brokers-demo" | |
| sudo yum install -y jq | |
| sudo yum install -y wget | |
| sudo yum install -y java | |
| cd ~ | |
| wget "http://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz" | |
| tar -xvf kafka_2.11-2.1.0.tgz |
OlderNewer