Skip to content

Instantly share code, notes, and snippets.

View pinkhominid's full-sized avatar

John Ericson pinkhominid

View GitHub Profile
@pinkhominid
pinkhominid / starter.css
Created November 25, 2019 13:27
2020 CSS Starter
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
html:before {
padding: 200px;
position: fixed;
background-color: #222;
@pinkhominid
pinkhominid / index.js
Created November 18, 2019 15:25
Short-hand querySelector/querySelectorAll
// Found in a Lea Verou project and tweaked :) (https://github.com/LeaVerou/animatable/blob/gh-pages/index.js#L1)
function $(expr, con) { return (con || document).querySelector(expr); }
function $$(expr, con) { return Array.from((con || document).querySelectorAll(expr)); }
@pinkhominid
pinkhominid / index.js
Created September 24, 2019 10:15
Upload a file with node-fetch and form-data
const fs = require('fs');
const fetch = require('node-fetch');
const FormData = require('form-data');
const filePath = `path/to/file.ext`;
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('field-name', fileStream, { knownLength: fileSizeInBytes });
@pinkhominid
pinkhominid / esm-tricks.js
Created August 31, 2019 13:23
ESM tricks
// Export a default import as default
export { default } from '../node_modules/roadtrip/dist/roadtrip.es.js';
// Export a default import as named
export { default as router } from '../node_modules/roadtrip/dist/roadtrip.es.js';
@pinkhominid
pinkhominid / fetch-json-retry.js
Last active February 10, 2021 19:52
fetch json with retry
function fetchJSON(url, options, retries = 0) {
return fetch(url, { cache: 'no-store', ...options })
.then(res => {
if (res.ok) return res.json();
if (retries > 0) return fetchJSON(url, options, --retries);
throw res;
});
}
@pinkhominid
pinkhominid / hide-broken-img.js
Created July 31, 2019 02:26
One-line hide a broken image
window.addEventListener('error', e=>{if (e.target.tagName !== 'IMG') return; e.target.style.visibility = 'hidden';}, true)
@pinkhominid
pinkhominid / routes.js
Created July 25, 2019 13:05
UI-Router Boilerplate
(function() {
'use strict';
angular
.module('theApp')
.config(config);
config.$inject = ['$stateProvider', '$locationProvider', '$urlRouterProvider'];
function config($stateProvider, $locationProvider, $urlRouterProvider) {
@pinkhominid
pinkhominid / example.sh
Last active July 8, 2019 19:46
Quick Git branch checkout when you don't know the complete name
# where xyz is a branch name fragment, e.g. 525 (using a ticket number)
git checkout `git branch | grep xyz`
@pinkhominid
pinkhominid / index.js
Created June 5, 2019 22:25
fetchJson
function fetchJson(url, options) {
return fetch(url, { cache: 'no-store', ...options })
.then(res => { if (res.ok) return res; throw res; })
.then(res => res.json());
}
@pinkhominid
pinkhominid / check-sha.sh
Created May 24, 2019 01:53
Bash Check SHA256 Example
shasum -a 256 -c <<< 'd42fc3297cff5ffae69b4dd4df628d50b520b26f24d7e7671c0a6b6f30d66b28 *tidy-5.6.0-macos.dmg'
tidy-5.6.0-macos.dmg: OK