Skip to content

Instantly share code, notes, and snippets.

@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
/* 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) {
@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
==> ../configure --build=x86_64-apple-darwin14.3.0 --prefix=/usr/local/Cellar/gcc49/4.9.2_1 --libdir=/usr/local/Cellar/gcc49/4.9.2_1/lib/gcc/4.9 --enable-languages=c,c++,objc,obj-c++ --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp4 --with-mpfr=/usr/local/opt/mpfr2 --with-mpc=/usr/local/opt/libmpc08 --with-cloog=/usr/local/opt/cloog018 --with-isl=/usr/local/opt/isl011 --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion=Homebrew gcc49 4.9.2_1 --with-bugurl=https://github.com/Homebrew/homebrew-versions/issues --enable-plugin --disable-nls --enable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.
#!/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