Skip to content

Instantly share code, notes, and snippets.


Dan Levy justsml

View GitHub Profile
justsml / index.html
Created Apr 16, 2019
User Interface I: Airport Starter File
View index.html
Semantic Markup === Meaningful code
Some semantic markup examples:
set -e
networksetup -getdnsservers Wi-Fi
networksetup -setdnsservers Wi-Fi \
# Quad 9 Cloudflare Google
justsml / promise-timeout.js
Last active Jan 1, 2019
adds tracking of the promise timeout via `__timeout` flag
View promise-timeout.js
function promiseTimeout(msec) {
return (promise) => {
let isDone = false
promise.then(() => isDone = true)
const timeout = new Promise((yea, nah) => setTimeout(() => {
if (!isDone) {
promise.__timeout = true
nah(new Error('Timeout expired'))
}, msec))
View fetch-custom-error.js
const isOk = response => response.ok ? response.json() : Promise.reject(new Error('Failed to load data from server'))
.then(isOk) // <= Use `isOk` function here
.then(data => {
console.log(data) // Prints result from `response.json()`
.catch(error => console.error(error))
View promised-timeout.js
function promiseTimeout(msec) {
return promise => {
const timeout = new Promise((yea, nah) => setTimeout(() => nah(new Error('Timeout expired')), msec))
return Promise.race([promise, timeout])
.then(response => response.json())
.then(data => {
View postgres

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.


installation, Ubuntu

View file-upload-field.html
<input type='file' multiple class='files' name='files' />
View progressHelper-usage.js
// OPTION #1: no temp streamProcessor var
// fetch(...)
// ⚠️ OR️ ️⚠️
// OPTION #2: define a `streamProcessor` to hold our console logger
const streamProcessor = progressHelper(console.log)
// fetch(...)
View getBlob.js
const getBlob = url => fetch(url)
.then(progressHelper(console.log)) // progressHelper used inside the .then()
.then(response => response.blob())
You can’t perform that action at this time.