Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# bee - return Spelling Bee words from maximal set
# Andrew Ho <andrew@zeuscat.com>
ME=`basename "$0"`
USAGE="usage: $ME letters middle-letter"
die_usage() { (echo "$ME: $@"; echo "$USAGE") 1>&2; exit 1; }
letters="$1"
[[ -z "$letters" ]] && die_usage 'missing required letters'
@andrewgho
andrewgho / bash_sub.sh
Last active October 27, 2022 17:31
bash in-process string substitution with one capturing group
# Bash parameter expansion syntax for ${parameter/match/replacement}:
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
#
# Bash pattern matching syntax:
# https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
#
# Bash conditional [[ string =~ pattern ]] and $BASH_REMATCH syntax:
# https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html
#
# Recipe to do a string replace with capturing:
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'json'
require 'http-cookie'
module Uck
class Client
attr_reader :baseurl
@andrewgho
andrewgho / unifi_clients.sh
Last active June 21, 2020 05:01
unifi_clients.sh - dump list of clients from UniFi Cloud Key
#!/bin/sh
# unifi_clients.sh - dump list of clients from UniFi Cloud Key
# Andrew Ho (andrew@zeuscat.com)
#
# https://ubntwiki.com/products/software/unifi-controller/api
USERNAME=redacted
PASSWORD=redacted
BASEURL=https://unifi-cloudkey-gen2:8443
@andrewgho
andrewgho / firstboot.sh
Last active June 21, 2020 23:42
firstboot.sh - Raspberry Pi OS (buster) first boot initialization script
#!/bin/sh
# firstboot.sh - Raspberry Pi OS (buster) first boot initialization script
# Andrew Ho (andrew@zeuscat.com)
# Set pi user password
passwd
# Add en_US.UTF-8 locale and set as default
cp /etc/locale.gen locale.gen.orig
sudo sed -i 's/^# \(en_US.UTF-8.*\)$/\1/' /etc/locale.gen
@andrewgho
andrewgho / signal_standalone.md
Last active October 4, 2017 04:27
Build Standalone Signal Desktop App for OS X

Build Standalone Signal Desktop App for OS X

This document describes how to build a standalone (not Chrome app) Signal desktop application for OS X, including packaging up the appropriate icons for the application.

Procedure

Find latest version of the NW.js SDK from http://dl.nwjs.io, then download and unpack it:

@andrewgho
andrewgho / keybase.md
Created February 10, 2017 06:39
Keybase proof

Keybase proof

I hereby claim:

  • I am andrewgho on github.
  • I am andrewgho (https://keybase.io/andrewgho) on keybase.
  • I have a public key whose fingerprint is 9BBA F92A 9768 B022 29E0 AFB0 9765 DF56 02C1 B75F

To claim this, I am signing this object:

@andrewgho
andrewgho / fizzbuzz.c
Created August 4, 2015 06:22
Branchless FizzBuzz
#include <stdio.h>
int main() {
int i, idx, mask[] = {3, 0, 0, 0, 0};
char buf[4], *out[] = {buf, "Fizz", "Buzz", "FizzBuzz"};
for(i = 1; i <= 100; i++) {
sprintf(buf, "%d", i);
idx = (mask[i % 3] & 1) + (mask[i % 5] & 2);
printf("%s\n", out[idx]);
@andrewgho
andrewgho / brew_install_gcc49.txt
Created April 28, 2015 20:08
HOMEBREW_MAKE_JOBS=1 brew install -v gcc49 2>&1
This file has been truncated, but you can view the full file.
==> Installing gcc49 from homebrew/homebrew-versions
==> Downloading http://ftpmirror.gnu.org/gcc/gcc-4.9.2/gcc-4.9.2.tar.bz2
Already downloaded: /Library/Caches/Homebrew/gcc49-4.9.2.tar.bz2
==> Verifying gcc49-4.9.2.tar.bz2 checksum
tar xf /Library/Caches/Homebrew/gcc49-4.9.2.tar.bz2
/* gcc -Wall -Wno-char-subscripts -o is_steal is_steal.c */
#include <stdio.h>
int is_steal(const char *base, const char *steal) {
char count[26] = {0};
int bl, sl;
for(bl = sl = 0; base[bl]; bl++) {
if(count[base[bl]] > 0) {