Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Hunt huntie

View GitHub Profile
@huntie
huntie / start-or-reattach-tmux.sh
Created Nov 28, 2020
Start a tmux server if none exists, create a new session if tmux is in use, or reattach if no tmux sessions are connected - and exit after. Useful as the initial command for a terminal profile.
View start-or-reattach-tmux.sh
tmux ls | grep attached > /dev/null && tmux || tmux attach || tmux; exit
@huntie
huntie / yarn_licences_md_table.sh
Last active Jun 16, 2021 — forked from Radagaisus/ThirdPartyNoticesExample.md
Script to generate a Markdown table from `yarn licenses list`
View yarn_licences_md_table.sh
#!/bin/sh
# Output a dependencies.md file with a table of installed Yarn dependencies
# Requires csvkit, jq
# https://csvkit.readthedocs.io/en/0.9.1/install.html
# https://stedolan.github.io/jq/download/
yarn licenses list --json \
| jq --slurp 'map(select(.type == "table"))' \
@huntie
huntie / aws-environment-concepts.md
Last active Jul 1, 2020
Notes outlining concepts for scoping and referring to environments in cloud applications. To accurately answer, "What is an environment?".
View aws-environment-concepts.md

AWS environment concepts

Notes outlining concepts for scoping and referring to environments in cloud applications. To accurately answer, "What is an environment?".

Environment type

e.g. dev or prod

The application environment classification. This defines what external environments/services the app should be configured against, and therefore the people and resources who should have access.

@huntie
huntie / metro.config.js
Last active Jun 30, 2022
Snippets accompanying my article "A concise guide to configuring React Native with Yarn Workspaces" on Medium
View metro.config.js
/**
* Metro Bundler configuration
* https://facebook.github.io/metro/docs/en/configuration
*
* eslint-env node, es6
*/
const exclusionList = require('metro-config/src/defaults/exclusionList');
const getWorkspaces = require('get-yarn-workspaces');
const path = require('path');
@huntie
huntie / git-log-changed-files.sh
Created Jul 8, 2019
List on individual lines the file paths changed since a given Git revision
View git-log-changed-files.sh
git log origin/master.. --name-only --pretty=format:
@huntie
huntie / webpack.config.js
Last active Mar 25, 2019
Load environment settings in a JavaScript project from a base .env and optional .env.<build-mode> file, using dotenv.parse (no side-effects)
View webpack.config.js
const dotenv = require('dotenv');
const fs = require('fs');
const { flowRight, partial, unary } = require('lodash');
const path = require('path');
/**
* Load the environment settings for the current mode from `.env.{mode}` merged
* with any private entries defined in `.env` if present.
*
* @param {string} mode
@huntie
huntie / graphqlresource.py
Last active Oct 7, 2018
Implementation of a GraphQL HTTP server for Graphene as a Falcon API resource
View graphqlresource.py
import falcon
from typing import Tuple
import ujson
from .graphql import schema
class GraphQLNoQueryResolved(falcon.HTTPBadRequest):
"""
An exception indicating that a GraphQL query could not be resolved from the
incoming request. This will create an HTTP 400 response when raised.
"""
@huntie
huntie / unpack_module.py
Created May 31, 2018
A small reflection utility to access public module members as a dict
View unpack_module.py
def unpack_module(module) -> dict:
"""
Return the members of an imported package or module explicitly exported
using __all__.
"""
return {k: module.__dict__[k] for k in module.__dict__.get('__all__', [])}
@huntie
huntie / certbot.md
Last active Mar 1, 2018
Issue and automate renewal of SSL certificates with Let's Encrypt using Certbot
View certbot.md

Install Certbot and register Let's Encrypt account:

add-apt-repository ppa:certbot/certbot
apt update
apt install certbot
certbot register

Issue new SSL certificates for each host:

certbot certonly --webroot -w /var/www/alexhunt.io/ -d alexhunt.io -d www.alexhunt.io

@huntie
huntie / dsa-query-selector.js
Last active Jan 3, 2022
A simplified implementation of `document.querySelector()` and `document.querySelectorAll()`, during a workshop on data structures.
View dsa-query-selector.js
/**
* Run a callback over all children of a given element using depth-first
* traversal.
*
* @param {HTMLElement} element
* @param {Function} callback
*/
function iterateDOM(element, callback) {
const nodes = [];