Skip to content

Instantly share code, notes, and snippets.

View ndbroadbent's full-sized avatar

Nathan Broadbent ndbroadbent

View GitHub Profile
@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 / 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 / karabiner-elements-enter-fnfn.json
Last active September 8, 2022 23:19
Karabiner-Elements rule - Double press keypad_enter to press Fn twice and start dictation
{
"title": "Double tap keypad_enter to double tap fn (start dictation.) Single tap for keypad_enter after a short delay (250ms.)",
"rules": [
{
"description": "This rule solves a problem with the Microsoft Surface Ergonomic Keyboard. The `Fn` key can't be used to start dictation, since it only toggles an internal state on and off, and it does not actually send any keypress event. This rule allows you to start dictation by double tapping the keypad enter key, which will send Fn twice. If you only press the keypad enter key once, it will send the original enter key after a short delay (250ms).",
"manipulators": [
{
"conditions": [
{
"name": "keypad_enter pressed",
@ndbroadbent
ndbroadbent / rangehood.yaml
Created September 6, 2022 23:51
Rangehood ESP32 Controller - ESPHome Configuration
esphome:
name: rangehood
includes:
- rangehood_button_leds.h
esp32:
board: nodemcu-32s
framework:
type: arduino
@ndbroadbent
ndbroadbent / run_failed_gitlab_pipeline_specs.sh
Created April 4, 2022 02:55
run_failed_gitlab_pipeline_specs
#!/bin/bash
set -eo pipefail
CURRENT_DIR="$(realpath $(dirname "$0"))"
ROOT_DIR="$(realpath $CURRENT_DIR/..)"
# https://gitlab.com/docspring/docspring
PROJECT_ID="1908805"
GITLAB_TOKEN=$(cat $ROOT_DIR/.gitlab-api-token)
@ndbroadbent
ndbroadbent / gpt3-hangman.txt
Last active April 11, 2021 05:49
Some test GPT-3 training data for the hangman game
Hint: This person is an actor.
____ ____
=> e
There were no e's!
- Guesses: e
____ ____
=> t
There were 2 t's!
@ndbroadbent
ndbroadbent / create_combined_submission.deluge.js
Last active February 20, 2021 22:49
DocSpring + Zoho CRM - Examples for creating Submissions and Combined Submissions, and poll for status until they are processed
// Used for loop that waits for pending jobs to be processed.
LoopList={"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"};
templateID = "<TEMPLATE ID>";
apiTokenId = "<API TOKEN ID>";
apiTokenSecret = "<API TOKEN SECRET>";
base64EncodedLogin = zoho.encryption.base64Encode(apiTokenId + ":" + apiTokenSecret);
@ndbroadbent
ndbroadbent / run_failed_gitlab_pipeline_specs.sh
Last active October 3, 2020 10:59
Find all the failed RSpec examples in GitLab CI pipeline logs and run them all locally
#!/bin/bash
set -eo pipefail
CURRENT_DIR="$(realpath $(dirname "$0"))"
ROOT_DIR="$(realpath $CURRENT_DIR/..)"
# https://gitlab.com/docspring/docspring
PROJECT_ID="1908805"
GITLAB_TOKEN=$(cat $ROOT_DIR/.gitlab-api-token)
@ndbroadbent
ndbroadbent / freeze_for_2s.txt
Created June 6, 2020 11:16
Minimal examples that freeze VS Code with a regex search
# VS Code freezes for 1-2 seconds with regex search "([^]+\n)+"
# foo foo foo foo
foo(foo).foo foo 'foo'
foo(foo).foo foo 'foo'
foo(foo(
'foo.foo.foo-foo-foo .foo-foo-foo'
).foo).foo foo('foo foo')
foo(foo).foo foo 'foo foo'
@ndbroadbent
ndbroadbent / system.rake
Created June 1, 2020 12:04
Check for Debian updates
namespace :system do
desc 'Check for security updates for Debian packages'
task check_security_updates: :environment do
return unless Rails.env.production?
Cronitor.run(ENV['CRONITOR_ID_CHECK_SECURITY_UPDATES']) do
stdout, stderr, status = Open3.capture3('apt-get update')
unless status.success?
raise "'apt-get update' failed! stdout:\n#{stdout}\nstderr:\n#{stderr}"