Skip to content

Instantly share code, notes, and snippets.

View pinkhominid's full-sized avatar

John Ericson pinkhominid

View GitHub Profile
@pinkhominid
pinkhominid / index.js
Last active April 22, 2020 03:16
findSpliceUndo()
// Find, Splice, Undo
function findSpliceUndo(arr, findCallback) {
const idx = arr.findIndex(findCallback)
if (idx < 0) return
const removedArr = arr.splice(idx, 1)
return () => arr.splice(idx, 0, removedArr[0])
}
@pinkhominid
pinkhominid / url-utils.js
Created March 29, 2020 14:51
Are URL Origins Equal?
export function areUrlOriginsEqual(url1, url2) {
const u1 = new URL(url1);
const u2 = new URL(url2);
return u1.origin === u2.origin;
}
@pinkhominid
pinkhominid / index.html
Created March 13, 2020 20:11
Is your site/app iframeable?
<style>
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
}
iframe { flex-grow: 1 }
</style>
<script type=module>
@pinkhominid
pinkhominid / index.html
Last active May 14, 2020 13:15
Small index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
</head>
<body>
</body>
</html>
@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
@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 / 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 / ng-scope.js
Created February 4, 2020 23:05
One-line get AngularJS scope
angular.element(document.documentElement).scope()
@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 <pinkhominid@birdbomb.com>",
"license": "MIT",
"homepage": "https://gist.github.com/pinkhominid/742ff38688f7638d4eb795048b620e8e"
}
@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();
}