Skip to content

Instantly share code, notes, and snippets.

View fanzeyi's full-sized avatar

Zeyi (Rice) Fan fanzeyi

View GitHub Profile
@fanzeyi
fanzeyi / crawler.go
Created September 29, 2012 17:32
My solution for `Exercise: Web Crawler`
package main
import "fmt"
var visited = map[string]bool {
}
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
#include <stdio.h>
inline int fibonacci(n, x1, x2) {
if (n == 0) {
return x1;
}
return fibonacci(n - 1, x2, x1 + x2);
}
int main() {
@fanzeyi
fanzeyi / tree.go
Created September 27, 2012 19:19
My answser for `A Tour of Go` Part III
package main
import "fmt"
import "code.google.com/p/go-tour/tree"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
_walk(t, ch)
close(ch)
@fanzeyi
fanzeyi / error.go
Created September 27, 2012 17:40
My answser for `A Tour of Go` Part II
package main
import "fmt"
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %v", float64(e))
}
@fanzeyi
fanzeyi / cbrt.go
Created September 27, 2012 15:45
My answer for `The Tour of Go`
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128) complex128 {
z := x / 4
for i := 0; i < 10; i++ {
z = z - (cmplx.Pow(z, 3) - x) / (3 * z * z)
}
# -*- coding: utf-8 -*-
import os
import time
from sh import xte
CACHE_FILE = "/tmp/zeray.cache"
SINGLE_OFFSET = 16
class Xte(object):
@fanzeyi
fanzeyi / gist:3766633
Created September 22, 2012 16:08
Zeray pathed pppoeconf script for archlinux
#!/bin/sh
# (c) Eduard Bloch <blade@debian.org>, Gregory Colpart <reg@evolix.fr>
# LICENSE: GPL
# Purpose: initial PPPoE configuration on Debian
# Depends: ppp, whiptail, gettext, sed
export TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAIN=pppoeconf
export OPTSFILE="/etc/ppp/peers/dsl-provider"
export REALINTFILE="/etc/network/interfaces"
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define fin stdin
#define fout stdout
#define MAX_CARD 102
#define MAX_WEIGHT 100002
int n;
int weight;
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define MAX_ITEM 62
#define MAX_MONEY 32002
int n;
int money;
int cost[MAX_ITEM];
int value[MAX_ITEM];
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define MAX_CASTLE 102
#define MAX_HEIGHT 10002
#define fin stdin
#define fout stdout
int n;
int min_height = 0x7FFFFFFF;