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 randomLatLon() { | |
let lat = (Math.random() * 180 - 90).toFixed(8) | |
let lon = (Math.random() * 360 - 180).toFixed(8) | |
return { | |
lat, | |
lon | |
} | |
} |
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
'use strict'; | |
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+'; | |
const ALPHABET_LENGTH = ALPHABET.length; | |
const ID_LENGTH = 8; | |
const UNIQUE_RETRIES = 9999; | |
let HashID = {}; | |
HashID.generate = 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
'use strict'; | |
const qr = require('qr-image'); | |
const mongoose = require('mongoose'); | |
const Grid = require('gridfs'); | |
const json = { | |
email: 'john@doe.com', | |
name: 'John Doe' | |
}; |
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
'use strict'; | |
function getMothersDay(year) { | |
// Earliest possible Mothers day | |
var date = new Date(year, 4, 7); | |
date.setDate(7 + (7 - date.getDay())); | |
return date; | |
} | |
function getFathersDay(year) { | |
// Earliest possible Fathers day |
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
String.prototype.toWesternNumerals = function () { | |
return this.replace(/[\u0660-\u0669]/g, (c) => { | |
return c.charCodeAt(0) - 0x0660; | |
}).replace(/[\u06f0-\u06f9]/g, (c) => { | |
return c.charCodeAt(0) - 0x06f0; | |
}); | |
} |
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 crypto = require('crypto'); | |
module.exports = class Encryptor { | |
constructor(encryptionKey) { | |
this.ENCRYPTION_KEY = encryptionKey.toString(); // Must be 256 bits (32 characters) | |
this.IV_LENGTH = 16; // For AES, this is always 16 | |
} | |
encrypt(text) { | |
let iv = crypto.randomBytes(this.IV_LENGTH); |
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
module.exports = function difference(object, base) { | |
function changes(object, base) { | |
let arrayIndexCounter = 0; | |
return _.transform(object, function (result, value, key) { | |
if (!_.isEqual(value, base[key])) { | |
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key; | |
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value; | |
console.log("Result: " + JSON.stringify(result)); | |
} | |
}); |
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
#!/bin/bash | |
# Get ids of processes running longer than 6 hrs (21600 secs) | |
PIDS=$(ps eaxo etimes,bsdtime,pid,comm,cmd | grep node | grep command-line-processes | awk '{if ($1 >= 21600) print $3}') | |
for i in ${PIDS}; | |
do { | |
PROC_FILE_PATH=$(ps eaxo pid,cmd | grep node | grep "$i"| awk '{print $3}'); | |
SCRIPT_NAME=$(basename "$PROC_FILE_PATH"); | |
printf "Killing $SCRIPT_NAME\n"; |
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(global){ | |
var MathUtils = { | |
powermod: function powermod(num, exp, mod){ | |
if(exp === 1) return num % mod; | |
if(exp & 1 === 1){ //odd | |
return (num * powermod(num, exp-1, mod)) % mod; | |
} | |
return Math.pow(powermod(num, exp/2, mod), 2) % mod; | |
}, |
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
export function uuid() { | |
let rnd: number, val: { toString: (arg0: number) => string }; | |
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => { | |
rnd = (Math.random() * 16) | 0; | |
val = c === "x" ? rnd : (rnd & 0x3) | 0x8; | |
return val.toString(16); | |
}); | |
} |