Skip to content

Instantly share code, notes, and snippets.

@gigamonkey
gigamonkey / keybase.md
Created March 22, 2014 21:59
Verifying my identity for keybase.io

Keybase proof

I hereby claim:

  • I am gigamonkey on github.
  • I am peterseibel (https://keybase.io/peterseibel) on keybase.
  • I have a public key whose fingerprint is 54F4 4A67 9127 A7FB 5398 B1E1 B4A6 DD7D 735E 60D3

To claim this, I am signing this object:

@gigamonkey
gigamonkey / lisp.py
Created October 22, 2014 21:29
Half implemented (or less) lisp interpreter
#!/usr/bin/env python3
# Reader -- parses text to something, some structure.
# Python lists for lists.
# Instances of Symbol for symbols.
# Numbers for numbers.
# Strings for strings.
# ??? for functions
@gigamonkey
gigamonkey / Foo.java
Created December 29, 2014 17:30
YYYY vs yyyy
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.GregorianCalendar;
public class Foo {
public static void main(String[] argv) {
TimeZone utc = TimeZone.getTimeZone("UTC");
@gigamonkey
gigamonkey / word-search.hs
Last active August 29, 2015 14:17
Word search solver
import Data.Array
import Data.Maybe
import Data.List.Split
import System.Environment
import System.IO
direction "n" = \(r, c) -> (r - 1, c)
direction "s" = \(r, c) -> (r + 1, c)
direction "e" = \(r, c) -> (r, c + 1)
direction "w" = \(r, c) -> (r, c - 1)
@gigamonkey
gigamonkey / 01_hundreds.hs
Last active August 29, 2015 14:20
My solution to problem #5 of five problems that every “real programmer” should be able to do except the guy who posted them screwed up #4 himself.
-- Problem statement:
-- Write a program that outputs all possibilities to put + or - or nothing between the
-- numbers 1, 2, ..., 9 (in this order) such that the result is always 100.
-- For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
data Item = Plus | Minus | Num Int deriving (Show)
hundreds = filter ((100 ==) . eval) $ map combineAdjacent $ combos [1..9]
-- Generate all combos of digits 1-9 with +, -, or nothing in between.
@gigamonkey
gigamonkey / gist:03efdb275e487da37c59
Last active August 29, 2015 14:22
How to collaborate on technical problems

“[A] good problem description had to satisfy everyone. If two people saw a problem from a different point of view, both people’s points of view were merged into the problem description, making the problem more complicated, and making solutions sometimes harder to achieve. But this was essential to addressing porting problems, for example. One couldn’t just solve how a file system operation would work on one operating system unless the solution was going to work on other operating systems, too. On the other hand, the “proposal” field was very different. If two people disagreed on a proposal, they each wrote their own proposal so that proposals could be internally consistent and coherent. This meant that a single problem often had several proposed solutions with different costs and benefits, and the committee had to decide which was the stronger proposal.”

From http://www.nhplace.com/kent/Papers/cl-untold-story.html

@gigamonkey
gigamonkey / easy.txt
Last active September 23, 2015 05:08
My first Haskell program -- it didn't work the first time it type checked but I got it there. Simple Sudoku solver based on the search part of Peter Norvig's essay about solving every Sudoku.
. 5 . | . . 1 | 4 7 9
. . 2 | 7 . . | . . 8
. . . | . 4 6 | 2 . .
------+-------+------
. 4 6 | . . 9 | 5 3 7
. . . | . 6 . | . . .
8 9 3 | 5 . . | 6 4 .
------+-------+------
. . 9 | 6 1 . | . . .
1 . . | . . 2 | 3 . .
@gigamonkey
gigamonkey / oranges.py
Created June 2, 2011 21:25
My solution to @bramcohen's coding puzzle from a week or two ago
#!/usr/bin/env python3
# Two solutions to http://www.bittorrent.com/company/about/developer_challenge
from itertools import combinations
bowls = 40
oranges = 9
def brute_force():
@gigamonkey
gigamonkey / test.js
Created June 8, 2011 01:34
Now working jQuery/Javascript
// #notes is DIV with overflow: scroll and currentParagraph is an element within that DIV.
// I'm trying to arrange things so that currentParagraph appears at the top of the DIV.
// The trick seems to be to set position: absolute on #notes so it will be the
// offsetParent of its elements and then to scroll like this:
$('#notes').scrollTop($('#notes').scrollTop() + $(currentParagraph).position().top);
@gigamonkey
gigamonkey / fpc.lisp
Created April 9, 2012 18:58
FPC experiments
(defun random-population (size p)
(loop repeat size collect (< (random 1d0) p)))
(defun population (size p)
(let ((pop (make-array size :initial-element nil)))
(loop for i below (round (* size p))
do (setf (aref pop i) t))
pop))
(defun p (population)