Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# wordchomp - given set of letters, generate sets of words that use them all
# Andrew Ho (andrew@zeuscat.com)
require 'multimap'
ME = File.basename(__FILE__)
USAGE = "usage: #{ME} letters"
# Given set of letters, generate set partitions, look for matches in dictionary
@andrewgho
andrewgho / wordchomp
Created July 31, 2013 21:50
Given set of letters, generate sets of words that use them all
#!/usr/bin/env ruby
# wordchomp - given set of letters, generate sets of words that use them all
# Andrew Ho (andrew@zeuscat.com)
require 'multimap'
ME = File.basename(__FILE__)
USAGE = "usage: #{ME} letters"
# Given set of letters, generate set partitions, look for matches in dictionary
@andrewgho
andrewgho / git-total-reset
Last active December 20, 2015 18:59
git-total-reset - wipe out any changes, make repo match origin/master
#!/bin/sh
# git-total-reset - wipe out any changes, make repo match origin/master
# Andrew Ho (andrew@zeuscat.com)
git checkout -f master
git stash clear
git fetch
git reset --hard origin/master
git clean -xfd
@andrewgho
andrewgho / demo_subprocess.py
Created February 9, 2014 03:41
Demonstrate Python subprocess polling and termination
#!/usr/bin/env python
# demo_subprocess.py - demonstrate Python subprocess polling and termination
# Andrew Ho (andrew@zeuscat.com)
import os, time, subprocess
sleep_for = 5 # How long in seconds should our test subprocess sleeps
timeout_after = 3 # Send SIGTERM to the subprocess after this many seconds
poll_delay = 0.5 # Sleep this long between polling for subprocess status
@andrewgho
andrewgho / show_poll.py
Last active August 29, 2015 13:56
Show that zombie processes get reaped by poll()
#!/usr/bin/env python
# show_poll.py - show that zombie processes get reaped by poll()
# Andrew Ho (andrew@zeuscat.com)
#
# To test: open two terminals. Run this program in one terminal, cut and
# paste the "ps" command that is printed in the other terminal, and keep
# re-running that ps command (Ctrl+P, Enter). After 5 seconds, the sleep
# subprocess exits and becomes a (sleep) zombie. After another 5 seconds,
# the parent process calls child.poll() and you should see it disappear.
@andrewgho
andrewgho / is_steal_sort.sh
Last active August 29, 2015 13:56
is_steal_sort.sh - return true for GrabScrab steal (via letter sorting)
#!/bin/sh
# is_steal_sort.sh - return true for GrabScrab steal (via letter sorting)
# Andrew Ho (andrew@zeuscat.com)
#
# Given two words, exits with zero return status if the second word is a
# GrabScrab steal for the first (see <http://grabscrab.com>).
#
# This solution counts letters and compares the letter counts, with best
# case O(n*log(n)) performance, where n is total letter count.
@andrewgho
andrewgho / is_steal_count.sh
Last active August 29, 2015 13:56
is_steal_count.sh - return true for GrabScrab steal (via letter counting)
#!/bin/sh
# is_steal_count.sh - return true for GrabScrab steal (via letter counting)
# Andrew Ho (andrew@zeuscat.com)
#
# Given two words, exits with zero return status if the second word is a
# GrabScrab steal for the first (see <http://grabscrab.com>).
#
# This solution counts letters and compares the letter counts, with best
# case linear performance, by total letter count.
@andrewgho
andrewgho / gist:11237678
Last active August 29, 2015 14:00
Search for a pattern, displaying last modification time

Search for a pattern, displaying last modification time

Problem

Use grep to search for a pattern in a set of files, but in the output, display the last modification time (mtime) of each file along with the matching line.

Solution

@andrewgho
andrewgho / sphinx.rb
Last active August 29, 2015 14:06 — forked from pcorliss/sphinx.rb
# Original: https://gist.githubusercontent.com/pcorliss/5628491/raw/eccb38d840734854dd5a10b25e7d52b71612f0d7/sphinx.rb
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
@andrewgho
andrewgho / bar.md
Last active August 29, 2015 14:06
Bar Equipment List