Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Dan Levy justsml

View GitHub Profile
@justsml
justsml / index.html
Created Apr 16, 2019
User Interface I: Airport Starter File
View index.html
<!--
Semantic Markup === Meaningful code
Some semantic markup examples:
<nav></nav>
<section></section>
<main></main>
<header></header>
View better-privacy-dns-servers.sh
#!/bin/bash
set -e
echo "> CURRENT DNS SERVERS:"
networksetup -getdnsservers Wi-Fi
networksetup -setdnsservers Wi-Fi \
9.9.9.9 1.1.1.1 8.8.8.8
# Quad 9 Cloudflare Google
echo "> DNS SERVERS UPDATED"
@justsml
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'))
fetch('https://api.github.com/orgs/nodejs')
.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])
}
}
promiseTimeout(5000)(fetch('https://api.github.com/orgs/nodejs'))
.then(response => response.json())
.then(data => {
View postgres cheatsheet.md

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.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

View file-upload-field.html
<input type='file' multiple class='files' name='files' />
View progressHelper-usage.js
// OPTION #1: no temp streamProcessor var
// fetch(...)
.then(progressHelper(console.log))
// ⚠️ OR️ ️⚠️
// OPTION #2: define a `streamProcessor` to hold our console logger
const streamProcessor = progressHelper(console.log)
// fetch(...)
.then(streamProcessor)
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.