Skip to content

Instantly share code, notes, and snippets.

View dz1984's full-sized avatar

Donald Zhan dz1984

View GitHub Profile
@dz1984
dz1984 / EIA.md
Created May 14, 2014 09:49
收集製作環境影響評估公民版-從環評看土地變更專案會用到的資源
@dz1984
dz1984 / Vagrantfile
Last active August 29, 2015 14:00
eia_crawler dev env.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
@dz1984
dz1984 / utils.go
Created March 25, 2014 06:22
Utility Functions with Golang.
package utils
import (
"bufio"
"fmt"
"io/ioutil"
"os"
)
func IsExists(path string) bool {
@dz1984
dz1984 / WebCrawler.go
Created March 23, 2014 13:54
"A Tour of Go"
/*
Exercise: Web Crawler
In this exercise you'll use Go's concurrency features to parallelize a web crawler.
Modify the Crawl function to fetch URLs in parallel without fetching the same URL twice.
*/
package main
@dz1984
dz1984 / EequivalentBinaryTrees
Created March 23, 2014 10:30
"A Tour of Go"
/*
Exercise: Equivalent Binary Trees
1. Implement the Walk function.
2. Test the Walk function.
The function tree.New(k) constructs a randomly-structured binary tree holding the values k, 2k, 3k, ..., 10k.
Create a new channel ch and kick off the walker:
@dz1984
dz1984 / Rot13Reader.go
Created March 23, 2014 09:37
"A Tour of Go"
/*
Exercise: Rot13 Reader
A common pattern is an io.Reader that wraps another io.Reader, modifying the stream in some way.
For example, the gzip.NewReader function takes an io.Reader (a stream of gzipped data) and returns a *gzip.Reader that also implements io.Reader (a stream of the decompressed data).
Implement a rot13Reader that implements io.Reader and reads from an io.Reader, modifying the stream by applying the ROT13 substitution cipher to all alphabetical characters.
The rot13Reader type is provided for you. Make it an io.Reader by implementing its Read method.
@dz1984
dz1984 / Images.go
Created March 23, 2014 09:14
"A Tour of Go"
/*
Exercise: Images
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data.
Define your own Image type, implement the necessary methods, and call pic.ShowImage.
Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h).
ColorModel should return color.RGBAModel.
@dz1984
dz1984 / HTTPHandlers.go
Created March 23, 2014 08:56
"A Tour of Go"
/*
Exercise: HTTP Handlers
Implement the following types and define ServeHTTP methods on them. Register them to handle specific paths in your web server.
type String string
type Struct struct {
Greeting string
Punct string
@dz1984
dz1984 / Errors.go
Created March 23, 2014 08:39
"A Tour of Go"
/*
Exercise: Errors
Copy your Sqrt function from the earlier exercises and modify it to return an error value.
Sqrt should return a non-nil error value when given a negative number, as it doesn't support complex numbers.
Create a new type
type ErrNegativeSqrt float64
@dz1984
dz1984 / ComplexCubeRoots.go
Created March 23, 2014 08:20
"A Tour of Go"
/*
Advanced Exercise: Complex cube roots
Let's explore Go's built-in support for complex numbers via the complex64 and complex128 types. For cube roots, Newton's method amounts to repeating:
Find the cube root of 2, just to make sure the algorithm works. There is a Pow function in the math/cmplx package.
*/
package main