This file contains 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
// Singleton pattern | |
var MySingleton=(function() { | |
// creating a variable to contain the instance | |
var instance=null; | |
// here goes private stuff | |
var _myPrivateVar=1; | |
var _myPrivateFunction=function(){ | |
console.log('In private function.'); | |
}; | |
// creating singleton constructor |
This file contains 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 Queue { | |
constructor(...elements) { | |
// Initializing the queue with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
shift(...args) { |
This file contains 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 Stack { | |
constructor(...elements) { | |
// Initializing the stack with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
pop(...args) { |
This file contains 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 Queue { | |
constructor(...elements) { | |
// Initializing the queue with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
shift(...args) { |
This file contains 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 noop = arg => arg; | |
const combine = () => Array.from(arguments).reduce((a, b) => a.concat(b)); | |
const compact = arr => arr.filter(el => el); | |
const difference = () => { | |
var others = Array.from(arguments).slice(1).reduce((a, b) => a.concat(b)); | |
return arguments[0].filter(el => !others.some(exclude => el === exclude)); | |
}; |
This file contains 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 buildMessage(values) { | |
const DIFF = Math.pow(2, 9); // 512 | |
const MAX_PRECISION = 4; // 512 * 4 allows to encode 300 <= x <= 1100 | |
const maxIndex = values.indexOf(Math.max(...values)); | |
const minIndex = values.indexOf(Math.min(...values)); | |
const maxDiff = values.reduce( | |
(diff, v) => Math.max(v - values[minIndex], diff), | |
0 | |
); | |
const precision = Math.ceil(maxDiff / DIFF); |
This file contains 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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"math" | |
"os" | |
"path/filepath" | |
"strconv" |
This file contains 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 { getInstance, initializer } from 'knifecycle'; | |
import uuid from 'uuid'; | |
import { initDelayService } from 'common-services'; | |
import { | |
initRouter, | |
initHTTP, | |
initHTTPTransaction | |
} from 'swagger-http-router'; |
This file contains 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
{ | |
"swagger": "2.0", | |
"info": { | |
"description": "WMG web services running altogether", | |
"version": "5.6.0", | |
"title": "infrastructure-wmg" | |
}, | |
"host": "localhost:1664", | |
"schemes": [ | |
"https" |
This file contains 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
// No middleware, just pur functions | |
import getBodyFromReq from 'pureBodyParser'; | |
import getQueryFromReq from 'pureQueryParser'; | |
import sendToRes from 'pureResponseMaker'; | |
// Use dependency injection for required services | |
// app/config/timer just come from this function caller | |
module.exports = ({ app, config, timer}) => { | |
app.post((req, res) => { |