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
/* | |
* shake.js - Enable shake gesture detection to trigger a callback function. | |
* Code based on a gist by iLee @ https://gist.github.com/leecrossley/4078996 | |
* | |
* Sample usage: | |
* var Shaker = require("./shake"); | |
* var shaker = new Shaker( | |
* function onShakeSuccess() { | |
* console.debug("Shake motion detected!"); | |
* }, |
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
/* | |
* isConnected.js | |
* Determine if a node is connected to another node within a graph. | |
* The implementation uses the Breath-first search algorithm. | |
* http://en.wikipedia.org/wiki/Breath-first_search | |
* | |
* Download this file to run the program and its test cases: | |
* % node isConnected.js | |
* | |
* Sample output: |
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
/** | |
* shortBinary.js | |
* "Short binary" format uses an array A to represent a binary number B'. | |
* If A[i] = x then B[x] = 1 where B is a string representing a binary number B'. | |
* For example: | |
* Short binary format of [0, 3, 7] represents the binary number 10010001. | |
* | |
* This program produces an array in the "short binary" format that represents | |
* 3 times the the input array (also in short binary format). | |
* |
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
/** | |
* myParseInt.js | |
* My implementation of the parseInt function. | |
* The function takes a string and returns an integer. i.e. int myParseInt(string str) | |
* | |
* Download this file to run the program and test cases: | |
* % node myParseInt.js | |
* | |
* Sample output: | |
* Correct: "999.4" --> 999 |
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
/** | |
* fff.js: | |
* fff, Fast File Find, efficiently find a huge number of files (of specific file types, | |
* html, xml and json) which contain phone numbers in the format (xxx)-xxx-xxxx or xxx-xxx-xxxx | |
* | |
* The implementation takes advantage of the asynchronous processing of Node.js. | |
* | |
* To run: (expects test files stored under the "data" folder) | |
* % node fff.js | |
* |
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 Tree { | |
/* | |
* Construct an empty tree | |
*/ | |
constructor () { | |
this.connections = {} | |
} | |
/* | |
* Return a ';' delimited string with each component |
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
{ | |
"namespace": "customerManagement.avro", | |
"type": "record", | |
"name": "Customer", | |
"fields": [ | |
{ | |
"name": "userID", "type": "long", "default": 9999 | |
}, | |
{ | |
"name": "userName", "type": "string" |
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
/* | |
* Enhance Avro to support data validation via Regular Expression | |
*/ | |
const avro = require('avsc') | |
class ValidatedString extends avro.types.LogicalType { | |
constructor (attrs, opts) { | |
super(attrs, opts) | |
this._pattern = new RegExp(attrs.pattern) | |
} |
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
async function sequentialExecutor(arr) { | |
const resArr = [] | |
for (const func of arr) { | |
const res = await func() | |
resArr.push(res) | |
} | |
return resArr | |
} |