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
var isOp = function (op) { | |
return !!({ | |
'+': true, | |
'-': true, | |
'*': true, | |
'/': true | |
}[op]) | |
}; | |
var applyOp = function (op, a, b) { |
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
// Paste in browser developer tools | |
Array(100).join('.').split('.').map(function (a, index) { return (~~(Math.random()*(1<<24))).toString(16) }).forEach(function(color) { console.log("%c ", "background-color: #" + color) }); |
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
{ | |
"auto_indent": true, | |
"bold_folder_labels": false, | |
"caret_style": "wide", | |
"color_scheme": "Packages/User/Monokai (SL).tmTheme", | |
"ensure_newline_at_eof_on_save": true, | |
"file_exclude_patterns": | |
[ | |
"*.pyc", | |
"*.pyo", |
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
var config = require("config"); | |
var pg = require("pg"); | |
var PromiseB = require("bluebird"); | |
PromiseB.promisifyAll(pg); | |
// To prevent data loss handle bigint as string | |
// https://github.com/brianc/node-postgres/pull/353 | |
pg.defaults.parseInt8 = false; |
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
var requests = { docs: [ 'hello' ], boards: [ 'R404' ] }; | |
var fetchResultTransform = function (requests) | |
{ | |
var resource = []; | |
Object.keys(requests).forEach(function (colName) | |
{ | |
requests[colName].forEach(function (docName) | |
{ |
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
var p1 = new Promise(function (resolve) { | |
return resolve(10); | |
}); | |
var add = function (num) { | |
return new Promise(function (resolve) { |
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
var getProviderInfo = function (provider) | |
{ | |
return new Promise(function (resolve, reject) { | |
var time = ~~(Math.random() * 2000) + 2000; | |
// Make request and get the data, simulate request api, no fail in our case | |
window.setTimeout(function () { | |
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
s := func(name string) string { | |
time.Sleep(4 * time.Second) | |
fmt.Println("Do something", name) | |
return "Done" | |
} | |
results := []string{} | |
c := make(chan string) | |
go func() { c <- s("first") }() |
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
var profile OAuthProfile | |
MapToStruct(result, &profile) | |
fmt.Println("Extracted", profile) | |
func MapToStruct(m map[string]interface{}, val interface{}) error { | |
tmp, err := json.Marshal(m) |
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
// Exponential moving average | |
function average (alpha) { | |
var last; | |
alpha = alpha || 3/4; | |
return function (input) { | |
if (!last) { | |
last = input; |