Skip to content

Instantly share code, notes, and snippets.

kennwhite

Block or report user

Report or block kennwhite

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kennwhite
kennwhite / powershell_command_urandom.js
Last active Jul 19, 2019
Powershell 1-liner to generate random n-byte key from Windows command line
View powershell_command_urandom.js
// Windows equivalent to Linux/Mac: echo $(head -c 64 /dev/urandom | base64 | tr -d '\n')
// Get-Random in Windows 10/Server 2016 PowerShell uses a CSPRNG seed by default.
// Prior to PS 5.1, seed was system clock.
// For Win 10/2016+
powershell -command "[Convert]::ToBase64String((1..64|%{[byte](Get-Random -Max 256)}))"
// For Win 8.x/2012
powershell -command "$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)"
@kennwhite
kennwhite / windows powershell random number base64.bat
Created Jul 14, 2019
windows powershell random number base64
View windows powershell random number base64.bat
05776215D594997C8BBA9502AA509920E43A442F873738E7C19CCA9E3DF3BA6F
(1..64|%{'{0:X}' -f (Get-Random -Max 16)}) -join ''
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("hello"))
[Convert]::ToBase64String((1..64| % {Get-Random -Minimum 0 -Maximum 256}))
@kennwhite
kennwhite / validating_mongodb_embedded_documents.js
Last active Jul 9, 2019
Some notes on validating embedded/nested document fields on MongoDB
View validating_mongodb_embedded_documents.js
// See: https://jira.mongodb.org/browse/SERVER-31493
//
// Most drivers will actively block "." in attempts to store documents (see first insert example below)
// but dots are fine to use for queries. Also, nested documents have to be specified carefully
// for jsonSchema document validation
//
> use schematest
switched to db schematest
>
View ClientSideEncryptionTest.java
/*
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View ClientSideEncryptionSimpleTest.java
/*
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@kennwhite
kennwhite / chicken_shrimp_korma_mortal_v1.md
Last active Apr 17, 2019
Restaurant style chicken/prawn korma - mere mortal version (v. 1)
View chicken_shrimp_korma_mortal_v1.md

Kenn's Chicken/King Prawn Coconut Curry (Korma)

Ingredients

  • 2 cups red or yellow onions, well peeled, loosely chopped
  • 6 cloves peeled garlic, finely grated
  • 2" peeled ginger root, finely grated
  • Optional: 1 medium serrano green pepper, seeded & cored, finely minced (leave out for no heat, use half pepper for medium, full for spicy)
  • 14 oz plain greek yogurt (2% or whole milk, eg FAGE 5%)
  • large can (~14 oz) unsweetened coconut milk (ideally containing no guar gum; well blended if it does)
  • 3 TB cashew butter
@kennwhite
kennwhite / Linux_setup_baseline_ChromeOS.md
Last active Sep 20, 2018
Dev environment setup for native Linux apps (VMs & containers) in ChromeOS Stable
View Linux_setup_baseline_ChromeOS.md

Notes for setting up a dev environment in Chrome Linux (Crostini VMs & containers) on Chromebooks

Once Linux Apps has been enabled in System menu, open a browser window

Open a CROSH window: ctrl-shift-T

crosh>

Enter built-in ChromeOS Linux VM termina, based on Gentoo

View .crostini-setup
These scripts set up Crostini on my Pixelbook
@kennwhite
kennwhite / enable_auth_mongodb.sh
Last active Sep 16, 2018
Enable Authentication for new install of MongoDB
View enable_auth_mongodb.sh
#!/bin/bash
sudo sed -i-`date -u|tr ' ' '_'`.bak 's/^#security:*/security:\n authorization: enabled/' /etc/mongod.conf
_mpwd=$(head -c 32 /dev/urandom 2>&1 | sha1sum | head -c 14 )
echo "db.createUser({user:'dba',pwd:'$_mpwd',roles:['root']})"|mongo admin 2>&1>/dev/null
sudo service mongod restart && sleep 5
@kennwhite
kennwhite / mongo_debian_9_install.sh
Last active Mar 20, 2019
Install MongoDB 4.x Enterprise on Debian 9
View mongo_debian_9_install.sh
#!/bin/bash
# To completely purge all remnants of Mongo (repo conf, pkgs, apt cache, DB files, pgp keys):
# sudo service mongod stop ; sudo apt-get purge -y mongodb-enterprise* ; sudo rm -rf /etc/apt/sources.list.d/mongodb* ; sudo rm -rf /var/lib/mongodb ; sudo apt-get clean; sudo apt-get autoclean ; sudo apt-get -y autoremove ; sudo apt-key del 9DA31620334BD75D9DCB49F368818C72E52529D4 ; sudo rm -rf /etc/mongod* ; sudo rm -rf /var/log/mongo ; sudo rm -rf /etc/apt/sources.list.d/mongodb-enterprise.list /etc/systemd/system/multi-user.target.wants/mongod.service
echo Installing MongoDB 4.x Enterprise edition...
echo
sudo apt-get install -y gnupg2 libcurl3
sudo apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
You can’t perform that action at this time.