資料來源:http://blog.ponyfoo.com/2014/01/20/how-to-design-great-programs
- 做好一件事
- 提供良好API介面
- ```README``導向開發
- Open Source
- 撰寫測試
/* | |
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" |
/* | |
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 |
/* | |
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.) |
# -*- 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 |
/* | |
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, ...). |
@ECHO off | |
REM setting the source and target folder path. | |
SET target=C:\wamp\www\ | |
SET source=C:\Projects\ | |
ECHO Target folder: %target% | |
ECHO Source folder: %source% | |
CD %target% | |
REM only catch the folder name | |
FOR /f %%i IN ('dir /B /AD %source%') DO mklink /D "%%i" "%source%%%i" |
<?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. |
資料來源:http://blog.ponyfoo.com/2014/01/20/how-to-design-great-programs
<?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); | |
} |