Skip to content

Instantly share code, notes, and snippets.

View jimmont's full-sized avatar

Jim Montgomery jimmont

View GitHub Profile
@jimmont
jimmont / normal.js
Last active August 27, 2017 00:21
collection to sync various api details in Safari-current and Chrome-current
if(!Event.prototype.hasOwnProperty('path')){
/*
in event handlers use the event.path which looks like:
for attached DOM nodes [target,target.parentNode,...<ancestors>...,document,window]
for unattached DOM nodes [target]
for window and document: [window] [document, window]
*/
Object.defineProperty(Event.prototype, 'path', {
// for Safari
get:function(){
@jimmont
jimmont / raspbian.pi
Last active September 21, 2017 22:48
## 2017 Sept RPi 3
serial gpio to USB requires editing `config.txt` on sdcard, see the following
http://elinux.org/RPi_Serial_Connection
https://raspberrypi.stackexchange.com/questions/44427/how-to-connect-a-raspberry-pi-3-to-usb-tty-cable
## older, older models
https://www.raspberrypi.org/downloads/raspbian/
download the image then expand the archive and:
@jimmont
jimmont / reading-list.html
Created November 27, 2017 03:52
reading list
<pre>
* https://google.github.io/styleguide/jsguide.html
* nytimes.com
* washingtonpost.com
*
</pre>
@jimmont
jimmont / the-controls.js
Created June 28, 2018 18:53
SF muni map for code review feedback (and self-improvement)
// see https://www.jimmont.com/sfmuni/
class TheControls extends HTMLElement{
constructor(){
super();
this.attachShadow({mode:'open'});
// {tags: {N: {}...}, taglist: []}
this.data = {};
this.addEventListener('click', this.clicked);
}
clicked(e){
@jimmont
jimmont / webcomponents.html
Last active July 6, 2018 17:51
web component v1 notes
web components v1 (not v0)
~July 2018
various npm installed components which use named imports like `import "@name"`;
instead of a build tool or service just do a one-time conversion when updating for predictability and simplicity using standard stuff:
cd node_modules && cp -R @polymer @webcomponents @vaadin lit-html pwa-helpers ../modules/
cd ../modules/ && rm -f `find . -iname '*.map'` && rm -f `find . -iname '*.ts'`
find . -type f -name '*.js' -print0 | xargs -0 perl -plwe 's/([\\"\\'"'"'])(\@(?:polymer|webcomponents|lit-html|lit-element|vaadin\/))/$1\/modules\/$2/g' -i
@jimmont
jimmont / mssql.notes.txt
Last active September 20, 2018 10:52
mssql on macos setup notes
§ install
1. install Homebrew https://docs.brew.sh/Installation.html
2. install Docker
$ brew cask install docker
this places the Docker.app in the Applications folder, and can be launched directly to start the service
3. install mssql per the instructions https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker
$ sudo docker pull microsoft/mssql-server-linux:2017-latest
4. run the image, check the status
$ sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_PID=Developer' -e 'MSSQL_SA_PASSWORD=<password>' -p 1433:1433 --name mssql0 -d microsoft/mssql-server-linux:2017-latest
@jimmont
jimmont / zfs-filesystem-basics.md
Last active December 9, 2018 04:56
zfs basic usage notes

late 2018 encrypted disk per https://openzfsonosx.org/wiki/Encryption

create new encrypted disk
plug in device
$ diskutil list
important to be absolutely certain of the device
$ sudo zpool create -f -o ashift=12 -O compression=lz4 -O casesensitivity=sensitive -O atime=off -O normalization=formD -O encryption=on -O keylocation=prompt -O keyformat=passphrase NAMEOFIT /dev/disk####
will interactively prompt for passphrase
next time importing plug in the device
@jimmont
jimmont / validations.js
Last active September 18, 2019 17:44
validate email addresses, dates, etc in JavaScript
/*
take an approach leveraging the platform implementation's internal parser for things to validate,
if it works in these on the user-experience side confirm the input is as-intended
possibly by entering the same value twice or similar user-controlled validation
email and date validation is too complex for pattern matching;
*/
function validEmail(email=''){
var $0, url, isValid = false, emailPatternInput = /^[^@]{1,64}@[^@]{4,253}$/, emailPatternUrl = /^[^@]{1,64}@[a-z][a-z0-9\.-]{3,252}$/i;
@jimmont
jimmont / amazing.js
Created January 23, 2020 21:14
greatest hits
// I always do this. Always.
Array(4).fill(undefined);
Object.values(Array(6,7,8)).length === Number(Object.keys([7,6,4]).pop()) + 1
@jimmont
jimmont / flat-arbitrary.js
Last active February 22, 2020 18:52
array flat arbitrary
/*
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
Your solution should be a link to a gist on gist.github.com with your implementation.
When writing this code, you can use any language you're comfortable with. The code must be well tested and documented. Please include unit tests and any documentation you feel is necessary. In general, treat the quality of the code as if it was ready to ship to production.
Try to avoid using language defined methods like Ruby's Array#flatten or JavaScript's Array.flat.
*/