Skip to content

Instantly share code, notes, and snippets.

View dz1984's full-sized avatar

Donald Zhan dz1984

View GitHub Profile
@dz1984
dz1984 / fibonacci.go
Created March 23, 2014 07:51
"A Tour of Go"
/*
Exercise: Fibonacci closure
Let's have some fun with functions.
Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers.
*/
package main
import "fmt"
@dz1984
dz1984 / maps.go
Created March 23, 2014 07:04
"A Tour of Go"
/*
Exercise: Maps
Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure.
You might find strings.Fields helpful.
*/
package main
@dz1984
dz1984 / Slices.go
Created March 23, 2014 06:47
"A Tour of Go"
/*
Exercise: Slices
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values.
The choice of image is up to you. Interesting functions include x^y, (x+y)/2, and x*y.
(You need to use a loop to allocate each []uint8 inside the [][]uint8.)
(Use uint8(intValue) to convert between types.)
@dz1984
dz1984 / Vagrantfile
Created March 23, 2014 01:29
My default vagrant setting.
# -*- 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 / Loops&Functions.go
Created March 19, 2014 08:55
"A Tour of Go"
/*
Exercise: Loops and Functions
As a simple way to play with functions and loops, implement the square root function using Newton's method.
In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating:
z= z- ( (z^2 -x) / (2*z) )
To begin with, just repeat that calculation 10 times and see how close you get to the answer for various values (1, 2, 3, ...).
@dz1984
dz1984 / CreateLink.bat
Created February 26, 2014 05:00
使用 Symbolic link方式,讓source code與Web Server可以IoC (Inversion of control)。
@dz1984
dz1984 / LoggerHelper.php
Last active August 29, 2015 13:56
Tiny Log helper.
<?php
/**
* Log helper functions
*
* This class can log error messages to a file or the console.
*
* It can take an error message and format it to include the date and the severity level.
*
* The message can be appended to a file or outputted to the console if the severity level is above the minimum severity threshold.

EditorConfig

如何安裝

Clone Eitorcongi-Vim回來,並複制到 ~/.vim 即完成。

$ git clone https://github.com/editorconfig/editorconfig-vim.git

$ cd editorconfig-vim &amp; cp -r doc/ autoload/ plugin/ ~/.vim
@dz1984
dz1984 / sortRoadName.php
Last active January 3, 2016 20:39
依照同路名不同段號排序。 http://ideone.com/AiRm6m
<?php
$rd_list = array('中山北路一段','承德路九段','中山北路五段','承德路三段','中山北路六段','承德路二段','中山北路四段','中山北路七段');
usort($rd_list,function($a,$b){
$pattern = '/(.*?)([一二三四五六七八九])段/u';
$num = array('一','二','三','四','五','六','七','八','九');
if (preg_match($pattern,$a,$matches_a) && preg_match($pattern,$b,$matches_b)){
if ($matches_a[1] == $matches_b[1]){
return array_search($matches_a[2],$num)-array_search($matches_b[2],$num);
}