Skip to content

Instantly share code, notes, and snippets.

kennwhite / merkel.json
Created January 16, 2023 18:15
Mock records for testing subdocuments and extended json EJSON-style dates (this is all fake data)
View merkel.json
"name": "Angela Merkel",
"dob": {
"$date": {
"$numberLong": "-487900800000"
"phone": "+49 30 182722720",
"address": {
"street": "Willy-Brandt-Straße 1",
kennwhite /
Last active December 21, 2022 23:17
Set Ubuntu 20.04 mongodb recommended ulimits
# ulimit -a
# sudo sysctl net.ipv4.tcp_fastopen=3
# sudo sysctl vm.max_map_count=524288
# note: "-l" (max locked memory) has no soft limit
# apt-get install numactl
sudo sh -c "sysctl -w net.ipv4.tcp_fastopen=3 ; \
sysctl -w vm.max_map_count=524288 ; \
ulimit -l unlimited ; \
kennwhite / sublimeRegExp1.txt
Last active December 17, 2022 04:15
Sublime regexp for find & replace
View sublimeRegExp1.txt
Regular expression for Sublime to find & replace and add double quotes
"$numberLong": 706213333988
"$numberLong": "706213333988"
Use this (make sure the [.*] button on the left is pressed)
Find: \$numberLong": (.*)
kennwhite / javascript_node_random_dob.js
Created December 9, 2022 04:04
Javascript/Node function to generate a random date set to UTC 00:00:00 timestamp
View javascript_node_random_dob.js
// Create a native Javascript Date object set to UTC 00:00:00 timestamp
// Here, the default parameters create a plausible DOB
function randomDate( start = new Date(1935, 0, 1), end = new Date(2004, 0, 1) ) {
var dt = new Date(+start + Math.random() * (end - start));
return dt;
// Random DOB
kennwhite /
Last active September 7, 2022 02:58
Setting up VS Code and Golang with debug & build flag (-tags foo) support

Setting up VS Code and Golang with debug & build flag (-tags foo) support

This is the setup that worked for me after half a day of hacking around and chasing rabbit holes down old forum posts and open & closed Github issues.

Problem: While Go integration with VS Code is pretty slick in general, I needed to pass compile-time build flags, e.g., -tags foo[^1] to go build and go run directives, and I wanted to be able to properly debug with breakpoints etc. While there are some promising tutorials out there like this on Digital Ocean and on Log Rocket it turned out that one of the first things they both say to do is add the Delve extension to VS Code,

kennwhite /
Created September 4, 2022 02:33
Permanently show hidden files in MacOS Monterey including Sublime Text
# To change the default Finder behavior and actually show hidden files/directories
defaults write AppleShowAllFiles -boolean true; killall Finder
# To make the Sublime 4 (Build 4126 at time of writing) File Open dialog boxes to also show hidden files
defaults write com.sublimetext.4 AppleShowAllFiles -bool true
kennwhite / csfle_explicit_hello_world.go
Last active September 5, 2022 21:24
CSFLE explicit encryption golang Hello World example
View csfle_explicit_hello_world.go
CSFLE explicit encryption golang Hello World example
brew install mongodb/brew/libmongocrypt
go get
go get
go get
go get
kennwhite / Dockerfile
Last active April 22, 2022 02:55
MongoDB .NET Alpine Dockerfile CSFLE example (MSFT's Alpine SDK image and Alpine's official image)
View Dockerfile
# syntax=docker/dockerfile:1
# FROM alpine:3.15
ENV MDB_CONN_STR="mongodb+srv://"
RUN apk update
RUN apk add git make cmake g++ libbson-static musl-dev libc-dev openssl openssl-dev py3-pip icu-dev bash nano coreutils
RUN mkdir -p /code/app
WORKDIR /code/app
kennwhite /
Created April 18, 2022 20:51 — forked from pkdone/
MongoDB CSFLE example using mongosh with a master key sourced from KMIP or a local file

MongoDB Client-Side Field Level Encryption (CSFLE) Using KMIP or Local Master Key (with mongosh)


  • You have an accessible MongoDB deployment already running and accessible (self-managed or in Atlas)
  • You have the modern MongoDB Shell (mongosh) installed locally on your workstation
  • You have a KMIP Server running and accessible, if you don't intend to use a local keyfile (for an example of running and configuring a Hashicorp Vault development instance, see: Hashicorp Vault Configuration For MongoDB KMIP Use)

Configure Local Workstation Context Files

kennwhite /
Last active April 6, 2022 23:57
Non-interactive user create & password change for Alpine Linux
#! /usr/bin/env sh
# Create unprivileged Alpine linux user. Run this script as root/sudo
# Don't prompt for password and make group same as username, default path & shell
adduser -D -g appuser appuser
# Set a decent random password (aiming for a 256 bit security level, but better than "monkey")
PW=$(head -c 32 /dev/urandom | base64) && echo -e "$PW\n$PW" | passwd appuser && unset PW