Skip to content

Instantly share code, notes, and snippets.

View apg's full-sized avatar
🐢
Turtle

Andrew Gwozdziewycz apg

🐢
Turtle
View GitHub Profile
@apg
apg / gist:657226
Created October 31, 2010 22:09 — forked from lancepantz/gist:654709
# I use this on Linux:
#!/bin/bash
# e - launch emacsclient or server.
ps ax | grep "emacs --daemon" | grep -v "grep"
if [ "$?" -eq "1" ]
then
/usr/bin/emacs --daemon
fi
@apg
apg / mastermind.c
Created December 10, 2010 19:36
A console mastermind game.
/**
* guessit
* Itty-bitty mastermind type game.
*
* OBJECT:
*
* The object of the game is to guess what the computer has choosen.
*
* The computer starts out by randomly selecting a number of symbols. Your job
* is to figure out what the symbols are. You have a limited number of
@apg
apg / passadd.sh
Created December 23, 2010 17:13
add a password to a GPG password encrypted "database"
#!/bin/bash
# passadd
if [ -z "$PASSFILE" ]
then
echo "PASSFILE doesn't exist"
exit 1
fi
if [ $# -ne 1 ]
@apg
apg / gist:769825
Created January 7, 2011 17:49
qsort
(defn qsort
[[x & r]]
(let [xs #(for [y r :when (% y x)] y)]
(when x
(concat (qsort (xs <=)) [x] (qsort (xs >))))))
@apg
apg / something-like-generators.scm
Created January 28, 2011 00:10
deriving something that could be generators, but I didn't feel like returning values.
;; Deriving something like generators, but I didn't really feel like doing that exactly.
;; This applys a function across a range from 0 to x.
(define (apply-to-range f x)
(let loop ((i 0))
(if (< i x)
(begin
(f i)
(loop (+ 1 i))))))
@apg
apg / generator-ttd.scm
Created January 29, 2011 16:26
generators (like python yield), in scheme, a language that doesn't normally have them.
;; Deriving something like generators, but I didn't really feel like
;; doing exactly that.
;; It doesn't, for instance, support sending back into the generator
;; This applys a function across a range from 0 to x.
(define (apply-to-range f i x)
(when (< i x)
(f i)
(apply-to-range f (+ 1 i) x)))
@apg
apg / functionize.py
Created February 2, 2011 17:03
use google a decorated function as a function in google collections via jython.
try:
from com.google.common.base import Function
except ImportError:
Function = None
class _FunctionTemplate(object):
def __init__(self, f):
self._func = f
def apply(self, *args):
(defmacro match
"shitty pattern matching macro
Example:
(def eval [exp]
(match exp
(:var v) v
(:abstraction arg body) (create-procedure arg body)
(:application operator operand) (operator operand)))
from functools import wraps
def jsonp(view_func):
"""Wrap a json response in a callback, and set the mimetype (Content-Type) header accordingly
(will wrap in text/javascript if there is a callback). If the "callback" or "jsonp" paramters
are provided, will wrap the json output in callback({thejson})
Usage:
@jsonp
@apg
apg / gist:886920
Created March 25, 2011 14:31
quick mirror.
for n in `curl http://www.classes.cs.uchicago.edu/current/22610-1/docs/ | awk '{FS="\">"} {print $3}' | awk '{FS="\""} {print $2}' | egrep "^[a-zA-Z]"`; do wget http://www.classes.cs.uchicago.edu/current/22610-1/docs/$n; done