Skip to content

Instantly share code, notes, and snippets.

View pinkhominid's full-sized avatar

John Ericson pinkhominid

View GitHub Profile
@pinkhominid
pinkhominid / history-event.js
Last active February 12, 2021 20:13
Custom historychangestate event for web apps that use history.pushState or history.replaceState
export const HISTORY_STATE_CHANGE_EVENT = 'historystatechange';
history.pushState = changeState(history.pushState)
history.replaceState = changeState(history.replaceState)
window.addEventListener('popstate', fireStateChange)
setTimeout(fireStateChange);
function changeState(orig) {
return (...args) => {
@pinkhominid
pinkhominid / .bash_profile
Last active November 30, 2018 22:59
My macOS Bash dotfiles
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
/**
* @category Common Helpers
* @summary Convert the given argument to an instance of Date.
*
* @description
* Convert the given argument to an instance of Date.
*
* If the argument is an instance of Date, the function returns its clone.
*
* If the argument is a number, it is treated as a timestamp.
@pinkhominid
pinkhominid / subl-user-prefs.json
Last active January 26, 2019 05:21
My Sublime Text user preferences
{
"ensure_newline_at_eof_on_save": false,
"font_size": 13,
"ignored_packages":
[
],
"rulers":
[
100
],
@pinkhominid
pinkhominid / one-line-fetch.js
Last active April 19, 2019 03:11
Fetch in console
fetch('/api/things')
.then(res => res.json())
.then(res => console.log(res))
@pinkhominid
pinkhominid / abortable-http-service.js
Last active January 26, 2019 04:46
AngularJS abortable GET request
/** Aborting $http made simple */
export class AbortableHttpService {
constructor($q, $http, $timeout) {
this.$q = $q;
this.$timeout = $timeout;
this.$http = $http;
}
get(url, options = {}) {
const {$q, $http, $timeout} = this;
@pinkhominid
pinkhominid / index.html
Last active January 26, 2019 03:26
Short valid HTML starter
<!doctype html><html lang=en><meta charset=utf-8><title>Hello World!</title>
@pinkhominid
pinkhominid / example.js
Created January 27, 2019 17:51
Get super class name of registered custom element
Object.getPrototypeOf(customElements.get('my-custom-element')).name
// "HTMLElement"
@pinkhominid
pinkhominid / demo-app.js
Last active January 31, 2019 01:05
Minimal Web Component Demo App Starter
const tagName = 'demo-app';
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
display: block;
contain: content;
}
:host([hidden]) {
@pinkhominid
pinkhominid / index.html
Last active February 5, 2019 02:19
AngularJS Quick Component Demo Page
<!doctype html><html lang=en><meta charset=utf-8><title>Demo</title>
<link rel=stylesheet href=component.css>
<component></component>
<script src=https://ajax.googleapis.com/ajax/libs/angularjs/1.7.6/angular.min.js></script>
<script>angular.module('componentModule', [])</script>
<script src=component.js></script>
<script>angular.bootstrap(document.documentElement, ['componentModule'])</script>