Skip to content

Instantly share code, notes, and snippets.

View edma2's full-sized avatar

Eugene Ma edma2

  • San Francisco, CA
View GitHub Profile
@edma2
edma2 / test.c
Created December 15, 2010 04:35
blah
int main(void) {
}
@edma2
edma2 / markov.c
Created October 22, 2011 09:13
Markov random text generator (Practice of Programming Exercise 3-2)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
NPREF = 2, /* Number of prefix words */
NHASH = 4093, /* Size of hash table */
MAXGEN = 10000 /* Maximum words generated */
};
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
NPREF = 2, /* Number of prefix words */
NHASH = 4093, /* Size of hash table */
MAXGEN = 10000 /* Maximum words generated */
};
import sys
from random import choice
MAXWORDS = 10000 # Max words to output
NPREF = 2 # Number of prefix words
NONWORD = '\n' # Sentinel word
table = {} # {(p1,p2) : [s1, s2, s3]}
prefix = tuple([NONWORD for i in range(NPREF)])
wordlist = sys.stdin.read().split()
; tee
; Returns non-zero exit code if an error occured
section .bss
buf: resb 1024
buflen equ $-buf
stdin equ 0
stdout equ 1
O_WRONLY equ 1q
O_CREAT equ 100q
@edma2
edma2 / tsort.go
Created March 15, 2012 00:21
Fun with Go: Topological Sort
package main
import "fmt"
/* Graph representation */
type Dag struct {
outgoing_edges map[int][]int
incoming_edges map[int][]int
}
@edma2
edma2 / q13.c
Created March 18, 2012 08:15
Project Euler #13
/*
* Project Euler #13
* Eugene Ma
*
* Real Answer: 5537376230
*/
#include <stdio.h>
#include <string.h>
import copy
import re
class Board(object):
'''
tile
[a-z] placed tile
"_" normal empty square
[2-9] multiplier empty square
'''
;; zipper.scm
;; A binary tree zipper implementation in Scheme
;; Author: Eugene Ma (edma2)
(define (make-tree datum left right)
(list datum left right))
(define datum car)
(define left-child cadr)
(define right-child caddr)
(define (make-leaf datum)
import itertools
import sys
from bottle import route, run, redirect
ALPHANUM = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
def usage():
print 'usage: %s <hostname> <port>'
exit(-1)