Skip to content

Instantly share code, notes, and snippets.

UIBarButtonItem *barButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleDone target:textField action:@selector(resignFirstResponder)] autorelease];
UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
toolbar.items = [NSArray arrayWithObject:barButton];
textField.inputAccessoryView = toolbar;
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
@yuanmai
yuanmai / select-cc.sh
Created October 2, 2013 16:30
select cc
sudo unlink /usr/bin/cc
sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/cc
sudo unlink /usr/bin/cc
sudo ln -s /usr/bin/clang /usr/bin/cc

第一轮Kata回顾

为何不采用自上而下的方法来做设计?

浮现设计可以自上而下,也可以[自下而上][1]。自上而下可以很好地避免过度设计,但根据我[过往][2]的[经验][3],这样提取的函数往往在概念上不够清晰。我在解罗马数字时也是先从个位数开始,而当我做到十位数时,我发现,这里存在两个子问题一个是数码转换,另一个是digits的拆分,这样的问题分解也不需要预先设计的。

我这里另一个尝试是编写正交的测试,我把要解的问题划分为[无关][4]的子问题,而且每组测试之间也没有什么联系。而自上而下设计能够提取函数,但测试是很难再拆成正交的了。这样就很容易导致score测试里面也去测spare的逻辑,to-roman测试又要覆盖digits的逻辑,这就造成最终的测试数量不必要的多和不够正交。在实际项目中,这样的测试维护成本就会高。

新的尝试和值得继续探讨的

(ns bowling_kata.core
(:use midje.sweet))
(defn strike [x & xs]
(when (= x 10)
[[10 (first xs) (second xs)] xs]))
(defn spare [x y & xs]
(when (= 10 (+ x y))
[[x y (first xs)] xs]))
@yuanmai
yuanmai / refactoring.clj
Last active December 17, 2015 15:59
Turn let into defn
(defmacro defletn [name & body]
(let [args (->> body
last
second
(apply array-map)
keys
vec)]
`(defn ~name
~@(butlast body)
~args
@yuanmai
yuanmai / gist:5538917
Created May 8, 2013 07:55
Speed up git tf
git config core.sparseCheckout true
cat .git/info/sparse-checkout
/*
!foo/bar/
cat .git/info/exclude
foo/bar/*
cd foo
git tf clone http://tfsclient $/Repo/foo/bar
@yuanmai
yuanmai / gist:5472682
Created April 27, 2013 10:56
binding dynamic var
user> (def ^:dynamic *foo* nil)
#'user/*foo*
user> *foo*
nil
user> (defn f [] *foo*)
#'user/f
user> (f)
nil
user> (binding [*foo* 1] (f))
1