Skip to content

Instantly share code, notes, and snippets.

@lukeaus
lukeaus / gist:bea183f8e3ea39993eed7911911ab1f1
Last active June 15, 2018 17:51
Install nodejs and npm on Ubuntu 14.04
# 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"
@lukeaus
lukeaus / convert_id_to_hash.py
Created July 25, 2017 04:09
Convert id to hash
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 / Visual Studio Code - Task - Babel Compile and Run.js
Created August 3, 2017 08:34
Get started in Visual Studio Code with Babel Quickly
// 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",
@lukeaus
lukeaus / mongoRenameEmbeddedDocsFields.js
Last active June 10, 2019 22:40
Mongo rename embedded docs field
/*
* Given the following schema for collection 'foo':
* myDoc: {
* embeddedDocs: [
* {
* bar: 'a',
* baz: 'b',
* },
* {
* bar: 'b',
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()) => {
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;