Skip to content

Instantly share code, notes, and snippets.

View ndbroadbent's full-sized avatar

Nathan Broadbent ndbroadbent

View GitHub Profile
@ndbroadbent
ndbroadbent / rn-i18n-locale-identifiers.csv
Last active April 18, 2024 11:43 — forked from JaseHadd/ioslocaleidentifiers.csv
React Native i18n Locale Identifiers
Locale Identifier Description
af Afrikaans
af-NA Afrikaans (Namibia)
af-ZA Afrikaans (South Africa)
agq Aghem
agq-CM Aghem (Cameroon)
ak Akan
ak-GH Akan (Ghana)
am Amharic
am-ET Amharic (Ethiopia)
@ndbroadbent
ndbroadbent / has_uid.rb
Created November 30, 2017 13:56
UIDs in Rails
module HasUid
extend ActiveSupport::Concern
# Skips characters that look the same, such as 0 and O
UID_CHARS = 'abcdefghjkmnpqrstxyzACDEFGHJKLMNPQRSTXYZ2345679'.split('')
def self.generate_uid(length)
Array.new(length) {
UID_CHARS[SecureRandom.random_number(UID_CHARS.size)]
}.join
@ndbroadbent
ndbroadbent / ha_compile_jinja.service
Last active November 2, 2023 16:36
Script to compile and format *.yaml.jinja files in Home Assistant config directory (Including systemd service)
[Unit]
Description=Compile Jinja templates to YAML in Home Assistant config directory
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=3
ExecStart=/opt/ha_compile_jinja.sh
@ndbroadbent
ndbroadbent / make_links_clickable.js
Created November 14, 2022 04:08
Tampermonkey script: Make CircleCI links clickable
@ndbroadbent
ndbroadbent / circleci_pipeline_status
Last active November 16, 2022 03:08
Scripts to fetch failed CircleCI pipelines and run failing steps locally. Supports RSpec (parallel), RuboCop, Rswag (Swapper API specs), bundle-audit, and shellcheck
#!/bin/bash
set -eo pipefail
CURRENT_DIR="$(realpath "$(dirname "$0")")"
ROOT_DIR="$(realpath "$CURRENT_DIR"/..)"
DEBUG=""
debug() {
if [ "$DEBUG" != "true" ]; then return; fi
echo "[DEBUG] $(date -u +"%Y-%m-%d %H:%M:%S") $*" >&2
}
@ndbroadbent
ndbroadbent / run_failed_gitlab_pipeline_specs.sh
Created November 5, 2022 02:28
Script to fetch the latest failed CI pipeline and run all the failing steps locally (RSpec, Rubocop, etc.)
#!/bin/bash
set -eo pipefail
CURRENT_DIR="$(realpath $(dirname "$0"))"
ROOT_DIR="$(realpath $CURRENT_DIR/..)"
# https://gitlab.com/*********/**********
PROJECT_ID="**********"
if ! [ -f "$ROOT_DIR/.gitlab-api-token" ]; then
echo "Please create a file named .gitlab-api-token in $ROOT_DIR, containing your GitLab API token" >&2
@ndbroadbent
ndbroadbent / MIT_LICENSE
Last active October 30, 2022 05:31
E24 Resistor Pack Ring Binder HTML / CSS
Copyright 2022 Nathan Broadbent. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this PDF document, software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE PDF AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR I
@ndbroadbent
ndbroadbent / rails_helper.rb
Created October 12, 2022 21:20
Configure RSpec to crash on any JS errors or warnings
# Inspired by https://medium.com/@coorasse/catch-javascript-errors-in-your-system-tests-89c2fe6773b1
IGNORED_BROWSER_LOGS = [
'You may test your Stripe.js integration over HTTP. However, live Stripe.js integrations must use HTTPS.',
].freeze
RSpec.configure do |config|
config.after :each, js: true do
errors = page.driver.browser.manage.logs.get(:browser)
next if errors.blank?
@ndbroadbent
ndbroadbent / header_length_enforcer.rb
Created September 29, 2022 08:56
Rack middleware to enforce header length
# frozen_string_literal: true
# Only used during test and development. Ensures we never receive or respond with
# header data that is over 4k.
# See: https://community.convox.com/t/getting-502-bad-gateway-errors-for-one-page-on-v3-rack-app-responds-with-200-and-the-page-works-fine-on-v2-rack/841
module Rack
class HeaderLengthEnforcer
class HeadersTooLargeError < StandardError; end
NGINX_HEADER_LENGTH_LIMIT = 4000
@ndbroadbent
ndbroadbent / .dev.scpt
Last active September 22, 2022 11:46
Using AppleScript to set up iTerm2 tabs and panes for Rails development
# iTerm2 AppleScript Docs: https://www.iterm2.com/documentation-scripting.html
on run argv
set current_dir to item 1 of argv
tell application "iTerm2"
tell current window
set rails_session to current session
set current_tab to current tab
tell current session