Skip to content

Instantly share code, notes, and snippets.

View pinkhominid's full-sized avatar

John Ericson pinkhominid

View GitHub Profile
@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 / 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 / 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 / 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 / are-urls-equal.js
Last active January 16, 2020 17:25
areUrlsEqual()
// Handles root path slash and casing diffs correctly. For example:
// areUrlsEqual('http://example.com', 'http://Example.com/') => true
export default function areUrlsEqual(url1, url2) {
const u1 = new URL(url1);
const u2 = new URL(url2);
return u1.toString() === u2.toString();
}
@pinkhominid
pinkhominid / package.json
Last active February 6, 2021 00:15
URL fun
{
"version": "0.3.0",
"name": "url-fun",
"description": "URL fun",
"main": "url-fun.js",
"author": "pinkhominid <[email protected]>",
"license": "MIT",
"homepage": "https://gist.github.com/pinkhominid/742ff38688f7638d4eb795048b620e8e"
}
@pinkhominid
pinkhominid / ng-scope.js
Created February 4, 2020 23:05
One-line get AngularJS scope
angular.element(document.documentElement).scope()
@pinkhominid
pinkhominid / starter.html
Last active February 5, 2020 03:15
Minimal 2020 Header/Main Starter (w/full document element scrolling)
<!doctype html>
<head>
<!-- See 2020 CSS Starter https://gist.github.com/pinkhominid/c59aa716fb9598d3e547a87305ef198d -->
<link rel=stylesheet href=https://gist.githubusercontent.com/pinkhominid/c59aa716fb9598d3e547a87305ef198d/raw/08f50f2d48074414d67e378f302be4bb31231170/starter.css>
<style>
body {
display: flex;
flex-direction: column;
}
header {
@pinkhominid
pinkhominid / eventPathFindTargetMatch.js
Last active March 3, 2021 13:46
browser event path find target match
export function eventPathFindTargetMatch(event, selector) {
return event.composedPath().find(target => target.matches?.(selector));
}
@pinkhominid
pinkhominid / oss-npm-pkg-setup.md
Last active April 2, 2020 13:41
2020 Minimal OSS npm pkg setup

2020 Minimal OSS npm pkg setup

  • New repository
  • Initialize this repository with a README
  • Add .gitignore Node
  • Add a license MIT License
  • Create repository
  • Clone or download
  • Copy to clipboard