Skip to content

Instantly share code, notes, and snippets.

@hcgatewood
hcgatewood / hash_table.rb
Last active December 23, 2019 08:23
An associative array in Ruby
#!/usr/bin/env ruby
# A simple hash table implementation in Ruby using Ruby's built-in
# prehashing methods, chaining, and variable load factors.
#
# Author:: Hunter Gatewood
# A linked-list node with key, value, and next node attributes.
class Node
attr_accessor(:key, :val, :next_node)
@hcgatewood
hcgatewood / random_note.py
Last active July 25, 2024 23:33
Print a random note at the passed interval, defaulting to every 4 seconds
#!/usr/bin/env python3
"""
random_note.py prints a random musical note at the passed interval (seconds).
If no interval passed, defaults 4 seconds.
"""
import itertools
import random
@hcgatewood
hcgatewood / play_notes.py
Last active February 25, 2025 08:25
Send a series of notes to a Twitch channel
"""
Read in notes from the passed notes.json file and send to our Twitch channel.
Usage: `python3 play_notes.py <your notes.json file>`
Notes:
- Careful about getting rate limited! The limits per 30 seconds
are 30 messages for non-mods and 100 messages for mods. Pass that
limit and your IP gets banned for 8 hours. See
https://help.twitch.tv/customer/portal/articles/1302780-twitch-irc.
- Expects fields in notes.json to be filled out (pass, nick, notes).
@hcgatewood
hcgatewood / how_to_be_miserable.md
Last active July 25, 2024 23:27
Checklist of strategies from Randy Paterson's How to Be Miserable: 40 Strategies You Already Use

Adopting a miserable lifestyle

  • 1. Avoid all exercise
  • 2. Eat what you're told
  • 3. Don't waste your life in bed
  • 4. Live better through chemistry
  • 5. Maximize your screen time
  • 6. If you want it, buy it
  • 7. Can't afford it? Get it anyway!
  • 8. Give 100 percent to your work
@hcgatewood
hcgatewood / twilio_dropbox_function.js
Last active February 25, 2025 08:25
Create a Dropbox file with contents from a Twilio-forwarded SMS
const isoFetch = require('isomorphic-fetch');
const Dropbox = require('dropbox').Dropbox;
const util = require('util');
exports.handler = function(context, event, callback) {
log(context);
log(event);
const whitelisted_numbers = [
context.HCG_NUM_1,
@hcgatewood
hcgatewood / nut.md
Created July 27, 2024 02:49
Configure NUT on macOS

Configure NUT on macOS

Quick overview of installing Network UPS Tools on macOS.

macOS notes

  • Config files are located in their normal Linux-style locations, with the brew --prefix prepended. So e.g., on Apple silicon, nut.conf is located at /opt/homebrew/etc/nut/nut.conf.
  • NUT's Homebrew service should be run as root, to support default shutdown command.
  • While desktop macOS supports "wake after power loss", it doesn't seem to support "wake on power". It treats the graceful shutdown as a normal shutdown, which doesn't result in startup after power restore. Can either accept manual power-on required, or remove graceful shutdown.
@hcgatewood
hcgatewood / vpn_login.bash
Last active February 25, 2025 08:26
Log in to Palo Alto Networks GlobalProtect VPN
# vpnon connects to GlobalProtect VPN.
#
# NOTE: GlobalProtect must be running.
#
# REF: https://gist.github.com/kaleksandrov/3cfee92845a403da995e7e44ba771183
#
# Usage: vpnon
function vpnon {
osascript <<EOF
tell application "System Events" to tell process "GlobalProtect"
@hcgatewood
hcgatewood / kuma_cloudflare.md
Last active April 10, 2025 03:48
Protect Uptime Kuma with Cloudflare Tunnel and Access

Uptime Kuma via Cloudflare Tunnel

This guide outlines steps to access Uptime Kuma through a semi-protected Cloudflare Tunnel.

Semi-protected meaning the status page is public, while all other endpoints are private.

Step 0: deploy Uptime Kuma

Consider e.g. Fly.io (repo) (howto).

@hcgatewood
hcgatewood / chrome_dialer.md
Last active April 10, 2025 03:32
Open Chrome bookmarks with hotkeys

Open Chrome Bookmarks with Keyboard Shortcuts

This guide outlines steps to create a custom dialer for Google Chrome on macOS, i.e. opening specific URLs with simple keyboard shortcuts.

The goal is to recreate Safari's affordance of ⌘1 opening your 1st bookmark, ⌘2 opening your 2nd bookmark, etc.

Prerequisites

  1. Install BetterTouchTool
@hcgatewood
hcgatewood / questions.py
Created April 1, 2025 02:38
Interview questions
# Sort airline tickets
#
# An "airline ticket" is defined as a tuple containing the departure airport code and arrival airport code.
# For example: ("SFO", "LAX") is a trip from SFO to LAX.
# A "legal trip" is a trip that uses all of the airline tickets, where
# the arrival airport for a ticket must be same as the departure airport for the next ticket.
#
# Example
# Input: [("SFO", "LAX"), ("LAX", "NYC"), ("ORD", "SFO")]
# Output: [("ORD", "SFO"), ("SFO", "LAX"), ("LAX", "NYC")]