Skip to content

Instantly share code, notes, and snippets.

View grantcarthew's full-sized avatar
🙂
Coding

Grant Carthew grantcarthew

🙂
Coding
View GitHub Profile
@grantcarthew
grantcarthew / settings.json
Last active November 29, 2018 03:26
VSCode Settings Backup
{
"workbench.colorTheme": "Solarized Light",
"workbench.editor.closeEmptyGroups": false,
"explorer.openEditors.visible": 0,
"explorer.autoReveal": false,
"editor.tabSize": 2,
"gitlens.advanced.messages": {
"suppressCommitHasNoPreviousCommitWarning": false,
"suppressCommitNotFoundWarning": false,
"suppressFileNotUnderSourceControlWarning": false,
@grantcarthew
grantcarthew / New-ACMEUser.csv
Last active October 22, 2019 12:19
Office 365 User Provisioning
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 15 columns, instead of 4 in line 8.
User Name,First Name,Last Name,Display Name,Job Title,Department,Office Number,Office Phone,Mobile Phone,Fax,Address,City,State or Province,ZIP or Postal Code,Country or Region
Porky,Porky,Pig,Porky Pig,Sidekick,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Daffy,Daffy,Duck,Daffy Duck,Bugs Bunny Sidekick,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Elmer,Elmer,Fudd,Elmer Fudd,Hunter,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Bugs,Bugs,Bunny,Bugs Bunny,Lead Character,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Tweety,Tweety,,Tweety,Cute Bird,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Sylvester,Sylvester,,Sylvester,Hungry Cat,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Yosemite,Yosmite,Sam,Yosmite Sam,Gun Slinger,ACME,12345,67890,1234567890,0987654321,4000 Warner Blvd,Burbank,CA,91522,USA
Foghorn,Foghorn,Leghorn,Forho

Keybase proof

I hereby claim:

  • I am grantcarthew on github.
  • I am grantcarthew (https://keybase.io/grantcarthew) on keybase.
  • I have a public key ASDuPrBqZ8grywTAt2TXnQyIDDnwMbV_uyu4ZK62K8GFggo

To claim this, I am signing this object:

Mongoose Code Snippets

Targeted Version: 5.1.6

Find Or Create

This will update the document on every call. Not the best option however it is atomic.

Ref: findOneAndUpdate

CLI Improved

This document lists improvements over the default Linux command line tools.

The list was initially motivated by a blog post by Remy Sharp.

CLI Tools

@grantcarthew
grantcarthew / server.js
Last active April 11, 2019 00:57
medium-server.js
// server.js
const log = require('./logger').child(module)
const driver = require('./store/driver')
const app = require('./app')
const SERVERPORT = process.env.SERVERPORT
if (process.listeners('unhandledRejection').length < 1) {
process.on('unhandledRejection', (reason, promise) => {
console.error(reason)
process.exit(1)
@grantcarthew
grantcarthew / app.js
Last active March 1, 2019 03:49
medium-app.js
//app.js
// Constants
const MAX_CONTENT_LENGTH_ACCEPTED = 102400000
const COOKIESIGNSECRET = process.env.COOKIESIGNSECRET
// Core Modules
const express = require('express')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
@grantcarthew
grantcarthew / package.json
Last active March 1, 2019 03:49
medium-package.json
// package.json <= JSON does not support comments. Remove this line.
{
"name": "example",
"version": "1.0.0",
"description": "Example for test script",
"main": "index.js",
"scripts": {
"test": "LOGENABLED=true LOGLEVEL=error DBCONNECTIONPOOLMAX=10 DBCONNECTIONPOOLIDLE=50 jest --watch"
},
"author": "",
@grantcarthew
grantcarthew / jest.config.js
Last active March 1, 2019 03:48
medium-jest.config.js
// jest.config.js
module.exports = {
clearMocks: true,
globalSetup: '<rootDir>/tests/setup/global-setup.js',
globalTeardown: '<rootDir>/tests/setup/global-teardown.js',
testEnvironment: '<rootDir>/tests/setup/mongo-environment.js'
}
@grantcarthew
grantcarthew / global-setup.js
Created March 2, 2019 02:46
medium-global-setup.js
// global-setup.js
const dbSetup = require('./db-setup')
module.exports = async function () {
await dbSetup()
}