Skip to content

Instantly share code, notes, and snippets.

Avatar

Jim Montgomery jimmont

View GitHub Profile
@jimmont
jimmont / websockets.js
Created Jul 27, 2020
http upgrade websocket
View websockets.js
/*
running with Deno 1.2
deno run --inspect --allow-net ./websockets.js
*/
import { Application, Router, HttpError, send, Status } from "https://deno.land/x/oak@v6.0.1/mod.ts";
import { isWebSocketCloseEvent } from "https://deno.land/std@0.61.0/ws/mod.ts";
const port = 8123;
const users = new Set();
const app = new Application({state:{users}});
View linkedlist.js
/*
add,remove,length, reverse
{value,next}
*/
class List{
constructor(){
}
}
class Node{
@jimmont
jimmont / jsx-template-transformer.js
Last active Feb 26, 2020
transform jsx to tagged template literals
View jsx-template-transformer.js
/*
transform JSX to tagged template literals
history:
2019-01-25 initial working draft
https://stackoverflow.com/a/54381294/965666
https://astexplorer.net/#/gist/fdaed19a884dc75fe4a92092826bd635/9bc3c34e276eaf74cc318da9b87bbe0cfd37ff6d
https://astexplorer.net/#/gist/fdaed19a884dc75fe4a92092826bd635/9a47a064fe0734868f8c5c46ceb99de6ebfe3600
@jimmont
jimmont / flat-arbitrary.js
Last active Feb 22, 2020
array flat arbitrary
View flat-arbitrary.js
/*
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.
*/
View amazing.js
// 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 / validations.js
Last active Sep 18, 2019
validate email addresses, dates, etc in JavaScript
View validations.js
/*
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 / the-controls.js
Created Jun 28, 2018
SF muni map for code review feedback (and self-improvement)
View the-controls.js
// 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 / zfs-filesystem-basics.md
Last active Dec 9, 2018
zfs basic usage notes
View zfs-filesystem-basics.md

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 / mssql.notes.txt
Last active Sep 20, 2018
mssql on macos setup notes
View mssql.notes.txt
§ 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
View reading-list.html
<pre>
* https://google.github.io/styleguide/jsguide.html
* nytimes.com
* washingtonpost.com
*
</pre>
You can’t perform that action at this time.