Skip to content

Instantly share code, notes, and snippets.

@jwatson3d
jwatson3d / referenced_mongo_json.md
Created February 3, 2020 05:09 — forked from bclinkinbeard/referenced_mongo_json.md
Populating referenced collections in MongoDB from JSON files using Node.js and Mongoose

Populating referenced collections in MongoDB from JSON files using Node.js and Mongoose

I recently began working with Node and MongoDB for a small personal project, largely just to learn the technologies. One thing that is fairly simple but that I found far from obvious and lacking in concrete examples was how to populate the part of my database that used referenced collections from the sample JSON data I was starting with. This post attempts to fill that gap using the following code snippets, which are heavily commented inline. You will notice I am using the awesome Mongoose library which makes working with MongoDB very easy.

http.createServer( app ).listen( app.get( 'port' ), function() {

    mongoose.connect( 'mongodb://localhost/{YOUR_DB_NAME}' );

	var db = mongoose.connection;
#!/usr/bin/env bash
#
# Description
# Bootstrap SSH Session to an SSM-managed instance
# by temporarily adding a public SSH key available on the local machine (ssh-agent or in ~/.ssh)
#
#
# Installation
#
# First run your eye over this script to check for malicious code
@jwatson3d
jwatson3d / cf_create_or_update.py
Created October 29, 2021 21:58 — forked from svrist/cf_create_or_update.py
Update or create a CloudFormation stack given a name and template + params'
'Update or create a stack given a name and template + params'
from __future__ import division, print_function, unicode_literals
from datetime import datetime
import logging
import json
import sys
import boto3
import botocore

Keybase proof

I hereby claim:

  • I am jwatson3d on github.
  • I am jhwatson3d (https://keybase.io/jhwatson3d) on keybase.
  • I have a public key ASBfOJvNKmtwoQBMS7iprMbuAru0h1nOuPb0Ime_sM4l9Ao

To claim this, I am signing this object:

@jwatson3d
jwatson3d / bash_aws_jq_cheatsheet.sh
Created May 5, 2022 15:12 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@jwatson3d
jwatson3d / tf-proj-scaffold.sh
Last active August 13, 2022 18:49
A simple Bash script to scaffold a new Terraform project using HCL syntax.
#!/bin/bash
# default project name to 'test' unless specified
PROJ_NAME=${1:-test}
echo -e "Using PROJ_NAME '${PROJ_NAME}'\n"
# pause to allow inspection
echo "Press any key to proceed or Ctl+C to quit"
read -n 1 -s
@jwatson3d
jwatson3d / conventional-commits.md
Created September 28, 2022 02:29 — forked from Zekfad/conventional-commits.md
Conventional Commits Cheatsheet

Quick examples

  • feat: new feature
  • fix(scope): bug in scope
  • feat!: breaking change / feat(scope)!: rework API
  • chore(deps): update dependencies

Commit types

  • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci: Changes to CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore: Changes which doesn't change source code or tests e.g. changes to the build process, auxiliary tools, libraries

Conventional Commit Messages

See how a minor change to your commit message style can make a difference. Examples

Have a look at CLI util git-conventional-commits to ensure this conventions and generate changelogs

Commit Formats

Default

#!/bin/bash
## Install development dependencies for macOS
#
# Usage: ./initial-macos-developer-setup.sh [--debug]
#
# Bash script installing the basic developer macOS command line
# development tools from Apple for this particular version of macOS,
# installs the `brew` package manager, and a few essential brew
# tap sources and settings.
pyenv install --list | grep " 3\.[789]"
pyenv versions
pyenv install 3.10.10
python3 -m venv .venv
source .venv/bin/activate
pyenv local 3.10.10