Skip to content

Instantly share code, notes, and snippets.

View ryaninvents's full-sized avatar

Ryan Kennedy ryaninvents

View GitHub Profile
var iso31662 = require("iso-3166-2");
function typeValue(a) {
switch (a.type) {
case 'Outlying area': return 1;
default: return 0;
}
};
[...Object.entries(iso31662.country('USA').sub)].sort(([,a], [,b]) => {
@ryaninvents
ryaninvents / devcreds.sh
Created December 29, 2021 23:24
Utility for pulling developer credentials from Google Cloud
#!/usr/bin/env bash
# @see https://github.com/xwmx/bash-boilerplate/blob/d14e016b830b1308174ba9acc461935bb45a20ed/bash-subcommands
set -o nounset
set -o errexit
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
set -o errtrace
set -o pipefail
IFS=$'\n\t'
###############################################################################
@ryaninvents
ryaninvents / yarn.zsh
Created August 9, 2021 13:27
ZSH Yarn autocomplete
# source this from your ~/.zshrc for Yarn autocompletion
# this won't suggest standard Yarn commands (add, upgrade, etc) but will show you custom commands for this project
# make sure you have jq installed
function _yarn() {
local scripts=$(jq -r '.scripts | to_entries | '\
'map(.key |= sub(":";"\\:";"g")) | '\
'.[] | '\
'[select((.value | length) > 0)] | '\
@ryaninvents
ryaninvents / back.html
Created April 8, 2021 13:25
Anki JavaScript generated questions
<div id="back" style="display:none;"></div>
{{FrontSide}}
<hr id=answer>
{{Back}}
@ryaninvents
ryaninvents / loadModule.js
Last active March 3, 2021 17:06
Loading ESM from regular JS
function addModule(src) {
return new Promise((ok, fail) => {
const script = document.createElement('script');
const id = `module-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`;
const body = `
import * as myModule from ${JSON.stringify(src)};
document.getElementById(${JSON.stringify(id)}).dispatchEvent(new CustomEvent('moduleloaded', {detail: myModule}));
`;
script.setAttribute('id', id);
@ryaninvents
ryaninvents / .block
Last active October 8, 2019 17:24 — forked from mbostock/.block
Now
license: gpl-3.0
@ryaninvents
ryaninvents / EffectExample.jsx
Created June 21, 2019 20:44
Hook-like state encapsulation in React class components
import React from 'react';
import PropTypes from 'prop-types';
import createEffect from './createEffect';
const noop = () => {};
export default class EffectExample extends React.Component {
_setGreeting = (greeting) => this.setState({greeting});
_fetchGreeting = createEffect((name) => {
if (!name) return null;
@ryaninvents
ryaninvents / .gitignore
Last active May 9, 2019 20:46
`styled-import/macro` issue
/node_modules/
@ryaninvents
ryaninvents / astexplorer.json
Last active February 15, 2019 16:02 — forked from astexplorer/astexplorer.json
Remove experimental bind syntax from a codebase
{
"v": 2,
"parserID": "babylon7",
"toolID": "jscodeshift",
"settings": {
"babylon7": null
},
"versions": {
"babylon7": "7.3.1",
"jscodeshift": "0.6.3"
@ryaninvents
ryaninvents / .block
Last active November 6, 2017 14:43 — forked from mbostock/.block
View of the World from Florida
license: gpl-3.0