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
"""
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
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.