Skip to content

Instantly share code, notes, and snippets.

View omit-irrelevant-mongoose-properties-for-obj-comparison.js
const _ = require('lodash')
const IRRELEVANT_PROPS_FOR_OBJECT_COMPARISON = ['__v', '_doc', '$__', '_id'];
/*
* Remove properties that you don't care about from a mongoose object
* to make comparing mongoose objects easy.
*/
omitIrrelevantMongoosePropertiesForObjComparison(obj) {
let relevantObjProps;
View sinon-clock-tick-dst-fix.js
const _ = require('moment')
const MAX_MONTHS_TO_TEST_DST_OFFSET = 12;
const convertToMoment = (date) {
if (date instanceof moment) return date;
return new moment(date);
}
const wasDSTNowNot = (was, now = new moment()) => {
@lukeaus
lukeaus / mongoRenameEmbeddedDocsFields.js
Last active Jun 10, 2019
Mongo rename embedded docs field
View mongoRenameEmbeddedDocsFields.js
/*
* Given the following schema for collection 'foo':
* myDoc: {
* embeddedDocs: [
* {
* bar: 'a',
* baz: 'b',
* },
* {
* bar: 'b',
@lukeaus
lukeaus / Visual Studio Code - Task - Babel Compile and Run.js
Created Aug 3, 2017
Get started in Visual Studio Code with Babel Quickly
View Visual Studio Code - Task - Babel Compile and Run.js
// Terminal
npm init
npm install --save babel-cli babel-preset-env
// Visual Studio Code
// Tasks --> Configure Tasks
// tasks.json
{
"version": "0.1.0",
"command": "${workspaceRoot}/node_modules/.bin/babel-node",
View convert_id_to_hash.py
import hashids
SALT = "this is my salt"
hash_func = hashids.Hashids(salt=SALT, min_length=16)
hash_ = hash_func.encode(1,) # ''JEDngB0NV05ev1Ww'
ids = hash_func.decode(hash_) # (1,)
@lukeaus
lukeaus / gist:bea183f8e3ea39993eed7911911ab1f1
Last active Jun 15, 2018
Install nodejs and npm on Ubuntu 14.04
View gist:bea183f8e3ea39993eed7911911ab1f1
# Install packages to allow Node to be installed
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-get install apt-transport-https
# Install Node
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280
# change /node_6.x to whatever release version of node you would like (e.g. node_5.x)
sudo apt-add-repository "deb https://deb.nodesource.com/node_6.x $(lsb_release -sc) main"