Skip to content

Instantly share code, notes, and snippets.

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
function removeDirWithRetries(folderPath) {
let delay = 50;
let attempts = 5;
const retryFunc = () => fsa.rmdirAsync(folderPath).catch((e) => {
if (e.code === "ENOTEMPTY") {
attempts--;
function giveMePromise() {
return sideEffect1()
.then(() => { return sideEffect2(); })
.then(() => { sideEffect3(); });
}
function workOnPromise() {
giveMePromise().then(() => {
// we are still in "side effect 2" here
});
var redis = require("redis"),
client = redis.createClient();
testZremForSetLength(5, () => {
testZremForSetLength(120, () => {
testZremForSetLength(1000, () => {
testZremForSetLength(10000, () => {
process.exit(0);
});
});
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++) {
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;
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');
router.get("/heapdump", function (req, res, next) {
try {
require("heapdump").writeSnapshot();
res.json("done");
} catch (e) {
next(e);
}
});
<html>
<head>
<script>
function setAndClear() {
action();
clear();
}
function clear() {