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 globalContainer = null; | |
var replaceGlobalContainer = function() { | |
var localRef = globalContainer; | |
var unused = function () { | |
// refering to localRef inside even unused function | |
// puts it into replaceGlobalContainer call Context | |
// it no longer is truly a "local" variable, it needs to |
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 removeDirWithRetries(folderPath) { | |
let delay = 50; | |
let attempts = 5; | |
const retryFunc = () => fsa.rmdirAsync(folderPath).catch((e) => { | |
if (e.code === "ENOTEMPTY") { | |
attempts--; |
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 giveMePromise() { | |
return sideEffect1() | |
.then(() => { return sideEffect2(); }) | |
.then(() => { sideEffect3(); }); | |
} | |
function workOnPromise() { | |
giveMePromise().then(() => { | |
// we are still in "side effect 2" here | |
}); |
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 redis = require("redis"), | |
client = redis.createClient(); | |
testZremForSetLength(5, () => { | |
testZremForSetLength(120, () => { | |
testZremForSetLength(1000, () => { | |
testZremForSetLength(10000, () => { | |
process.exit(0); | |
}); | |
}); |
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 extractRandomSubset (fullSet, subsetLength) { | |
var maxIndex, i, m, selectedItemIndex, selectedItem; | |
if(!fullSet.length){ | |
return []; | |
} | |
maxIndex = fullSet.length - 1; | |
for (i = maxIndex, m = 0; i >= 0 && m < subsetLength; i--, 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
var kmPerDegree = 110; // approximate distance in km per latitude degree and longitude degree on equator | |
var roundingMask = Math.pow(10, 6); // rounding coordinates to 6 digits after decimal point | |
export interface ICoordinates { | |
lon: number; | |
lat: number; | |
} | |
export function toRadians(degrees: number): number { | |
return (degrees / 180) * Math.PI; |
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 crypto = require("crypto"); | |
function generateSecurePathHash(url, expires, secret) { | |
if (!url || !expires || !secret) { | |
return undefined; | |
} | |
var input = expires + url + " " + secret; | |
var binaryHash = crypto.createHash("md5").update(input).digest(); | |
var base64Value = new Buffer(binaryHash).toString('base64'); |
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
location /img/ { | |
secure_link $arg_h,$arg_e; | |
secure_link_md5 "$secure_link_expires$uri 6q3R9jhzG5"; | |
if ($secure_link = "") { | |
return 404; | |
} | |
if ($secure_link = "0") { | |
return 404; |
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
router.get("/heapdump", function (req, res, next) { | |
try { | |
require("heapdump").writeSnapshot(); | |
res.json("done"); | |
} catch (e) { | |
next(e); | |
} | |
}); |
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
<html> | |
<head> | |
<script> | |
function setAndClear() { | |
action(); | |
clear(); | |
} | |
function clear() { |
NewerOlder