├── README.md
├── cheetsheet
├── emacs-cheatsheet.png
└── regrex-cheatsheet.pdf
├── emacs
└── README.md
├── java
├── README.md
└── algorithm
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ └── org.eclipse.core.resources.prefs
│ ├── bin
│ ├── .DS_Store
│ └── com
│ │ └── xiachufang
│ │ ├── AllTests.class
│ │ ├── BestRoute.class
│ │ ├── Client.class
│ │ ├── Dijkstra.class
│ │ ├── HeapSorting.class
│ │ ├── Levenshtein.class
│ │ ├── LevenshteinTest.class
│ │ ├── SortingAlgorithm.class
│ │ └── Unit.class
│ └── src
│ ├── .DS_Store
│ └── com
│ └── xiachufang
│ ├── AllTests.java
│ ├── BestRoute.java
│ ├── Client.java
│ ├── Dijkstra.java
│ ├── HeapSorting.java
│ ├── Levenshtein.java
│ ├── LevenshteinTest.java
│ ├── SortingAlgorithm.java
│ └── Unit.java
├── javascript
├── .DS_Store
└── levenshtein
│ ├── .DS_Store
│ ├── levenshtein.js
│ └── qunit.html
├── objc
├── .DS_Store
├── HelloObjc
│ ├── HelloObjc.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcuserdata
│ │ │ │ └── march.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── march.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── HelloObjc.xcscheme
│ │ │ └── xcschememanagement.plist
│ └── HelloObjc
│ │ ├── HelloObjc-Prefix.pch
│ │ ├── HelloObjc.1
│ │ └── main.m
├── KVCTest
│ ├── .DS_Store
│ ├── KTData.h
│ ├── KTData.m
│ ├── KTObserver.h
│ ├── KTObserver.m
│ ├── KTValue.h
│ ├── KTValue.m
│ ├── KVCTest.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcuserdata
│ │ │ │ └── march.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── march.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── KVCTest.xcscheme
│ │ │ └── xcschememanagement.plist
│ └── KVCTest
│ │ ├── KVCTest-Prefix.pch
│ │ ├── KVCTest.1
│ │ └── main.m
├── LevenshteinDistance
│ ├── LevenshteinDistance.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcuserdata
│ │ │ │ └── march.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── march.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── LevenshteinDistance.xcscheme
│ │ │ └── xcschememanagement.plist
│ └── LevenshteinDistance
│ │ ├── LevenshteinDistance-Prefix.pch
│ │ ├── LevenshteinDistance.1
│ │ ├── XcfLevenshteinDitstance.h
│ │ ├── XcfLevenshteinDitstance.m
│ │ └── main.m
├── README.md
├── SnapNotes
│ ├── SnapNotes.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcuserdata
│ │ │ │ └── march.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcuserdata
│ │ │ └── march.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── SnapNotes.xcscheme
│ │ │ └── xcschememanagement.plist
│ ├── SnapNotes
│ │ ├── .DS_Store
│ │ ├── NotesLine.h
│ │ ├── NotesLine.m
│ │ ├── NotesTableView.h
│ │ ├── NotesTableView.m
│ │ ├── SnapNotes-Info.plist
│ │ ├── SnapNotes-Prefix.pch
│ │ ├── SnapNotes.xcdatamodeld
│ │ │ ├── .xccurrentversion
│ │ │ └── SnapNotes.xcdatamodel
│ │ │ │ └── contents
│ │ ├── XcfAppDelegate.h
│ │ ├── XcfAppDelegate.m
│ │ ├── en.lproj
│ │ │ └── InfoPlist.strings
│ │ └── main.m
│ └── SnapNotesTests
│ │ ├── SnapNotesTests-Info.plist
│ │ ├── SnapNotesTests.h
│ │ ├── SnapNotesTests.m
│ │ └── en.lproj
│ │ └── InfoPlist.strings
├── SortUsingDescriptors.md
├── first
│ ├── .DS_Store
│ └── slide
│ │ ├── .#Untitled
│ │ ├── .DS_Store
│ │ ├── Untitled
│ │ ├── images
│ │ ├── .DS_Store
│ │ ├── iPad.png
│ │ ├── iPhone.png
│ │ ├── iPod.png
│ │ ├── iossoft.jpg
│ │ ├── mac.png
│ │ └── macsoft.png
│ │ ├── xcodeTutorial.aux
│ │ ├── xcodeTutorial.log
│ │ ├── xcodeTutorial.nav
│ │ ├── xcodeTutorial.out
│ │ ├── xcodeTutorial.pdf
│ │ ├── xcodeTutorial.rel
│ │ ├── xcodeTutorial.snm
│ │ ├── xcodeTutorial.tex
│ │ └── xcodeTutorial.toc
├── hello
├── hello.m
├── helloObjc.m
├── helloObject
├── mainmenu
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── AppDelegate.plist
│ ├── Info.plist
│ ├── MainMenu.h
│ ├── MainMenu.m
│ ├── MainMenu.plist
│ ├── Makefile
│ ├── README.md
│ ├── main.m
│ └── main.plist
├── noxcode
│ ├── Makefile
│ ├── README.md
│ ├── main.m
│ ├── myView.h
│ ├── myView.m
│ ├── myWindow.h
│ └── myWindow.m
└── statusmenu
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── AppDelegate.plist
│ ├── Info.plist
│ ├── MainMenu.h
│ ├── MainMenu.m
│ ├── MainMenu.plist
│ ├── Makefile
│ ├── README.md
│ ├── main.m
│ └── main.plist
├── python
├── MetaClass
│ └── Zero.py
├── README.md
├── levenshtein
│ └── ditstance.py
├── sa
│ └── My2InnoDB.py
└── sumit.py
└── ruby
├── README.md
├── convert2icns.rb
├── create_readme.rb
└── jekyll-galleriffic
├── make-galleriffic
└── template.html
/README.md:
--------------------------------------------------------------------------------
1 | Black Cookbook in Dwarf Artisan
2 | =============
3 |
4 | Welcome to Dwarf Artisan's Black Cookbook.
5 |
6 | This this a fork from [Xia Chu Fang Black Cookbook](https://github.com/xiachufang/BlackCookbook), a knowlage code library.
7 |
8 | 下厨房黑科技
9 | ===================
10 |
11 | 下厨房技术团队的开放仓库。这里主要下厨房的工程师们在工作和学习研究过程中积累的
12 | 心得体会。包括一些练习和尝试。
13 |
14 | 不怕笨拙,积极KUSO。为我们自己的成长喝彩。为我们这个不靠谱团队成长为知名不靠谱
15 | 团队做出自己的贡献。
16 |
17 | 在黑科技仓库,我们鼓励过度设计,面条代码,各种非实用技术的尝试。更欢迎大家留下
18 | 翔实的文档,严谨的测试。在工程师独有的娱乐中成长为砖家。
19 |
20 | 关于下厨房
21 | =============
22 |
23 | 下厨房美食菜谱网倡导在家烹饪、健康的生活方式,提供有版权的实用菜谱与饮食知识,为厨艺爱好者搭建一个真诚、有爱的记录分享平台。
24 |
25 | 下厨房非常年轻,但发展速度惊人。自2011年3月上线以来,以与众不同的简洁设计、方便实用的菜谱信息、文艺有爱的气质情怀,从众多同类型网站中脱颖而出,获得了来自各方的好评,以及忠诚度极高的用户。网站目前已有超过20万注册用户,拥有超过200名美食领袖人物作为认证专家,用户活跃度高达30%,网站PR为4,博客PR为5。这个数字还在持续快速增加。
26 |
27 | 网站数据
28 | ----------------------
29 | 月均访问IP:150—180万,月均访问PV:750—900万
30 | alexa排名中国1100名左右
31 |
32 | 下厨房以【网站+博客+邮件EDM+移动客户端+社会化平台】的方式,进行多方位运营。网站提供近10万道有情怀有掌故的菜谱信息;博客通过书影音等文章专题传递“唯有美食与爱不可辜负”的价值观;邮件EDM以诗情画意的意境结合实用性受到用户一致好评;安卓与iPhone移动客户端一经推出便得到了多方关注,下载安装量逾百万;在社会化平台方面,下厨房的新浪微博、QQ空间、豆瓣小站、人人小站、点点等,都各自拥有数量庞大的忠诚粉丝,互动性极高。
33 |
34 | 下厨房不妄称自己是最大最好的,用户认可我们为“最文艺最有爱的菜谱网站”,这比任何自夸都更具含金量。真诚,是下厨房最好的口碑。未来,我们期待在美食领域做得更多。
35 |
36 | 关于的关于
37 | ===============
38 |
39 | 一个正在穿着睡衣上班的胖子代表 Black Cookbook 向提供此文案的有爱的下厨房官方表示感谢。
--------------------------------------------------------------------------------
/cheetsheet/emacs-cheatsheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/cheetsheet/emacs-cheatsheet.png
--------------------------------------------------------------------------------
/cheetsheet/regrex-cheatsheet.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/cheetsheet/regrex-cheatsheet.pdf
--------------------------------------------------------------------------------
/emacs/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/emacs/README.md
--------------------------------------------------------------------------------
/java/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/README.md
--------------------------------------------------------------------------------
/java/algorithm/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/java/algorithm/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | algorithm
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/java/algorithm/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/java/algorithm/bin/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/.DS_Store
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/AllTests.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/AllTests.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/BestRoute.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/BestRoute.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/Client.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/Client.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/Dijkstra.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/Dijkstra.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/HeapSorting.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/HeapSorting.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/Levenshtein.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/Levenshtein.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/LevenshteinTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/LevenshteinTest.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/SortingAlgorithm.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/SortingAlgorithm.class
--------------------------------------------------------------------------------
/java/algorithm/bin/com/xiachufang/Unit.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/bin/com/xiachufang/Unit.class
--------------------------------------------------------------------------------
/java/algorithm/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/src/.DS_Store
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/AllTests.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 | import org.junit.runners.Suite.SuiteClasses;
6 |
7 | @RunWith(Suite.class)
8 | @SuiteClasses({ LevenshteinTest.class })
9 | public class AllTests {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/BestRoute.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | public class BestRoute {
4 | int cast = Integer.MAX_VALUE;
5 | int lastPre = -1;
6 | boolean inOpen = true;
7 |
8 | public int getLastPre() {
9 | return lastPre;
10 | }
11 |
12 | public void setLastPre(int lastPre) {
13 | this.lastPre = lastPre;
14 | }
15 |
16 | public int getCast() {
17 | return cast;
18 | }
19 |
20 | public void setCast(int cast) {
21 | this.cast = cast;
22 | }
23 |
24 | public boolean isInOpen() {
25 | return inOpen;
26 | }
27 |
28 | public void setInOpen(boolean inOpen) {
29 | this.inOpen = inOpen;
30 | }
31 |
32 | public void setLstPre(int pre) {
33 | this.lastPre = pre;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/Client.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | public class Client {
4 | static int MAX = Integer.MAX_VALUE;
5 | static int[][] links = {{MAX,1,2,MAX},{3,MAX,1,2},{2,3,MAX,1},{MAX,2,3,MAX}};
6 | /**
7 | * @param args
8 | */
9 | public static void main(String[] args) {
10 | int sta = 0;
11 | int dst = 3;
12 | Dijkstra d = new Dijkstra(links, sta, dst);
13 | System.out.println(d.calculate());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/Dijkstra.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/java/algorithm/src/com/xiachufang/Dijkstra.java
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/HeapSorting.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 |
6 | public class HeapSorting implements SortingAlgorithm {
7 | private ArrayList units;
8 | int count=0;
9 |
10 | public HeapSorting(ArrayList data) {
11 | units = new ArrayList(20);
12 | makeHeap(data);
13 | }
14 |
15 |
16 | public void makeHeap(ArrayList data) {
17 | units.addAll(0,data);
18 | for (int i = units.size() / 2 - 1; i >= 0; i--) {
19 | heapAdjust(i);
20 | }
21 | // System.out.println("make heap complete");
22 | }
23 |
24 | public void insert(Unit u) {
25 | units.add(u);
26 | int position = units.size() - 1;
27 | while (position > 0 && units.get(position).getValue() < units.get((position - 1) / 2).getValue()) {
28 | Collections.swap(units, position,(position - 1) / 2);
29 | position = (position - 1) / 2;
30 | }
31 | }
32 |
33 | public void heapAdjust(int position) {
34 | while (position * 2 + 1 < units.size()) {
35 | if (position * 2 + 2 < units.size()) {
36 | if (units.get(position * 2 + 1).getValue() > units.get(position * 2 + 2).getValue()) {
37 | if (units.get(position * 2 + 2).getValue() < units.get(position).getValue()) {
38 | Collections.swap(units, position, position * 2 + 2);
39 | position = position * 2 + 2;
40 | continue;
41 | } else {
42 | return;
43 | }
44 | } else {
45 | if (units.get(position * 2 + 1).getValue() < units.get(position).getValue()) {
46 | Collections.swap(units, position, position * 2 + 1);
47 | position = position * 2 + 1;
48 | continue;
49 | } else {
50 | return;
51 | }
52 | }
53 | } else {
54 |
55 | if (units.get(position * 2 + 1).getValue() < units.get(position).getValue()) {
56 | Collections.swap(units, position, position * 2 + 1);
57 | position = position * 2 + 1;
58 | continue;
59 | } else {
60 | return;
61 | }
62 | }
63 | }
64 | }
65 |
66 | public int extractMin() {
67 | if (!units.isEmpty()) {
68 | Collections.swap(units, 0, units.size() - 1);
69 | Unit temp = units.remove(units.size() - 1);
70 | heapAdjust(0);
71 | // System.out.print(++count + "\ttimes findmin"+temp+"\tcomplete opentable size for now:" + units.size()+"\t");
72 | return Integer.parseInt(temp.getKey());
73 | } else {
74 | return Integer.MIN_VALUE;
75 | }
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/Levenshtein.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | public class Levenshtein {
4 | public static int ditstance(String source, String target) {
5 | int src_length = source.length() + 1;
6 | int tgt_length = target.length() + 1;
7 |
8 | if (src_length == 1) {
9 | return tgt_length - 1;
10 | }
11 |
12 | if (tgt_length == 1) {
13 | return src_length - 1;
14 | }
15 |
16 | int[][] matrix = new int[src_length][tgt_length];
17 | for (int i = 0; i < src_length; i++) {
18 | matrix[i][0] = i;
19 | }
20 | for (int i = 0; i < tgt_length; i++) {
21 | matrix[0][i] = i;
22 | }
23 |
24 | for (int i = 1; i < src_length; i++) {
25 | char src_char = source.charAt(i-1);
26 | for (int j = 1; j < tgt_length; j++) {
27 | char tgt_char = target.charAt(j-1);
28 | int cost = (src_char == tgt_char)?0:1;
29 | int above = matrix[i-1][j]+1;
30 | int left = matrix[i][j-1]+1;
31 | int diag = matrix[i-1][j-1]+cost;
32 | int value = Math.min(above, Math.min(left, diag));
33 | matrix[i][j] = value;
34 | }
35 | }
36 |
37 | return matrix[src_length - 1][tgt_length - 1];
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/LevenshteinTest.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | import com.xiachufang.Levenshtein;
8 |
9 | public class LevenshteinTest {
10 |
11 | @Test
12 | public void testDitstanceEqual() {
13 | int value;
14 | value = Levenshtein.ditstance("qq.com", "qq.com");
15 | assertEquals(0, value);
16 | value = Levenshtein.ditstance(".sina.com", ".sina.com");
17 | assertEquals(0, value);
18 | }
19 |
20 | @Test
21 | public void testDitstanceValue() {
22 | int value;
23 |
24 | value = Levenshtein.ditstance("qq.com", ".qq.com");
25 | assertEquals(1, value);
26 | value = Levenshtein.ditstance("qq.com", "qq.cn");
27 | assertEquals(2, value);
28 | value = Levenshtein.ditstance("qq.com", "qq.con");
29 | assertEquals(1, value);
30 | value = Levenshtein.ditstance("gmail.com", ".gmail.com");
31 | assertEquals(1, value);
32 | value = Levenshtein.ditstance("gmail.com.", "gmail.com");
33 | assertEquals(1, value);
34 | value = Levenshtein.ditstance("139.com", "19.com");
35 | assertEquals(1, value);
36 | value = Levenshtein.ditstance("", "gmail.com");
37 | assertEquals(9, value);
38 | value = Levenshtein.ditstance("gmail.com", "");
39 | assertEquals(9, value);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/SortingAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | public interface SortingAlgorithm {
4 | abstract void insert(Unit data);
5 | abstract int extractMin();
6 | }
7 |
--------------------------------------------------------------------------------
/java/algorithm/src/com/xiachufang/Unit.java:
--------------------------------------------------------------------------------
1 | package com.xiachufang;
2 |
3 | public class Unit {
4 | private String key;
5 | private int value;
6 |
7 | public String getKey() {
8 | return key;
9 | }
10 |
11 | public void setKey(String key) {
12 | this.key = key;
13 | }
14 |
15 | public int getValue() {
16 | return value;
17 | }
18 |
19 | public void setValue(int value) {
20 | this.value = value;
21 | }
22 |
23 | public Unit(String key, int value) {
24 | this.key = key;
25 | this.value = value;
26 | }
27 | @Override
28 | public String toString(){
29 | return "key: "+key+" value: "+value;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/javascript/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/javascript/.DS_Store
--------------------------------------------------------------------------------
/javascript/levenshtein/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/javascript/levenshtein/.DS_Store
--------------------------------------------------------------------------------
/javascript/levenshtein/levenshtein.js:
--------------------------------------------------------------------------------
1 | function ditstance(source, target) {
2 | var src_length = source.length + 1;
3 | var tgt_length = target.length + 1;
4 |
5 | if (src_length == 1) {
6 | return tgt_length - 1;
7 | }
8 | if (tgt_length == 1) {
9 | return src_length - 1;
10 | }
11 |
12 | var matrix = new Array();
13 | var row = new Array();
14 | for (i = 0; i < tgt_length; i++){
15 | row[i] = i;
16 | }
17 | matrix[0] = row;
18 | for (i = 1; i < src_length; i++) {
19 | var row = new Array();
20 | row[0] = i;
21 | for (j = 1; j < tgt_length; j++) {
22 | row[j] = 0;
23 | }
24 | matrix[i] = row;
25 | }
26 |
27 | for (i = 1; i < src_length; i++) {
28 | var src_char = source[i-1];
29 | for (j = 1; j < tgt_length; j++) {
30 | var tgt_char = target[j-1];
31 | var cost;
32 | if (src_char === tgt_char) {
33 | cost = 0;
34 | } else {
35 | cost = 1;
36 | }
37 | var above = matrix[i-1][j]+1;
38 | var left = matrix[i][j-1]+1;
39 | var diag = matrix[i-1][j-1]+cost;
40 | var value = Math.min(above, left, diag);
41 | matrix[i][j] = value;
42 | }
43 | }
44 | return matrix[src_length - 1][tgt_length - 1];
45 | }
46 |
--------------------------------------------------------------------------------
/javascript/levenshtein/qunit.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
50 |
51 |
52 |
53 | 此页面需要 qunit 支持
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/objc/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/.DS_Store
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 39C0606714F74DC5009907AE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0606614F74DC5009907AE /* Foundation.framework */; };
11 | 39C0606A14F74DC5009907AE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C0606914F74DC5009907AE /* main.m */; };
12 | 39C0606E14F74DC5009907AE /* HelloObjc.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 39C0606D14F74DC5009907AE /* HelloObjc.1 */; };
13 | /* End PBXBuildFile section */
14 |
15 | /* Begin PBXCopyFilesBuildPhase section */
16 | 39C0606014F74DC5009907AE /* CopyFiles */ = {
17 | isa = PBXCopyFilesBuildPhase;
18 | buildActionMask = 2147483647;
19 | dstPath = /usr/share/man/man1/;
20 | dstSubfolderSpec = 0;
21 | files = (
22 | 39C0606E14F74DC5009907AE /* HelloObjc.1 in CopyFiles */,
23 | );
24 | runOnlyForDeploymentPostprocessing = 1;
25 | };
26 | /* End PBXCopyFilesBuildPhase section */
27 |
28 | /* Begin PBXFileReference section */
29 | 39C0606214F74DC5009907AE /* HelloObjc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = HelloObjc; sourceTree = BUILT_PRODUCTS_DIR; };
30 | 39C0606614F74DC5009907AE /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
31 | 39C0606914F74DC5009907AE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
32 | 39C0606C14F74DC5009907AE /* HelloObjc-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "HelloObjc-Prefix.pch"; sourceTree = ""; };
33 | 39C0606D14F74DC5009907AE /* HelloObjc.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = HelloObjc.1; sourceTree = ""; };
34 | /* End PBXFileReference section */
35 |
36 | /* Begin PBXFrameworksBuildPhase section */
37 | 39C0605F14F74DC5009907AE /* Frameworks */ = {
38 | isa = PBXFrameworksBuildPhase;
39 | buildActionMask = 2147483647;
40 | files = (
41 | 39C0606714F74DC5009907AE /* Foundation.framework in Frameworks */,
42 | );
43 | runOnlyForDeploymentPostprocessing = 0;
44 | };
45 | /* End PBXFrameworksBuildPhase section */
46 |
47 | /* Begin PBXGroup section */
48 | 39C0605714F74DC5009907AE = {
49 | isa = PBXGroup;
50 | children = (
51 | 39C0606814F74DC5009907AE /* HelloObjc */,
52 | 39C0606514F74DC5009907AE /* Frameworks */,
53 | 39C0606314F74DC5009907AE /* Products */,
54 | );
55 | sourceTree = "";
56 | };
57 | 39C0606314F74DC5009907AE /* Products */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 39C0606214F74DC5009907AE /* HelloObjc */,
61 | );
62 | name = Products;
63 | sourceTree = "";
64 | };
65 | 39C0606514F74DC5009907AE /* Frameworks */ = {
66 | isa = PBXGroup;
67 | children = (
68 | 39C0606614F74DC5009907AE /* Foundation.framework */,
69 | );
70 | name = Frameworks;
71 | sourceTree = "";
72 | };
73 | 39C0606814F74DC5009907AE /* HelloObjc */ = {
74 | isa = PBXGroup;
75 | children = (
76 | 39C0606914F74DC5009907AE /* main.m */,
77 | 39C0606D14F74DC5009907AE /* HelloObjc.1 */,
78 | 39C0606B14F74DC5009907AE /* Supporting Files */,
79 | );
80 | path = HelloObjc;
81 | sourceTree = "";
82 | };
83 | 39C0606B14F74DC5009907AE /* Supporting Files */ = {
84 | isa = PBXGroup;
85 | children = (
86 | 39C0606C14F74DC5009907AE /* HelloObjc-Prefix.pch */,
87 | );
88 | name = "Supporting Files";
89 | sourceTree = "";
90 | };
91 | /* End PBXGroup section */
92 |
93 | /* Begin PBXNativeTarget section */
94 | 39C0606114F74DC5009907AE /* HelloObjc */ = {
95 | isa = PBXNativeTarget;
96 | buildConfigurationList = 39C0607114F74DC5009907AE /* Build configuration list for PBXNativeTarget "HelloObjc" */;
97 | buildPhases = (
98 | 39C0605E14F74DC5009907AE /* Sources */,
99 | 39C0605F14F74DC5009907AE /* Frameworks */,
100 | 39C0606014F74DC5009907AE /* CopyFiles */,
101 | );
102 | buildRules = (
103 | );
104 | dependencies = (
105 | );
106 | name = HelloObjc;
107 | productName = HelloObjc;
108 | productReference = 39C0606214F74DC5009907AE /* HelloObjc */;
109 | productType = "com.apple.product-type.tool";
110 | };
111 | /* End PBXNativeTarget section */
112 |
113 | /* Begin PBXProject section */
114 | 39C0605914F74DC5009907AE /* Project object */ = {
115 | isa = PBXProject;
116 | attributes = {
117 | LastUpgradeCheck = 0420;
118 | };
119 | buildConfigurationList = 39C0605C14F74DC5009907AE /* Build configuration list for PBXProject "HelloObjc" */;
120 | compatibilityVersion = "Xcode 3.2";
121 | developmentRegion = English;
122 | hasScannedForEncodings = 0;
123 | knownRegions = (
124 | en,
125 | );
126 | mainGroup = 39C0605714F74DC5009907AE;
127 | productRefGroup = 39C0606314F74DC5009907AE /* Products */;
128 | projectDirPath = "";
129 | projectRoot = "";
130 | targets = (
131 | 39C0606114F74DC5009907AE /* HelloObjc */,
132 | );
133 | };
134 | /* End PBXProject section */
135 |
136 | /* Begin PBXSourcesBuildPhase section */
137 | 39C0605E14F74DC5009907AE /* Sources */ = {
138 | isa = PBXSourcesBuildPhase;
139 | buildActionMask = 2147483647;
140 | files = (
141 | 39C0606A14F74DC5009907AE /* main.m in Sources */,
142 | );
143 | runOnlyForDeploymentPostprocessing = 0;
144 | };
145 | /* End PBXSourcesBuildPhase section */
146 |
147 | /* Begin XCBuildConfiguration section */
148 | 39C0606F14F74DC5009907AE /* Debug */ = {
149 | isa = XCBuildConfiguration;
150 | buildSettings = {
151 | ALWAYS_SEARCH_USER_PATHS = NO;
152 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
153 | COPY_PHASE_STRIP = NO;
154 | GCC_C_LANGUAGE_STANDARD = gnu99;
155 | GCC_DYNAMIC_NO_PIC = NO;
156 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
157 | GCC_OPTIMIZATION_LEVEL = 0;
158 | GCC_PREPROCESSOR_DEFINITIONS = (
159 | "DEBUG=1",
160 | "$(inherited)",
161 | );
162 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
163 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
164 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
165 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
166 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
167 | GCC_WARN_UNUSED_VARIABLE = YES;
168 | MACOSX_DEPLOYMENT_TARGET = 10.7;
169 | ONLY_ACTIVE_ARCH = YES;
170 | SDKROOT = macosx;
171 | };
172 | name = Debug;
173 | };
174 | 39C0607014F74DC5009907AE /* Release */ = {
175 | isa = XCBuildConfiguration;
176 | buildSettings = {
177 | ALWAYS_SEARCH_USER_PATHS = NO;
178 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
179 | COPY_PHASE_STRIP = YES;
180 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
181 | GCC_C_LANGUAGE_STANDARD = gnu99;
182 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
183 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
184 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
185 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
186 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
187 | GCC_WARN_UNUSED_VARIABLE = YES;
188 | MACOSX_DEPLOYMENT_TARGET = 10.7;
189 | SDKROOT = macosx;
190 | };
191 | name = Release;
192 | };
193 | 39C0607214F74DC5009907AE /* Debug */ = {
194 | isa = XCBuildConfiguration;
195 | buildSettings = {
196 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
197 | GCC_PREFIX_HEADER = "HelloObjc/HelloObjc-Prefix.pch";
198 | PRODUCT_NAME = "$(TARGET_NAME)";
199 | };
200 | name = Debug;
201 | };
202 | 39C0607314F74DC5009907AE /* Release */ = {
203 | isa = XCBuildConfiguration;
204 | buildSettings = {
205 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
206 | GCC_PREFIX_HEADER = "HelloObjc/HelloObjc-Prefix.pch";
207 | PRODUCT_NAME = "$(TARGET_NAME)";
208 | };
209 | name = Release;
210 | };
211 | /* End XCBuildConfiguration section */
212 |
213 | /* Begin XCConfigurationList section */
214 | 39C0605C14F74DC5009907AE /* Build configuration list for PBXProject "HelloObjc" */ = {
215 | isa = XCConfigurationList;
216 | buildConfigurations = (
217 | 39C0606F14F74DC5009907AE /* Debug */,
218 | 39C0607014F74DC5009907AE /* Release */,
219 | );
220 | defaultConfigurationIsVisible = 0;
221 | defaultConfigurationName = Release;
222 | };
223 | 39C0607114F74DC5009907AE /* Build configuration list for PBXNativeTarget "HelloObjc" */ = {
224 | isa = XCConfigurationList;
225 | buildConfigurations = (
226 | 39C0607214F74DC5009907AE /* Debug */,
227 | 39C0607314F74DC5009907AE /* Release */,
228 | );
229 | defaultConfigurationIsVisible = 0;
230 | };
231 | /* End XCConfigurationList section */
232 | };
233 | rootObject = 39C0605914F74DC5009907AE /* Project object */;
234 | }
235 |
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/HelloObjc/HelloObjc.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/HelloObjc.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
14 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
38 |
39 |
40 |
41 |
49 |
50 |
56 |
57 |
58 |
59 |
60 |
61 |
67 |
68 |
74 |
75 |
76 |
77 |
79 |
80 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HelloObjc.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 39C0606114F74DC5009907AE
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc/HelloObjc-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'HelloObjc' target in the 'HelloObjc' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc/HelloObjc.1:
--------------------------------------------------------------------------------
1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
2 | .\"See Also:
3 | .\"man mdoc.samples for a complete listing of options
4 | .\"man mdoc for the short list of editing options
5 | .\"/usr/share/misc/mdoc.template
6 | .Dd 12-2-24 \" DATE
7 | .Dt HelloObjc 1 \" Program name and manual section number
8 | .Os Darwin
9 | .Sh NAME \" Section Header - required - don't modify
10 | .Nm HelloObjc,
11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key
12 | .\" words here as the database is built based on the words here and in the .ND line.
13 | .Nm Other_name_for_same_program(),
14 | .Nm Yet another name for the same program.
15 | .\" Use .Nm macro to designate other names for the documented program.
16 | .Nd This line parsed for whatis database.
17 | .Sh SYNOPSIS \" Section Header - required - don't modify
18 | .Nm
19 | .Op Fl abcd \" [-abcd]
20 | .Op Fl a Ar path \" [-a path]
21 | .Op Ar file \" [file]
22 | .Op Ar \" [file ...]
23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline
24 | arg2 ... \" Arguments
25 | .Sh DESCRIPTION \" Section Header - required - don't modify
26 | Use the .Nm macro to refer to your program throughout the man page like such:
27 | .Nm
28 | Underlining is accomplished with the .Ar macro like this:
29 | .Ar underlined text .
30 | .Pp \" Inserts a space
31 | A list of items with descriptions:
32 | .Bl -tag -width -indent \" Begins a tagged list
33 | .It item a \" Each item preceded by .It macro
34 | Description of item a
35 | .It item b
36 | Description of item b
37 | .El \" Ends the list
38 | .Pp
39 | A list of flags and their descriptions:
40 | .Bl -tag -width -indent \" Differs from above in tag removed
41 | .It Fl a \"-a flag as a list item
42 | Description of -a flag
43 | .It Fl b
44 | Description of -b flag
45 | .El \" Ends the list
46 | .Pp
47 | .\" .Sh ENVIRONMENT \" May not be needed
48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
49 | .\" .It Ev ENV_VAR_1
50 | .\" Description of ENV_VAR_1
51 | .\" .It Ev ENV_VAR_2
52 | .\" Description of ENV_VAR_2
53 | .\" .El
54 | .Sh FILES \" File used or created by the topic of the man page
55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
56 | .It Pa /usr/share/file_name
57 | FILE_1 description
58 | .It Pa /Users/joeuser/Library/really_long_file_name
59 | FILE_2 description
60 | .El \" Ends the list
61 | .\" .Sh DIAGNOSTICS \" May not be needed
62 | .\" .Bl -diag
63 | .\" .It Diagnostic Tag
64 | .\" Diagnostic informtion here.
65 | .\" .It Diagnostic Tag
66 | .\" Diagnostic informtion here.
67 | .\" .El
68 | .Sh SEE ALSO
69 | .\" List links in ascending order by section, alphabetically within a section.
70 | .\" Please do not reference files that do not exist without filing a bug report
71 | .Xr a 1 ,
72 | .Xr b 1 ,
73 | .Xr c 1 ,
74 | .Xr a 2 ,
75 | .Xr b 2 ,
76 | .Xr a 3 ,
77 | .Xr b 3
78 | .\" .Sh BUGS \" Document known, unremedied bugs
79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner
--------------------------------------------------------------------------------
/objc/HelloObjc/HelloObjc/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // HelloObjc
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main (int argc, const char * argv[])
12 | {
13 |
14 | @autoreleasepool {
15 |
16 | // insert code here...
17 | NSLog(@"Hello, World!");
18 |
19 | }
20 | return 0;
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/objc/KVCTest/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/KVCTest/.DS_Store
--------------------------------------------------------------------------------
/objc/KVCTest/KTData.h:
--------------------------------------------------------------------------------
1 | //
2 | // KTData.h
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-25.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "KTValue.h"
11 |
12 | @interface KTData : NSObject {
13 | NSString *field;
14 | KTValue *item;
15 | NSNumber *number;
16 | NSArray *numberPool;
17 | }
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/objc/KVCTest/KTData.m:
--------------------------------------------------------------------------------
1 | //
2 | // KTData.m
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-25.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "KTData.h"
10 |
11 | @implementation KTData
12 |
13 | - (id)init {
14 | self = [super init];
15 | if (self) {
16 | field = @"key value coding test object";
17 | item = [[KTValue alloc] init];
18 | number = [[NSNumber alloc] initWithInt:rand()];
19 | numberPool = [[NSArray alloc] initWithObjects:[[NSNumber alloc] initWithInt:rand()],
20 | [[NSNumber alloc] initWithInt:rand()],
21 | [[NSNumber alloc] initWithInt:rand()],
22 | [[NSNumber alloc] initWithInt:rand()],
23 | [[NSNumber alloc] initWithInt:rand()],nil];
24 | }
25 | return self;
26 | }
27 |
28 | - (id)valueForUndefinedKey:(NSString *)key {
29 | return [[NSString alloc] initWithFormat:@"I'm a ghost value for %@", key];
30 | }
31 |
32 | // 激活注释中的代码可以观察到 KVC 方法被重载后的效果
33 | //- (id)valueForKey:(NSString *)key {
34 | // NSLog(@"override for valueForKey ");
35 | // return [super valueForKey:key];
36 | //}
37 | //
38 | //- (id)valueForKeyPath:(NSString *)keyPath {
39 | // NSLog(@"override for valueForKeyPath");
40 | // return [super valueForKeyPath:keyPath];
41 | //}
42 |
43 | @end
44 |
--------------------------------------------------------------------------------
/objc/KVCTest/KTObserver.h:
--------------------------------------------------------------------------------
1 | //
2 | // KTObserver.h
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-26.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KTObserver : NSObject
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/KVCTest/KTObserver.m:
--------------------------------------------------------------------------------
1 | //
2 | // KTObserver.m
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-26.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "KTObserver.h"
10 |
11 | @implementation KTObserver
12 |
13 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
14 | NSLog(@"the sender's value from %@ change to %@",
15 | [change objectForKey:NSKeyValueChangeOldKey],
16 | [change objectForKey:NSKeyValueChangeNewKey]);
17 | }
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/objc/KVCTest/KTValue.h:
--------------------------------------------------------------------------------
1 | //
2 | // KTValue.h
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-26.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface KTValue : NSObject {
12 | NSString *value;
13 | }
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/objc/KVCTest/KTValue.m:
--------------------------------------------------------------------------------
1 | //
2 | // KTValue.m
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-26.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "KTValue.h"
10 |
11 | @implementation KTValue
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 3910F45B14FA69F100841664 /* KTObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 3910F45A14FA69F100841664 /* KTObserver.m */; };
11 | 3910F46214FA7DFE00841664 /* KTValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 3910F46114FA7DFE00841664 /* KTValue.m */; };
12 | 39D12DF114F8B54500B9EF05 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39D12DF014F8B54500B9EF05 /* Foundation.framework */; };
13 | 39D12DF414F8B54500B9EF05 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 39D12DF314F8B54500B9EF05 /* main.m */; };
14 | 39D12DF814F8B54500B9EF05 /* KVCTest.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 39D12DF714F8B54500B9EF05 /* KVCTest.1 */; };
15 | 39D12E0014F8B55F00B9EF05 /* KTData.m in Sources */ = {isa = PBXBuildFile; fileRef = 39D12DFF14F8B55F00B9EF05 /* KTData.m */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXCopyFilesBuildPhase section */
19 | 39D12DEA14F8B54500B9EF05 /* CopyFiles */ = {
20 | isa = PBXCopyFilesBuildPhase;
21 | buildActionMask = 2147483647;
22 | dstPath = /usr/share/man/man1/;
23 | dstSubfolderSpec = 0;
24 | files = (
25 | 39D12DF814F8B54500B9EF05 /* KVCTest.1 in CopyFiles */,
26 | );
27 | runOnlyForDeploymentPostprocessing = 1;
28 | };
29 | /* End PBXCopyFilesBuildPhase section */
30 |
31 | /* Begin PBXFileReference section */
32 | 3910F45914FA69F100841664 /* KTObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KTObserver.h; sourceTree = ""; };
33 | 3910F45A14FA69F100841664 /* KTObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KTObserver.m; sourceTree = ""; };
34 | 3910F46014FA7DFE00841664 /* KTValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KTValue.h; sourceTree = ""; };
35 | 3910F46114FA7DFE00841664 /* KTValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KTValue.m; sourceTree = ""; };
36 | 39D12DEC14F8B54500B9EF05 /* KVCTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = KVCTest; sourceTree = BUILT_PRODUCTS_DIR; };
37 | 39D12DF014F8B54500B9EF05 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
38 | 39D12DF314F8B54500B9EF05 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
39 | 39D12DF614F8B54500B9EF05 /* KVCTest-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KVCTest-Prefix.pch"; sourceTree = ""; };
40 | 39D12DF714F8B54500B9EF05 /* KVCTest.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = KVCTest.1; sourceTree = ""; };
41 | 39D12DFE14F8B55F00B9EF05 /* KTData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KTData.h; sourceTree = ""; };
42 | 39D12DFF14F8B55F00B9EF05 /* KTData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KTData.m; sourceTree = ""; };
43 | /* End PBXFileReference section */
44 |
45 | /* Begin PBXFrameworksBuildPhase section */
46 | 39D12DE914F8B54500B9EF05 /* Frameworks */ = {
47 | isa = PBXFrameworksBuildPhase;
48 | buildActionMask = 2147483647;
49 | files = (
50 | 39D12DF114F8B54500B9EF05 /* Foundation.framework in Frameworks */,
51 | );
52 | runOnlyForDeploymentPostprocessing = 0;
53 | };
54 | /* End PBXFrameworksBuildPhase section */
55 |
56 | /* Begin PBXGroup section */
57 | 39D12DE114F8B54500B9EF05 = {
58 | isa = PBXGroup;
59 | children = (
60 | 3910F46014FA7DFE00841664 /* KTValue.h */,
61 | 3910F46114FA7DFE00841664 /* KTValue.m */,
62 | 3910F45914FA69F100841664 /* KTObserver.h */,
63 | 3910F45A14FA69F100841664 /* KTObserver.m */,
64 | 39D12DFE14F8B55F00B9EF05 /* KTData.h */,
65 | 39D12DFF14F8B55F00B9EF05 /* KTData.m */,
66 | 39D12DF214F8B54500B9EF05 /* KVCTest */,
67 | 39D12DEF14F8B54500B9EF05 /* Frameworks */,
68 | 39D12DED14F8B54500B9EF05 /* Products */,
69 | );
70 | sourceTree = "";
71 | };
72 | 39D12DED14F8B54500B9EF05 /* Products */ = {
73 | isa = PBXGroup;
74 | children = (
75 | 39D12DEC14F8B54500B9EF05 /* KVCTest */,
76 | );
77 | name = Products;
78 | sourceTree = "";
79 | };
80 | 39D12DEF14F8B54500B9EF05 /* Frameworks */ = {
81 | isa = PBXGroup;
82 | children = (
83 | 39D12DF014F8B54500B9EF05 /* Foundation.framework */,
84 | );
85 | name = Frameworks;
86 | sourceTree = "";
87 | };
88 | 39D12DF214F8B54500B9EF05 /* KVCTest */ = {
89 | isa = PBXGroup;
90 | children = (
91 | 39D12DF314F8B54500B9EF05 /* main.m */,
92 | 39D12DF714F8B54500B9EF05 /* KVCTest.1 */,
93 | 39D12DF514F8B54500B9EF05 /* Supporting Files */,
94 | );
95 | path = KVCTest;
96 | sourceTree = "";
97 | };
98 | 39D12DF514F8B54500B9EF05 /* Supporting Files */ = {
99 | isa = PBXGroup;
100 | children = (
101 | 39D12DF614F8B54500B9EF05 /* KVCTest-Prefix.pch */,
102 | );
103 | name = "Supporting Files";
104 | sourceTree = "";
105 | };
106 | /* End PBXGroup section */
107 |
108 | /* Begin PBXNativeTarget section */
109 | 39D12DEB14F8B54500B9EF05 /* KVCTest */ = {
110 | isa = PBXNativeTarget;
111 | buildConfigurationList = 39D12DFB14F8B54500B9EF05 /* Build configuration list for PBXNativeTarget "KVCTest" */;
112 | buildPhases = (
113 | 39D12DE814F8B54500B9EF05 /* Sources */,
114 | 39D12DE914F8B54500B9EF05 /* Frameworks */,
115 | 39D12DEA14F8B54500B9EF05 /* CopyFiles */,
116 | );
117 | buildRules = (
118 | );
119 | dependencies = (
120 | );
121 | name = KVCTest;
122 | productName = KVCTest;
123 | productReference = 39D12DEC14F8B54500B9EF05 /* KVCTest */;
124 | productType = "com.apple.product-type.tool";
125 | };
126 | /* End PBXNativeTarget section */
127 |
128 | /* Begin PBXProject section */
129 | 39D12DE314F8B54500B9EF05 /* Project object */ = {
130 | isa = PBXProject;
131 | attributes = {
132 | LastUpgradeCheck = 0420;
133 | };
134 | buildConfigurationList = 39D12DE614F8B54500B9EF05 /* Build configuration list for PBXProject "KVCTest" */;
135 | compatibilityVersion = "Xcode 3.2";
136 | developmentRegion = English;
137 | hasScannedForEncodings = 0;
138 | knownRegions = (
139 | en,
140 | );
141 | mainGroup = 39D12DE114F8B54500B9EF05;
142 | productRefGroup = 39D12DED14F8B54500B9EF05 /* Products */;
143 | projectDirPath = "";
144 | projectRoot = "";
145 | targets = (
146 | 39D12DEB14F8B54500B9EF05 /* KVCTest */,
147 | );
148 | };
149 | /* End PBXProject section */
150 |
151 | /* Begin PBXSourcesBuildPhase section */
152 | 39D12DE814F8B54500B9EF05 /* Sources */ = {
153 | isa = PBXSourcesBuildPhase;
154 | buildActionMask = 2147483647;
155 | files = (
156 | 39D12DF414F8B54500B9EF05 /* main.m in Sources */,
157 | 39D12E0014F8B55F00B9EF05 /* KTData.m in Sources */,
158 | 3910F45B14FA69F100841664 /* KTObserver.m in Sources */,
159 | 3910F46214FA7DFE00841664 /* KTValue.m in Sources */,
160 | );
161 | runOnlyForDeploymentPostprocessing = 0;
162 | };
163 | /* End PBXSourcesBuildPhase section */
164 |
165 | /* Begin XCBuildConfiguration section */
166 | 39D12DF914F8B54500B9EF05 /* Debug */ = {
167 | isa = XCBuildConfiguration;
168 | buildSettings = {
169 | ALWAYS_SEARCH_USER_PATHS = NO;
170 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
171 | CLANG_ENABLE_OBJC_ARC = YES;
172 | COPY_PHASE_STRIP = NO;
173 | GCC_C_LANGUAGE_STANDARD = gnu99;
174 | GCC_DYNAMIC_NO_PIC = NO;
175 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
176 | GCC_OPTIMIZATION_LEVEL = 0;
177 | GCC_PREPROCESSOR_DEFINITIONS = (
178 | "DEBUG=1",
179 | "$(inherited)",
180 | );
181 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
182 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
183 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
184 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
185 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
186 | GCC_WARN_UNUSED_VARIABLE = YES;
187 | MACOSX_DEPLOYMENT_TARGET = 10.7;
188 | ONLY_ACTIVE_ARCH = YES;
189 | SDKROOT = macosx;
190 | };
191 | name = Debug;
192 | };
193 | 39D12DFA14F8B54500B9EF05 /* Release */ = {
194 | isa = XCBuildConfiguration;
195 | buildSettings = {
196 | ALWAYS_SEARCH_USER_PATHS = NO;
197 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
198 | CLANG_ENABLE_OBJC_ARC = YES;
199 | COPY_PHASE_STRIP = YES;
200 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
201 | GCC_C_LANGUAGE_STANDARD = gnu99;
202 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
203 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
205 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
206 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
207 | GCC_WARN_UNUSED_VARIABLE = YES;
208 | MACOSX_DEPLOYMENT_TARGET = 10.7;
209 | SDKROOT = macosx;
210 | };
211 | name = Release;
212 | };
213 | 39D12DFC14F8B54500B9EF05 /* Debug */ = {
214 | isa = XCBuildConfiguration;
215 | buildSettings = {
216 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
217 | GCC_PREFIX_HEADER = "KVCTest/KVCTest-Prefix.pch";
218 | PRODUCT_NAME = "$(TARGET_NAME)";
219 | };
220 | name = Debug;
221 | };
222 | 39D12DFD14F8B54500B9EF05 /* Release */ = {
223 | isa = XCBuildConfiguration;
224 | buildSettings = {
225 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
226 | GCC_PREFIX_HEADER = "KVCTest/KVCTest-Prefix.pch";
227 | PRODUCT_NAME = "$(TARGET_NAME)";
228 | };
229 | name = Release;
230 | };
231 | /* End XCBuildConfiguration section */
232 |
233 | /* Begin XCConfigurationList section */
234 | 39D12DE614F8B54500B9EF05 /* Build configuration list for PBXProject "KVCTest" */ = {
235 | isa = XCConfigurationList;
236 | buildConfigurations = (
237 | 39D12DF914F8B54500B9EF05 /* Debug */,
238 | 39D12DFA14F8B54500B9EF05 /* Release */,
239 | );
240 | defaultConfigurationIsVisible = 0;
241 | defaultConfigurationName = Release;
242 | };
243 | 39D12DFB14F8B54500B9EF05 /* Build configuration list for PBXNativeTarget "KVCTest" */ = {
244 | isa = XCConfigurationList;
245 | buildConfigurations = (
246 | 39D12DFC14F8B54500B9EF05 /* Debug */,
247 | 39D12DFD14F8B54500B9EF05 /* Release */,
248 | );
249 | defaultConfigurationIsVisible = 0;
250 | defaultConfigurationName = Release;
251 | };
252 | /* End XCConfigurationList section */
253 | };
254 | rootObject = 39D12DE314F8B54500B9EF05 /* Project object */;
255 | }
256 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/KVCTest/KVCTest.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/KVCTest.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
14 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
38 |
39 |
40 |
41 |
49 |
50 |
56 |
57 |
58 |
59 |
60 |
61 |
67 |
68 |
74 |
75 |
76 |
77 |
79 |
80 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | KVCTest.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 39D12DEB14F8B54500B9EF05
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest/KVCTest-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'KVCTest' target in the 'KVCTest' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest/KVCTest.1:
--------------------------------------------------------------------------------
1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
2 | .\"See Also:
3 | .\"man mdoc.samples for a complete listing of options
4 | .\"man mdoc for the short list of editing options
5 | .\"/usr/share/misc/mdoc.template
6 | .Dd 12-2-25 \" DATE
7 | .Dt KVCTest 1 \" Program name and manual section number
8 | .Os Darwin
9 | .Sh NAME \" Section Header - required - don't modify
10 | .Nm KVCTest,
11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key
12 | .\" words here as the database is built based on the words here and in the .ND line.
13 | .Nm Other_name_for_same_program(),
14 | .Nm Yet another name for the same program.
15 | .\" Use .Nm macro to designate other names for the documented program.
16 | .Nd This line parsed for whatis database.
17 | .Sh SYNOPSIS \" Section Header - required - don't modify
18 | .Nm
19 | .Op Fl abcd \" [-abcd]
20 | .Op Fl a Ar path \" [-a path]
21 | .Op Ar file \" [file]
22 | .Op Ar \" [file ...]
23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline
24 | arg2 ... \" Arguments
25 | .Sh DESCRIPTION \" Section Header - required - don't modify
26 | Use the .Nm macro to refer to your program throughout the man page like such:
27 | .Nm
28 | Underlining is accomplished with the .Ar macro like this:
29 | .Ar underlined text .
30 | .Pp \" Inserts a space
31 | A list of items with descriptions:
32 | .Bl -tag -width -indent \" Begins a tagged list
33 | .It item a \" Each item preceded by .It macro
34 | Description of item a
35 | .It item b
36 | Description of item b
37 | .El \" Ends the list
38 | .Pp
39 | A list of flags and their descriptions:
40 | .Bl -tag -width -indent \" Differs from above in tag removed
41 | .It Fl a \"-a flag as a list item
42 | Description of -a flag
43 | .It Fl b
44 | Description of -b flag
45 | .El \" Ends the list
46 | .Pp
47 | .\" .Sh ENVIRONMENT \" May not be needed
48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
49 | .\" .It Ev ENV_VAR_1
50 | .\" Description of ENV_VAR_1
51 | .\" .It Ev ENV_VAR_2
52 | .\" Description of ENV_VAR_2
53 | .\" .El
54 | .Sh FILES \" File used or created by the topic of the man page
55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
56 | .It Pa /usr/share/file_name
57 | FILE_1 description
58 | .It Pa /Users/joeuser/Library/really_long_file_name
59 | FILE_2 description
60 | .El \" Ends the list
61 | .\" .Sh DIAGNOSTICS \" May not be needed
62 | .\" .Bl -diag
63 | .\" .It Diagnostic Tag
64 | .\" Diagnostic informtion here.
65 | .\" .It Diagnostic Tag
66 | .\" Diagnostic informtion here.
67 | .\" .El
68 | .Sh SEE ALSO
69 | .\" List links in ascending order by section, alphabetically within a section.
70 | .\" Please do not reference files that do not exist without filing a bug report
71 | .Xr a 1 ,
72 | .Xr b 1 ,
73 | .Xr c 1 ,
74 | .Xr a 2 ,
75 | .Xr b 2 ,
76 | .Xr a 3 ,
77 | .Xr b 3
78 | .\" .Sh BUGS \" Document known, unremedied bugs
79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner
--------------------------------------------------------------------------------
/objc/KVCTest/KVCTest/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // KVCTest
4 | //
5 | // Created by March Liu on 12-2-25.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "KTData.h"
11 | #import "KTObserver.h"
12 |
13 | NSArray * arraryOfData();
14 | NSSet * setOfData();
15 |
16 | int main (int argc, const char * argv[])
17 | {
18 |
19 | @autoreleasepool {
20 | NSLog(@"参考文档为官方文档和 http://www.slideshare.net/sergio.acosta/intro-to-cocoa-kvckvo-and-bindings-presentation ");
21 | NSLog(@"创建KVC实验对象");
22 | KTData *data = [[KTData alloc] init];
23 | NSLog(@"绑定 KVO");
24 | KTObserver *ob = [[KTObserver alloc] init];
25 | [data addObserver:ob forKeyPath:@"name" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
26 | NSLog(@"绑定数据属性");
27 | [data setValue:@"test data" forKey:@"field"];
28 | NSLog(@"数据绑定成功, data.name 的值为 %@", [data valueForKey:@"field"]);
29 | [data setValue:@"data's item value" forKeyPath:@"item.value"];
30 | NSLog(@"通过 keyvaluepath 的 set/valueForPath 操作可以将 data.item.value 赋值为 %@", [data valueForKeyPath:@"item.value"]);
31 | NSLog(@"解除 KVO 绑定");
32 | [data removeObserver:ob forKeyPath:@"name"];
33 | NSLog(@"构造data对象数组");
34 |
35 | NSArray *array = arraryOfData();
36 | NSLog(@"通过 @avg 计算 nsarray 的数据平均值,结果为 %@", [array valueForKeyPath:@"@avg.number"]);
37 | NSLog(@"通过 @sum 计算 nsarray 的数据总和,结果为 %@", [array valueForKeyPath:@"@sum.number"]);
38 | NSLog(@"通过 @min 计算 nsarray 的最小值,结果为 %@", [array valueForKeyPath:@"@min.number"]);
39 | NSLog(@"通过 @max 计算 nsarray 的最大值,结果为 %@", [array valueForKeyPath:@"@max.number"]);
40 | NSLog(@"通过 @count 计算 nsarray 的数据計數,结果为 %@", [array valueForKeyPath:@"@count.number"]);
41 | NSLog(@"通过 @distinctUnionOfObjects 计算 nsarray 的去重,结果为 %@", [array valueForKeyPath:@"@distinctUnionOfObjects.number"]);
42 | NSLog(@"下面的代码里有什么奇怪的东西混了进来……");
43 | NSLog(@"通过 numberPool.@avg.self 计算 data 中数值池成员的元素平均值,结果为 %@", [data valueForKeyPath:@"numberPool.@avg.self"]);
44 |
45 | NSArray *nestPool = [[NSArray alloc] initWithObjects:arraryOfData(),
46 | arraryOfData(),
47 | arraryOfData(),
48 | arraryOfData(),
49 | arraryOfData(),
50 | nil];
51 |
52 | NSLog(@"通过 @distinctUnionOfArrays 计算多个数组的联合去重,结果为 %@", [nestPool valueForKeyPath:@"@distinctUnionOfArrays.number"]);
53 |
54 | NSLog(@"通过 @unionOfArrays 计算多个数组的联合,结果为 %@", [nestPool valueForKeyPath:@"@unionOfArrays.number"]);
55 |
56 | NSSet *nestSet = [[NSSet alloc] initWithObjects:setOfData(),
57 | setOfData(),
58 | setOfData(),
59 | setOfData(),
60 | setOfData(),
61 | nil];
62 | NSLog(@"通过 @unionOfSets 计算多个集合的联合,结果为 %@", [nestSet valueForKeyPath:@"@distinctUnionOfSets.number"]);
63 |
64 | NSLog(@"valueForUndefinedKey 相当于 Ruby 的 method_missing");
65 | NSLog(@"这个值 %@ 来自不存在的成员 undefined", [data valueForKey:@"undefined"]);
66 | NSLog(@"Objective c 不能动态添加对象的成员,不过通过 valueForUndefinedKey ,我们可以将请求消息转向,从而实现这个功能。");
67 |
68 | NSMutableDictionary *ddata = [[NSMutableDictionary alloc] init];
69 | NSLog(@"对字典对象使用 setValue forKey");
70 | [ddata setValue:@"a value set by setValue:forKey: method" forKey:@"keyInDict"];
71 | NSLog(@"从字典 %@ 中读取 %@ 的 value 而非 object ", ddata, [data valueForKey:@"keyInDict"]);
72 | }
73 | return 0;
74 | }
75 |
76 | NSArray* arraryOfData() {
77 | return [[NSArray alloc] initWithObjects:[[KTData alloc] init],
78 | [[KTData alloc] init],
79 | [[KTData alloc] init],
80 | [[KTData alloc] init],
81 | nil];
82 | }
83 |
84 | NSSet *setOfData() {
85 | return [[NSSet alloc] initWithObjects:[[KTData alloc] init],
86 | [[KTData alloc] init],
87 | [[KTData alloc] init],
88 | [[KTData alloc] init],
89 | nil];
90 | }
91 |
92 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 3910F47814FB713900841664 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3910F47714FB713900841664 /* Foundation.framework */; };
11 | 3910F47B14FB713900841664 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3910F47A14FB713900841664 /* main.m */; };
12 | 3910F47F14FB713900841664 /* LevenshteinDistance.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3910F47E14FB713900841664 /* LevenshteinDistance.1 */; };
13 | 3910F48714FB77BE00841664 /* XcfLevenshteinDitstance.m in Sources */ = {isa = PBXBuildFile; fileRef = 3910F48614FB77BE00841664 /* XcfLevenshteinDitstance.m */; };
14 | /* End PBXBuildFile section */
15 |
16 | /* Begin PBXCopyFilesBuildPhase section */
17 | 3910F47114FB713900841664 /* CopyFiles */ = {
18 | isa = PBXCopyFilesBuildPhase;
19 | buildActionMask = 2147483647;
20 | dstPath = /usr/share/man/man1/;
21 | dstSubfolderSpec = 0;
22 | files = (
23 | 3910F47F14FB713900841664 /* LevenshteinDistance.1 in CopyFiles */,
24 | );
25 | runOnlyForDeploymentPostprocessing = 1;
26 | };
27 | /* End PBXCopyFilesBuildPhase section */
28 |
29 | /* Begin PBXFileReference section */
30 | 3910F47314FB713900841664 /* LevenshteinDistance */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = LevenshteinDistance; sourceTree = BUILT_PRODUCTS_DIR; };
31 | 3910F47714FB713900841664 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
32 | 3910F47A14FB713900841664 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
33 | 3910F47D14FB713900841664 /* LevenshteinDistance-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LevenshteinDistance-Prefix.pch"; sourceTree = ""; };
34 | 3910F47E14FB713900841664 /* LevenshteinDistance.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = LevenshteinDistance.1; sourceTree = ""; };
35 | 3910F48514FB77BE00841664 /* XcfLevenshteinDitstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XcfLevenshteinDitstance.h; sourceTree = ""; };
36 | 3910F48614FB77BE00841664 /* XcfLevenshteinDitstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XcfLevenshteinDitstance.m; sourceTree = ""; };
37 | /* End PBXFileReference section */
38 |
39 | /* Begin PBXFrameworksBuildPhase section */
40 | 3910F47014FB713900841664 /* Frameworks */ = {
41 | isa = PBXFrameworksBuildPhase;
42 | buildActionMask = 2147483647;
43 | files = (
44 | 3910F47814FB713900841664 /* Foundation.framework in Frameworks */,
45 | );
46 | runOnlyForDeploymentPostprocessing = 0;
47 | };
48 | /* End PBXFrameworksBuildPhase section */
49 |
50 | /* Begin PBXGroup section */
51 | 3910F46814FB713900841664 = {
52 | isa = PBXGroup;
53 | children = (
54 | 3910F47914FB713900841664 /* LevenshteinDistance */,
55 | 3910F47614FB713900841664 /* Frameworks */,
56 | 3910F47414FB713900841664 /* Products */,
57 | );
58 | sourceTree = "";
59 | };
60 | 3910F47414FB713900841664 /* Products */ = {
61 | isa = PBXGroup;
62 | children = (
63 | 3910F47314FB713900841664 /* LevenshteinDistance */,
64 | );
65 | name = Products;
66 | sourceTree = "";
67 | };
68 | 3910F47614FB713900841664 /* Frameworks */ = {
69 | isa = PBXGroup;
70 | children = (
71 | 3910F47714FB713900841664 /* Foundation.framework */,
72 | );
73 | name = Frameworks;
74 | sourceTree = "";
75 | };
76 | 3910F47914FB713900841664 /* LevenshteinDistance */ = {
77 | isa = PBXGroup;
78 | children = (
79 | 3910F47A14FB713900841664 /* main.m */,
80 | 3910F47E14FB713900841664 /* LevenshteinDistance.1 */,
81 | 3910F47C14FB713900841664 /* Supporting Files */,
82 | 3910F48514FB77BE00841664 /* XcfLevenshteinDitstance.h */,
83 | 3910F48614FB77BE00841664 /* XcfLevenshteinDitstance.m */,
84 | );
85 | path = LevenshteinDistance;
86 | sourceTree = "";
87 | };
88 | 3910F47C14FB713900841664 /* Supporting Files */ = {
89 | isa = PBXGroup;
90 | children = (
91 | 3910F47D14FB713900841664 /* LevenshteinDistance-Prefix.pch */,
92 | );
93 | name = "Supporting Files";
94 | sourceTree = "";
95 | };
96 | /* End PBXGroup section */
97 |
98 | /* Begin PBXNativeTarget section */
99 | 3910F47214FB713900841664 /* LevenshteinDistance */ = {
100 | isa = PBXNativeTarget;
101 | buildConfigurationList = 3910F48214FB713900841664 /* Build configuration list for PBXNativeTarget "LevenshteinDistance" */;
102 | buildPhases = (
103 | 3910F46F14FB713900841664 /* Sources */,
104 | 3910F47014FB713900841664 /* Frameworks */,
105 | 3910F47114FB713900841664 /* CopyFiles */,
106 | );
107 | buildRules = (
108 | );
109 | dependencies = (
110 | );
111 | name = LevenshteinDistance;
112 | productName = LevenshteinDistance;
113 | productReference = 3910F47314FB713900841664 /* LevenshteinDistance */;
114 | productType = "com.apple.product-type.tool";
115 | };
116 | /* End PBXNativeTarget section */
117 |
118 | /* Begin PBXProject section */
119 | 3910F46A14FB713900841664 /* Project object */ = {
120 | isa = PBXProject;
121 | attributes = {
122 | LastUpgradeCheck = 0420;
123 | };
124 | buildConfigurationList = 3910F46D14FB713900841664 /* Build configuration list for PBXProject "LevenshteinDistance" */;
125 | compatibilityVersion = "Xcode 3.2";
126 | developmentRegion = English;
127 | hasScannedForEncodings = 0;
128 | knownRegions = (
129 | en,
130 | );
131 | mainGroup = 3910F46814FB713900841664;
132 | productRefGroup = 3910F47414FB713900841664 /* Products */;
133 | projectDirPath = "";
134 | projectRoot = "";
135 | targets = (
136 | 3910F47214FB713900841664 /* LevenshteinDistance */,
137 | );
138 | };
139 | /* End PBXProject section */
140 |
141 | /* Begin PBXSourcesBuildPhase section */
142 | 3910F46F14FB713900841664 /* Sources */ = {
143 | isa = PBXSourcesBuildPhase;
144 | buildActionMask = 2147483647;
145 | files = (
146 | 3910F47B14FB713900841664 /* main.m in Sources */,
147 | 3910F48714FB77BE00841664 /* XcfLevenshteinDitstance.m in Sources */,
148 | );
149 | runOnlyForDeploymentPostprocessing = 0;
150 | };
151 | /* End PBXSourcesBuildPhase section */
152 |
153 | /* Begin XCBuildConfiguration section */
154 | 3910F48014FB713900841664 /* Debug */ = {
155 | isa = XCBuildConfiguration;
156 | buildSettings = {
157 | ALWAYS_SEARCH_USER_PATHS = NO;
158 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
159 | COPY_PHASE_STRIP = NO;
160 | GCC_C_LANGUAGE_STANDARD = gnu99;
161 | GCC_DYNAMIC_NO_PIC = NO;
162 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
163 | GCC_OPTIMIZATION_LEVEL = 0;
164 | GCC_PREPROCESSOR_DEFINITIONS = (
165 | "DEBUG=1",
166 | "$(inherited)",
167 | );
168 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
169 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
170 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
171 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
172 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
173 | GCC_WARN_UNUSED_VARIABLE = YES;
174 | MACOSX_DEPLOYMENT_TARGET = 10.7;
175 | ONLY_ACTIVE_ARCH = YES;
176 | SDKROOT = macosx;
177 | };
178 | name = Debug;
179 | };
180 | 3910F48114FB713900841664 /* Release */ = {
181 | isa = XCBuildConfiguration;
182 | buildSettings = {
183 | ALWAYS_SEARCH_USER_PATHS = NO;
184 | ARCHS = "$(ARCHS_STANDARD_64_BIT)";
185 | COPY_PHASE_STRIP = YES;
186 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
187 | GCC_C_LANGUAGE_STANDARD = gnu99;
188 | GCC_ENABLE_OBJC_EXCEPTIONS = YES;
189 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
190 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
191 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
192 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
193 | GCC_WARN_UNUSED_VARIABLE = YES;
194 | MACOSX_DEPLOYMENT_TARGET = 10.7;
195 | SDKROOT = macosx;
196 | };
197 | name = Release;
198 | };
199 | 3910F48314FB713900841664 /* Debug */ = {
200 | isa = XCBuildConfiguration;
201 | buildSettings = {
202 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
203 | GCC_PREFIX_HEADER = "LevenshteinDistance/LevenshteinDistance-Prefix.pch";
204 | PRODUCT_NAME = "$(TARGET_NAME)";
205 | };
206 | name = Debug;
207 | };
208 | 3910F48414FB713900841664 /* Release */ = {
209 | isa = XCBuildConfiguration;
210 | buildSettings = {
211 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
212 | GCC_PREFIX_HEADER = "LevenshteinDistance/LevenshteinDistance-Prefix.pch";
213 | PRODUCT_NAME = "$(TARGET_NAME)";
214 | };
215 | name = Release;
216 | };
217 | /* End XCBuildConfiguration section */
218 |
219 | /* Begin XCConfigurationList section */
220 | 3910F46D14FB713900841664 /* Build configuration list for PBXProject "LevenshteinDistance" */ = {
221 | isa = XCConfigurationList;
222 | buildConfigurations = (
223 | 3910F48014FB713900841664 /* Debug */,
224 | 3910F48114FB713900841664 /* Release */,
225 | );
226 | defaultConfigurationIsVisible = 0;
227 | defaultConfigurationName = Release;
228 | };
229 | 3910F48214FB713900841664 /* Build configuration list for PBXNativeTarget "LevenshteinDistance" */ = {
230 | isa = XCConfigurationList;
231 | buildConfigurations = (
232 | 3910F48314FB713900841664 /* Debug */,
233 | 3910F48414FB713900841664 /* Release */,
234 | );
235 | defaultConfigurationIsVisible = 0;
236 | };
237 | /* End XCConfigurationList section */
238 | };
239 | rootObject = 3910F46A14FB713900841664 /* Project object */;
240 | }
241 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/LevenshteinDistance.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
14 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
38 |
39 |
40 |
41 |
49 |
50 |
56 |
57 |
58 |
59 |
60 |
61 |
67 |
68 |
74 |
75 |
76 |
77 |
79 |
80 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | LevenshteinDistance.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 3910F47214FB713900841664
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance/LevenshteinDistance-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'LevenshteinDistance' target in the 'LevenshteinDistance' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance/LevenshteinDistance.1:
--------------------------------------------------------------------------------
1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
2 | .\"See Also:
3 | .\"man mdoc.samples for a complete listing of options
4 | .\"man mdoc for the short list of editing options
5 | .\"/usr/share/misc/mdoc.template
6 | .Dd 12-2-27 \" DATE
7 | .Dt LevenshteinDistance 1 \" Program name and manual section number
8 | .Os Darwin
9 | .Sh NAME \" Section Header - required - don't modify
10 | .Nm LevenshteinDistance,
11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key
12 | .\" words here as the database is built based on the words here and in the .ND line.
13 | .Nm Other_name_for_same_program(),
14 | .Nm Yet another name for the same program.
15 | .\" Use .Nm macro to designate other names for the documented program.
16 | .Nd This line parsed for whatis database.
17 | .Sh SYNOPSIS \" Section Header - required - don't modify
18 | .Nm
19 | .Op Fl abcd \" [-abcd]
20 | .Op Fl a Ar path \" [-a path]
21 | .Op Ar file \" [file]
22 | .Op Ar \" [file ...]
23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline
24 | arg2 ... \" Arguments
25 | .Sh DESCRIPTION \" Section Header - required - don't modify
26 | Use the .Nm macro to refer to your program throughout the man page like such:
27 | .Nm
28 | Underlining is accomplished with the .Ar macro like this:
29 | .Ar underlined text .
30 | .Pp \" Inserts a space
31 | A list of items with descriptions:
32 | .Bl -tag -width -indent \" Begins a tagged list
33 | .It item a \" Each item preceded by .It macro
34 | Description of item a
35 | .It item b
36 | Description of item b
37 | .El \" Ends the list
38 | .Pp
39 | A list of flags and their descriptions:
40 | .Bl -tag -width -indent \" Differs from above in tag removed
41 | .It Fl a \"-a flag as a list item
42 | Description of -a flag
43 | .It Fl b
44 | Description of -b flag
45 | .El \" Ends the list
46 | .Pp
47 | .\" .Sh ENVIRONMENT \" May not be needed
48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
49 | .\" .It Ev ENV_VAR_1
50 | .\" Description of ENV_VAR_1
51 | .\" .It Ev ENV_VAR_2
52 | .\" Description of ENV_VAR_2
53 | .\" .El
54 | .Sh FILES \" File used or created by the topic of the man page
55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
56 | .It Pa /usr/share/file_name
57 | FILE_1 description
58 | .It Pa /Users/joeuser/Library/really_long_file_name
59 | FILE_2 description
60 | .El \" Ends the list
61 | .\" .Sh DIAGNOSTICS \" May not be needed
62 | .\" .Bl -diag
63 | .\" .It Diagnostic Tag
64 | .\" Diagnostic informtion here.
65 | .\" .It Diagnostic Tag
66 | .\" Diagnostic informtion here.
67 | .\" .El
68 | .Sh SEE ALSO
69 | .\" List links in ascending order by section, alphabetically within a section.
70 | .\" Please do not reference files that do not exist without filing a bug report
71 | .Xr a 1 ,
72 | .Xr b 1 ,
73 | .Xr c 1 ,
74 | .Xr a 2 ,
75 | .Xr b 2 ,
76 | .Xr a 3 ,
77 | .Xr b 3
78 | .\" .Sh BUGS \" Document known, unremedied bugs
79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance/XcfLevenshteinDitstance.h:
--------------------------------------------------------------------------------
1 | //
2 | // XcfLevenshteinDitstance.h
3 | // LevenshteinDistance
4 | //
5 | // Created by March Liu on 12-2-27.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface XcfLevenshteinDitstance : NSObject
12 |
13 | + (int) levenshteinDitstanceFromS:(NSString *)x toT:(NSString *)y;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/objc/LevenshteinDistance/LevenshteinDistance/XcfLevenshteinDitstance.m:
--------------------------------------------------------------------------------
1 | //
2 | // XcfLevenshteinDitstance.m
3 | // LevenshteinDistance
4 | //
5 | // Created by March Liu on 12-2-27.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "XcfLevenshteinDitstance.h"
10 |
11 | @implementation XcfLevenshteinDitstance
12 |
13 | + (int) levenshteinDitstanceFromS:(NSString *)source toT:(NSString *)target {
14 | int sl = (int)[source length]+1;
15 | int tl = (int)[target length]+1;
16 |
17 | if (sl==1) {
18 | return tl - 1;
19 | }
20 | if (tl==1) {
21 | return sl - 1;
22 | }
23 |
24 | int length = sizeof(int)*sl*tl;
25 | int *buffer = malloc(length);
26 | int **matrix = malloc(sizeof(int*)*sl);
27 | memset(buffer, 0, length);
28 | for (int i = 0; i
10 | #import "XcfLevenshteinDitstance.h"
11 |
12 | int main (int argc, const char * argv[])
13 | {
14 |
15 | @autoreleasepool {
16 |
17 | // insert code here...
18 | NSLog(@"Levenshitein Distance!");
19 |
20 | NSArray *array = [[NSArray alloc] initWithObjects:@"march.liu@gmail.com",
21 | @"noreply@gmail.com",
22 | @"noreply@qmail.com",
23 | @"liuxin2@kingsoft.com",
24 | @"march@xiachufang.com", nil];
25 |
26 | for (NSString *source in array) {
27 | for (NSString *target in array) {
28 | NSLog(@"the ditance of %@ and %@ is %d", source, target,
29 | [XcfLevenshteinDitstance levenshteinDitstanceFromS:source toT:target]);
30 | }
31 | }
32 | }
33 | return 0;
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/objc/README.md:
--------------------------------------------------------------------------------
1 | 关于 Objective C 仓库
2 | =========================
3 |
4 | Objective C 是 Smalltalk 族系中的高性能应用开发语言。
5 | 提供 Smalltalk 风格的面向对象语法和 C 级别的运行性能。
6 |
7 | Objective C 是 Apple 公司 iOS 和 Mac OS 操作系统环境中的主力开发语言。
8 | 这个领域的开发人员通常使用 XCode 为开发工具。底层使用 LLVM/clang 编译器。
9 |
10 | 关于本仓库
11 | -----------------
12 |
13 | 本仓库主要存储下厨房团队使用 Objective C 开发的 iOS/Mac OS
14 | 或其它平台的非产品代码。
15 |
16 | Levenshtein Distance
17 | ---------------------------
18 | 字符串相似度判断算法 Levenshtein Distance 编辑距离算法。
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 39C0608914F7736C009907AE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608814F7736C009907AE /* UIKit.framework */; };
11 | 39C0608B14F7736C009907AE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608A14F7736C009907AE /* Foundation.framework */; };
12 | 39C0608D14F7736C009907AE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608C14F7736C009907AE /* CoreGraphics.framework */; };
13 | 39C0608F14F7736C009907AE /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608E14F7736C009907AE /* CoreData.framework */; };
14 | 39C0609514F7736D009907AE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 39C0609314F7736D009907AE /* InfoPlist.strings */; };
15 | 39C0609714F7736D009907AE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C0609614F7736D009907AE /* main.m */; };
16 | 39C0609B14F7736D009907AE /* XcfAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C0609A14F7736D009907AE /* XcfAppDelegate.m */; };
17 | 39C0609E14F7736E009907AE /* SnapNotes.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 39C0609C14F7736E009907AE /* SnapNotes.xcdatamodeld */; };
18 | 39C060A614F7736E009907AE /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C060A514F7736E009907AE /* SenTestingKit.framework */; };
19 | 39C060A714F7736E009907AE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608814F7736C009907AE /* UIKit.framework */; };
20 | 39C060A814F7736E009907AE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608A14F7736C009907AE /* Foundation.framework */; };
21 | 39C060A914F7736E009907AE /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 39C0608E14F7736C009907AE /* CoreData.framework */; };
22 | 39C060B114F7736E009907AE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 39C060AF14F7736E009907AE /* InfoPlist.strings */; };
23 | 39C060B414F7736F009907AE /* SnapNotesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C060B314F7736F009907AE /* SnapNotesTests.m */; };
24 | 39C060C114F77742009907AE /* NotesTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C060C014F77742009907AE /* NotesTableView.m */; };
25 | 39C060C414F7779A009907AE /* NotesLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 39C060C314F7779A009907AE /* NotesLine.m */; };
26 | /* End PBXBuildFile section */
27 |
28 | /* Begin PBXContainerItemProxy section */
29 | 39C060AA14F7736E009907AE /* PBXContainerItemProxy */ = {
30 | isa = PBXContainerItemProxy;
31 | containerPortal = 39C0607B14F7736C009907AE /* Project object */;
32 | proxyType = 1;
33 | remoteGlobalIDString = 39C0608314F7736C009907AE;
34 | remoteInfo = SnapNotes;
35 | };
36 | /* End PBXContainerItemProxy section */
37 |
38 | /* Begin PBXFileReference section */
39 | 39C0608414F7736C009907AE /* SnapNotes.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SnapNotes.app; sourceTree = BUILT_PRODUCTS_DIR; };
40 | 39C0608814F7736C009907AE /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
41 | 39C0608A14F7736C009907AE /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
42 | 39C0608C14F7736C009907AE /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
43 | 39C0608E14F7736C009907AE /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
44 | 39C0609214F7736D009907AE /* SnapNotes-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SnapNotes-Info.plist"; sourceTree = ""; };
45 | 39C0609414F7736D009907AE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
46 | 39C0609614F7736D009907AE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
47 | 39C0609814F7736D009907AE /* SnapNotes-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SnapNotes-Prefix.pch"; sourceTree = ""; };
48 | 39C0609914F7736D009907AE /* XcfAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XcfAppDelegate.h; sourceTree = ""; };
49 | 39C0609A14F7736D009907AE /* XcfAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XcfAppDelegate.m; sourceTree = ""; };
50 | 39C0609D14F7736E009907AE /* SnapNotes.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = SnapNotes.xcdatamodel; sourceTree = ""; };
51 | 39C060A414F7736E009907AE /* SnapNotesTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnapNotesTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
52 | 39C060A514F7736E009907AE /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
53 | 39C060AE14F7736E009907AE /* SnapNotesTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SnapNotesTests-Info.plist"; sourceTree = ""; };
54 | 39C060B014F7736E009907AE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
55 | 39C060B214F7736E009907AE /* SnapNotesTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SnapNotesTests.h; sourceTree = ""; };
56 | 39C060B314F7736F009907AE /* SnapNotesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SnapNotesTests.m; sourceTree = ""; };
57 | 39C060BF14F77742009907AE /* NotesTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotesTableView.h; sourceTree = ""; };
58 | 39C060C014F77742009907AE /* NotesTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotesTableView.m; sourceTree = ""; };
59 | 39C060C214F7779A009907AE /* NotesLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotesLine.h; sourceTree = ""; };
60 | 39C060C314F7779A009907AE /* NotesLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotesLine.m; sourceTree = ""; };
61 | /* End PBXFileReference section */
62 |
63 | /* Begin PBXFrameworksBuildPhase section */
64 | 39C0608114F7736C009907AE /* Frameworks */ = {
65 | isa = PBXFrameworksBuildPhase;
66 | buildActionMask = 2147483647;
67 | files = (
68 | 39C0608914F7736C009907AE /* UIKit.framework in Frameworks */,
69 | 39C0608B14F7736C009907AE /* Foundation.framework in Frameworks */,
70 | 39C0608D14F7736C009907AE /* CoreGraphics.framework in Frameworks */,
71 | 39C0608F14F7736C009907AE /* CoreData.framework in Frameworks */,
72 | );
73 | runOnlyForDeploymentPostprocessing = 0;
74 | };
75 | 39C060A014F7736E009907AE /* Frameworks */ = {
76 | isa = PBXFrameworksBuildPhase;
77 | buildActionMask = 2147483647;
78 | files = (
79 | 39C060A614F7736E009907AE /* SenTestingKit.framework in Frameworks */,
80 | 39C060A714F7736E009907AE /* UIKit.framework in Frameworks */,
81 | 39C060A814F7736E009907AE /* Foundation.framework in Frameworks */,
82 | 39C060A914F7736E009907AE /* CoreData.framework in Frameworks */,
83 | );
84 | runOnlyForDeploymentPostprocessing = 0;
85 | };
86 | /* End PBXFrameworksBuildPhase section */
87 |
88 | /* Begin PBXGroup section */
89 | 39C0607914F7736C009907AE = {
90 | isa = PBXGroup;
91 | children = (
92 | 39C0609014F7736C009907AE /* SnapNotes */,
93 | 39C060AC14F7736E009907AE /* SnapNotesTests */,
94 | 39C0608714F7736C009907AE /* Frameworks */,
95 | 39C0608514F7736C009907AE /* Products */,
96 | );
97 | sourceTree = "";
98 | };
99 | 39C0608514F7736C009907AE /* Products */ = {
100 | isa = PBXGroup;
101 | children = (
102 | 39C0608414F7736C009907AE /* SnapNotes.app */,
103 | 39C060A414F7736E009907AE /* SnapNotesTests.octest */,
104 | );
105 | name = Products;
106 | sourceTree = "";
107 | };
108 | 39C0608714F7736C009907AE /* Frameworks */ = {
109 | isa = PBXGroup;
110 | children = (
111 | 39C0608814F7736C009907AE /* UIKit.framework */,
112 | 39C0608A14F7736C009907AE /* Foundation.framework */,
113 | 39C0608C14F7736C009907AE /* CoreGraphics.framework */,
114 | 39C0608E14F7736C009907AE /* CoreData.framework */,
115 | 39C060A514F7736E009907AE /* SenTestingKit.framework */,
116 | );
117 | name = Frameworks;
118 | sourceTree = "";
119 | };
120 | 39C0609014F7736C009907AE /* SnapNotes */ = {
121 | isa = PBXGroup;
122 | children = (
123 | 39C060BE14F774D3009907AE /* Controllers */,
124 | 39C060BD14F7749C009907AE /* models */,
125 | 39C0609914F7736D009907AE /* XcfAppDelegate.h */,
126 | 39C0609A14F7736D009907AE /* XcfAppDelegate.m */,
127 | 39C0609C14F7736E009907AE /* SnapNotes.xcdatamodeld */,
128 | 39C0609114F7736D009907AE /* Supporting Files */,
129 | );
130 | path = SnapNotes;
131 | sourceTree = "";
132 | };
133 | 39C0609114F7736D009907AE /* Supporting Files */ = {
134 | isa = PBXGroup;
135 | children = (
136 | 39C0609214F7736D009907AE /* SnapNotes-Info.plist */,
137 | 39C0609314F7736D009907AE /* InfoPlist.strings */,
138 | 39C0609614F7736D009907AE /* main.m */,
139 | 39C0609814F7736D009907AE /* SnapNotes-Prefix.pch */,
140 | );
141 | name = "Supporting Files";
142 | sourceTree = "";
143 | };
144 | 39C060AC14F7736E009907AE /* SnapNotesTests */ = {
145 | isa = PBXGroup;
146 | children = (
147 | 39C060B214F7736E009907AE /* SnapNotesTests.h */,
148 | 39C060B314F7736F009907AE /* SnapNotesTests.m */,
149 | 39C060AD14F7736E009907AE /* Supporting Files */,
150 | );
151 | path = SnapNotesTests;
152 | sourceTree = "";
153 | };
154 | 39C060AD14F7736E009907AE /* Supporting Files */ = {
155 | isa = PBXGroup;
156 | children = (
157 | 39C060AE14F7736E009907AE /* SnapNotesTests-Info.plist */,
158 | 39C060AF14F7736E009907AE /* InfoPlist.strings */,
159 | );
160 | name = "Supporting Files";
161 | sourceTree = "";
162 | };
163 | 39C060BD14F7749C009907AE /* models */ = {
164 | isa = PBXGroup;
165 | children = (
166 | 39C060C214F7779A009907AE /* NotesLine.h */,
167 | 39C060C314F7779A009907AE /* NotesLine.m */,
168 | );
169 | name = models;
170 | sourceTree = "";
171 | };
172 | 39C060BE14F774D3009907AE /* Controllers */ = {
173 | isa = PBXGroup;
174 | children = (
175 | 39C060BF14F77742009907AE /* NotesTableView.h */,
176 | 39C060C014F77742009907AE /* NotesTableView.m */,
177 | );
178 | name = Controllers;
179 | sourceTree = "";
180 | };
181 | /* End PBXGroup section */
182 |
183 | /* Begin PBXNativeTarget section */
184 | 39C0608314F7736C009907AE /* SnapNotes */ = {
185 | isa = PBXNativeTarget;
186 | buildConfigurationList = 39C060B714F7736F009907AE /* Build configuration list for PBXNativeTarget "SnapNotes" */;
187 | buildPhases = (
188 | 39C0608014F7736C009907AE /* Sources */,
189 | 39C0608114F7736C009907AE /* Frameworks */,
190 | 39C0608214F7736C009907AE /* Resources */,
191 | );
192 | buildRules = (
193 | );
194 | dependencies = (
195 | );
196 | name = SnapNotes;
197 | productName = SnapNotes;
198 | productReference = 39C0608414F7736C009907AE /* SnapNotes.app */;
199 | productType = "com.apple.product-type.application";
200 | };
201 | 39C060A314F7736E009907AE /* SnapNotesTests */ = {
202 | isa = PBXNativeTarget;
203 | buildConfigurationList = 39C060BA14F7736F009907AE /* Build configuration list for PBXNativeTarget "SnapNotesTests" */;
204 | buildPhases = (
205 | 39C0609F14F7736E009907AE /* Sources */,
206 | 39C060A014F7736E009907AE /* Frameworks */,
207 | 39C060A114F7736E009907AE /* Resources */,
208 | 39C060A214F7736E009907AE /* ShellScript */,
209 | );
210 | buildRules = (
211 | );
212 | dependencies = (
213 | 39C060AB14F7736E009907AE /* PBXTargetDependency */,
214 | );
215 | name = SnapNotesTests;
216 | productName = SnapNotesTests;
217 | productReference = 39C060A414F7736E009907AE /* SnapNotesTests.octest */;
218 | productType = "com.apple.product-type.bundle";
219 | };
220 | /* End PBXNativeTarget section */
221 |
222 | /* Begin PBXProject section */
223 | 39C0607B14F7736C009907AE /* Project object */ = {
224 | isa = PBXProject;
225 | attributes = {
226 | LastUpgradeCheck = 0420;
227 | };
228 | buildConfigurationList = 39C0607E14F7736C009907AE /* Build configuration list for PBXProject "SnapNotes" */;
229 | compatibilityVersion = "Xcode 3.2";
230 | developmentRegion = English;
231 | hasScannedForEncodings = 0;
232 | knownRegions = (
233 | en,
234 | );
235 | mainGroup = 39C0607914F7736C009907AE;
236 | productRefGroup = 39C0608514F7736C009907AE /* Products */;
237 | projectDirPath = "";
238 | projectRoot = "";
239 | targets = (
240 | 39C0608314F7736C009907AE /* SnapNotes */,
241 | 39C060A314F7736E009907AE /* SnapNotesTests */,
242 | );
243 | };
244 | /* End PBXProject section */
245 |
246 | /* Begin PBXResourcesBuildPhase section */
247 | 39C0608214F7736C009907AE /* Resources */ = {
248 | isa = PBXResourcesBuildPhase;
249 | buildActionMask = 2147483647;
250 | files = (
251 | 39C0609514F7736D009907AE /* InfoPlist.strings in Resources */,
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | 39C060A114F7736E009907AE /* Resources */ = {
256 | isa = PBXResourcesBuildPhase;
257 | buildActionMask = 2147483647;
258 | files = (
259 | 39C060B114F7736E009907AE /* InfoPlist.strings in Resources */,
260 | );
261 | runOnlyForDeploymentPostprocessing = 0;
262 | };
263 | /* End PBXResourcesBuildPhase section */
264 |
265 | /* Begin PBXShellScriptBuildPhase section */
266 | 39C060A214F7736E009907AE /* ShellScript */ = {
267 | isa = PBXShellScriptBuildPhase;
268 | buildActionMask = 2147483647;
269 | files = (
270 | );
271 | inputPaths = (
272 | );
273 | outputPaths = (
274 | );
275 | runOnlyForDeploymentPostprocessing = 0;
276 | shellPath = /bin/sh;
277 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
278 | };
279 | /* End PBXShellScriptBuildPhase section */
280 |
281 | /* Begin PBXSourcesBuildPhase section */
282 | 39C0608014F7736C009907AE /* Sources */ = {
283 | isa = PBXSourcesBuildPhase;
284 | buildActionMask = 2147483647;
285 | files = (
286 | 39C0609714F7736D009907AE /* main.m in Sources */,
287 | 39C0609B14F7736D009907AE /* XcfAppDelegate.m in Sources */,
288 | 39C0609E14F7736E009907AE /* SnapNotes.xcdatamodeld in Sources */,
289 | 39C060C114F77742009907AE /* NotesTableView.m in Sources */,
290 | 39C060C414F7779A009907AE /* NotesLine.m in Sources */,
291 | );
292 | runOnlyForDeploymentPostprocessing = 0;
293 | };
294 | 39C0609F14F7736E009907AE /* Sources */ = {
295 | isa = PBXSourcesBuildPhase;
296 | buildActionMask = 2147483647;
297 | files = (
298 | 39C060B414F7736F009907AE /* SnapNotesTests.m in Sources */,
299 | );
300 | runOnlyForDeploymentPostprocessing = 0;
301 | };
302 | /* End PBXSourcesBuildPhase section */
303 |
304 | /* Begin PBXTargetDependency section */
305 | 39C060AB14F7736E009907AE /* PBXTargetDependency */ = {
306 | isa = PBXTargetDependency;
307 | target = 39C0608314F7736C009907AE /* SnapNotes */;
308 | targetProxy = 39C060AA14F7736E009907AE /* PBXContainerItemProxy */;
309 | };
310 | /* End PBXTargetDependency section */
311 |
312 | /* Begin PBXVariantGroup section */
313 | 39C0609314F7736D009907AE /* InfoPlist.strings */ = {
314 | isa = PBXVariantGroup;
315 | children = (
316 | 39C0609414F7736D009907AE /* en */,
317 | );
318 | name = InfoPlist.strings;
319 | sourceTree = "";
320 | };
321 | 39C060AF14F7736E009907AE /* InfoPlist.strings */ = {
322 | isa = PBXVariantGroup;
323 | children = (
324 | 39C060B014F7736E009907AE /* en */,
325 | );
326 | name = InfoPlist.strings;
327 | sourceTree = "";
328 | };
329 | /* End PBXVariantGroup section */
330 |
331 | /* Begin XCBuildConfiguration section */
332 | 39C060B514F7736F009907AE /* Debug */ = {
333 | isa = XCBuildConfiguration;
334 | buildSettings = {
335 | ALWAYS_SEARCH_USER_PATHS = NO;
336 | ARCHS = "$(ARCHS_STANDARD_32_BIT)";
337 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
338 | COPY_PHASE_STRIP = NO;
339 | GCC_C_LANGUAGE_STANDARD = gnu99;
340 | GCC_DYNAMIC_NO_PIC = NO;
341 | GCC_OPTIMIZATION_LEVEL = 0;
342 | GCC_PREPROCESSOR_DEFINITIONS = (
343 | "DEBUG=1",
344 | "$(inherited)",
345 | );
346 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
347 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
348 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
349 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
350 | GCC_WARN_UNUSED_VARIABLE = YES;
351 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
352 | SDKROOT = iphoneos;
353 | TARGETED_DEVICE_FAMILY = "1,2";
354 | };
355 | name = Debug;
356 | };
357 | 39C060B614F7736F009907AE /* Release */ = {
358 | isa = XCBuildConfiguration;
359 | buildSettings = {
360 | ALWAYS_SEARCH_USER_PATHS = NO;
361 | ARCHS = "$(ARCHS_STANDARD_32_BIT)";
362 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
363 | COPY_PHASE_STRIP = YES;
364 | GCC_C_LANGUAGE_STANDARD = gnu99;
365 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
366 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
367 | GCC_WARN_ABOUT_RETURN_TYPE = YES;
368 | GCC_WARN_UNUSED_VARIABLE = YES;
369 | IPHONEOS_DEPLOYMENT_TARGET = 5.0;
370 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
371 | SDKROOT = iphoneos;
372 | TARGETED_DEVICE_FAMILY = "1,2";
373 | VALIDATE_PRODUCT = YES;
374 | };
375 | name = Release;
376 | };
377 | 39C060B814F7736F009907AE /* Debug */ = {
378 | isa = XCBuildConfiguration;
379 | buildSettings = {
380 | CLANG_ENABLE_OBJC_ARC = YES;
381 | CLANG_WARN_OBJCPP_ARC_ABI = YES;
382 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
383 | GCC_PREFIX_HEADER = "SnapNotes/SnapNotes-Prefix.pch";
384 | INFOPLIST_FILE = "SnapNotes/SnapNotes-Info.plist";
385 | PRODUCT_NAME = "$(TARGET_NAME)";
386 | WRAPPER_EXTENSION = app;
387 | };
388 | name = Debug;
389 | };
390 | 39C060B914F7736F009907AE /* Release */ = {
391 | isa = XCBuildConfiguration;
392 | buildSettings = {
393 | CLANG_ENABLE_OBJC_ARC = YES;
394 | CLANG_WARN_OBJCPP_ARC_ABI = YES;
395 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
396 | GCC_PREFIX_HEADER = "SnapNotes/SnapNotes-Prefix.pch";
397 | INFOPLIST_FILE = "SnapNotes/SnapNotes-Info.plist";
398 | PRODUCT_NAME = "$(TARGET_NAME)";
399 | WRAPPER_EXTENSION = app;
400 | };
401 | name = Release;
402 | };
403 | 39C060BB14F7736F009907AE /* Debug */ = {
404 | isa = XCBuildConfiguration;
405 | buildSettings = {
406 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SnapNotes.app/SnapNotes";
407 | FRAMEWORK_SEARCH_PATHS = (
408 | "$(SDKROOT)/Developer/Library/Frameworks",
409 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks",
410 | );
411 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
412 | GCC_PREFIX_HEADER = "SnapNotes/SnapNotes-Prefix.pch";
413 | INFOPLIST_FILE = "SnapNotesTests/SnapNotesTests-Info.plist";
414 | PRODUCT_NAME = "$(TARGET_NAME)";
415 | TEST_HOST = "$(BUNDLE_LOADER)";
416 | WRAPPER_EXTENSION = octest;
417 | };
418 | name = Debug;
419 | };
420 | 39C060BC14F7736F009907AE /* Release */ = {
421 | isa = XCBuildConfiguration;
422 | buildSettings = {
423 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SnapNotes.app/SnapNotes";
424 | FRAMEWORK_SEARCH_PATHS = (
425 | "$(SDKROOT)/Developer/Library/Frameworks",
426 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks",
427 | );
428 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
429 | GCC_PREFIX_HEADER = "SnapNotes/SnapNotes-Prefix.pch";
430 | INFOPLIST_FILE = "SnapNotesTests/SnapNotesTests-Info.plist";
431 | PRODUCT_NAME = "$(TARGET_NAME)";
432 | TEST_HOST = "$(BUNDLE_LOADER)";
433 | WRAPPER_EXTENSION = octest;
434 | };
435 | name = Release;
436 | };
437 | /* End XCBuildConfiguration section */
438 |
439 | /* Begin XCConfigurationList section */
440 | 39C0607E14F7736C009907AE /* Build configuration list for PBXProject "SnapNotes" */ = {
441 | isa = XCConfigurationList;
442 | buildConfigurations = (
443 | 39C060B514F7736F009907AE /* Debug */,
444 | 39C060B614F7736F009907AE /* Release */,
445 | );
446 | defaultConfigurationIsVisible = 0;
447 | defaultConfigurationName = Release;
448 | };
449 | 39C060B714F7736F009907AE /* Build configuration list for PBXNativeTarget "SnapNotes" */ = {
450 | isa = XCConfigurationList;
451 | buildConfigurations = (
452 | 39C060B814F7736F009907AE /* Debug */,
453 | 39C060B914F7736F009907AE /* Release */,
454 | );
455 | defaultConfigurationIsVisible = 0;
456 | };
457 | 39C060BA14F7736F009907AE /* Build configuration list for PBXNativeTarget "SnapNotesTests" */ = {
458 | isa = XCConfigurationList;
459 | buildConfigurations = (
460 | 39C060BB14F7736F009907AE /* Debug */,
461 | 39C060BC14F7736F009907AE /* Release */,
462 | );
463 | defaultConfigurationIsVisible = 0;
464 | };
465 | /* End XCConfigurationList section */
466 |
467 | /* Begin XCVersionGroup section */
468 | 39C0609C14F7736E009907AE /* SnapNotes.xcdatamodeld */ = {
469 | isa = XCVersionGroup;
470 | children = (
471 | 39C0609D14F7736E009907AE /* SnapNotes.xcdatamodel */,
472 | );
473 | currentVersion = 39C0609D14F7736E009907AE /* SnapNotes.xcdatamodel */;
474 | path = SnapNotes.xcdatamodeld;
475 | sourceTree = "";
476 | versionGroupType = wrapper.xcdatamodel;
477 | };
478 | /* End XCVersionGroup section */
479 | };
480 | rootObject = 39C0607B14F7736C009907AE /* Project object */;
481 | }
482 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/SnapNotes/SnapNotes.xcodeproj/project.xcworkspace/xcuserdata/march.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/SnapNotes.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
14 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
32 |
38 |
39 |
40 |
41 |
42 |
48 |
49 |
50 |
51 |
59 |
60 |
66 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
84 |
85 |
86 |
87 |
89 |
90 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes.xcodeproj/xcuserdata/march.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SnapNotes.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 39C0608314F7736C009907AE
16 |
17 | primary
18 |
19 |
20 | 39C060A314F7736E009907AE
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/SnapNotes/SnapNotes/.DS_Store
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/NotesLine.h:
--------------------------------------------------------------------------------
1 | //
2 | // NotesLine.h
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NotesLine : NSObject {
12 | NSMutableData
13 | }
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/NotesLine.m:
--------------------------------------------------------------------------------
1 | //
2 | // NotesLine.m
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "NotesLine.h"
10 |
11 | @implementation NotesLine
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/NotesTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // NotesTableView.h
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NotesTableView : UITableViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/NotesTableView.m:
--------------------------------------------------------------------------------
1 | //
2 | // NotesTableView.m
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "NotesTableView.h"
10 |
11 |
12 | @implementation NotesTableView
13 |
14 | - (id)initWithStyle:(UITableViewStyle)style
15 | {
16 | self = [super initWithStyle:style];
17 | if (self) {
18 | // Custom initialization
19 | }
20 | return self;
21 | }
22 |
23 | - (void)didReceiveMemoryWarning
24 | {
25 | // Releases the view if it doesn't have a superview.
26 | [super didReceiveMemoryWarning];
27 |
28 | // Release any cached data, images, etc that aren't in use.
29 | }
30 |
31 | #pragma mark - View lifecycle
32 |
33 | - (void)viewDidLoad
34 | {
35 | [super viewDidLoad];
36 |
37 | // Uncomment the following line to preserve selection between presentations.
38 | // self.clearsSelectionOnViewWillAppear = NO;
39 |
40 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
41 | // self.navigationItem.rightBarButtonItem = self.editButtonItem;
42 | }
43 |
44 | - (void)viewDidUnload
45 | {
46 | [super viewDidUnload];
47 | // Release any retained subviews of the main view.
48 | // e.g. self.myOutlet = nil;
49 | }
50 |
51 | - (void)viewWillAppear:(BOOL)animated
52 | {
53 | [super viewWillAppear:animated];
54 | }
55 |
56 | - (void)viewDidAppear:(BOOL)animated
57 | {
58 | [super viewDidAppear:animated];
59 | }
60 |
61 | - (void)viewWillDisappear:(BOOL)animated
62 | {
63 | [super viewWillDisappear:animated];
64 | }
65 |
66 | - (void)viewDidDisappear:(BOOL)animated
67 | {
68 | [super viewDidDisappear:animated];
69 | }
70 |
71 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
72 | {
73 | // Return YES for supported orientations
74 | return (interfaceOrientation == UIInterfaceOrientationPortrait);
75 | }
76 |
77 | #pragma mark - Table view data source
78 |
79 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
80 | {
81 | #warning Potentially incomplete method implementation.
82 | // Return the number of sections.
83 | return 0;
84 | }
85 |
86 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
87 | {
88 | #warning Incomplete method implementation.
89 | // Return the number of rows in the section.
90 | return 0;
91 | }
92 |
93 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
94 | {
95 | static NSString *CellIdentifier = @"Cell";
96 |
97 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
98 | if (cell == nil) {
99 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
100 | }
101 |
102 | // Configure the cell...
103 |
104 | return cell;
105 | }
106 |
107 | /*
108 | // Override to support conditional editing of the table view.
109 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
110 | {
111 | // Return NO if you do not want the specified item to be editable.
112 | return YES;
113 | }
114 | */
115 |
116 | /*
117 | // Override to support editing the table view.
118 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
119 | {
120 | if (editingStyle == UITableViewCellEditingStyleDelete) {
121 | // Delete the row from the data source
122 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
123 | }
124 | else if (editingStyle == UITableViewCellEditingStyleInsert) {
125 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
126 | }
127 | }
128 | */
129 |
130 | /*
131 | // Override to support rearranging the table view.
132 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
133 | {
134 | }
135 | */
136 |
137 | /*
138 | // Override to support conditional rearranging of the table view.
139 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
140 | {
141 | // Return NO if you do not want the item to be re-orderable.
142 | return YES;
143 | }
144 | */
145 |
146 | #pragma mark - Table view delegate
147 |
148 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
149 | {
150 | // Navigation logic may go here. Create and push another view controller.
151 | /*
152 | <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
153 | // ...
154 | // Pass the selected object to the new view controller.
155 | [self.navigationController pushViewController:detailViewController animated:YES];
156 | */
157 | }
158 |
159 | @end
160 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/SnapNotes-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIconFiles
12 |
13 | CFBundleIdentifier
14 | xiachufang.${PRODUCT_NAME:rfc1034identifier}
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | ${PRODUCT_NAME}
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | 1.0
23 | CFBundleSignature
24 | ????
25 | CFBundleVersion
26 | 1.0
27 | LSRequiresIPhoneOS
28 |
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/SnapNotes-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'SnapNotes' target in the 'SnapNotes' project
3 | //
4 |
5 | #import
6 |
7 | #ifndef __IPHONE_3_0
8 | #warning "This project uses features only available in iOS SDK 3.0 and later."
9 | #endif
10 |
11 | #ifdef __OBJC__
12 | #import
13 | #import
14 | #import
15 | #endif
16 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/SnapNotes.xcdatamodeld/.xccurrentversion:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | _XCCurrentVersionName
6 | SnapNotes.xcdatamodel
7 |
8 |
9 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/SnapNotes.xcdatamodeld/SnapNotes.xcdatamodel/contents:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/XcfAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // XcfAppDelegate.h
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface XcfAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
16 | @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
17 | @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
18 |
19 | - (void)saveContext;
20 | - (NSURL *)applicationDocumentsDirectory;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/XcfAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // XcfAppDelegate.m
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "XcfAppDelegate.h"
10 |
11 | @implementation XcfAppDelegate
12 |
13 | @synthesize window = _window;
14 | @synthesize managedObjectContext = __managedObjectContext;
15 | @synthesize managedObjectModel = __managedObjectModel;
16 | @synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
19 | {
20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
21 | // Override point for customization after application launch.
22 | self.window.backgroundColor = [UIColor whiteColor];
23 | [self.window makeKeyAndVisible];
24 | return YES;
25 | }
26 |
27 | - (void)applicationWillResignActive:(UIApplication *)application
28 | {
29 | /*
30 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
31 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
32 | */
33 | }
34 |
35 | - (void)applicationDidEnterBackground:(UIApplication *)application
36 | {
37 | /*
38 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
39 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
40 | */
41 | }
42 |
43 | - (void)applicationWillEnterForeground:(UIApplication *)application
44 | {
45 | /*
46 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
47 | */
48 | }
49 |
50 | - (void)applicationDidBecomeActive:(UIApplication *)application
51 | {
52 | /*
53 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
54 | */
55 | }
56 |
57 | - (void)applicationWillTerminate:(UIApplication *)application
58 | {
59 | // Saves changes in the application's managed object context before the application terminates.
60 | [self saveContext];
61 | }
62 |
63 | - (void)saveContext
64 | {
65 | NSError *error = nil;
66 | NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
67 | if (managedObjectContext != nil)
68 | {
69 | if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
70 | {
71 | /*
72 | Replace this implementation with code to handle the error appropriately.
73 |
74 | abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
75 | */
76 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
77 | abort();
78 | }
79 | }
80 | }
81 |
82 | #pragma mark - Core Data stack
83 |
84 | /**
85 | Returns the managed object context for the application.
86 | If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
87 | */
88 | - (NSManagedObjectContext *)managedObjectContext
89 | {
90 | if (__managedObjectContext != nil)
91 | {
92 | return __managedObjectContext;
93 | }
94 |
95 | NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
96 | if (coordinator != nil)
97 | {
98 | __managedObjectContext = [[NSManagedObjectContext alloc] init];
99 | [__managedObjectContext setPersistentStoreCoordinator:coordinator];
100 | }
101 | return __managedObjectContext;
102 | }
103 |
104 | /**
105 | Returns the managed object model for the application.
106 | If the model doesn't already exist, it is created from the application's model.
107 | */
108 | - (NSManagedObjectModel *)managedObjectModel
109 | {
110 | if (__managedObjectModel != nil)
111 | {
112 | return __managedObjectModel;
113 | }
114 | NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SnapNotes" withExtension:@"momd"];
115 | __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
116 | return __managedObjectModel;
117 | }
118 |
119 | /**
120 | Returns the persistent store coordinator for the application.
121 | If the coordinator doesn't already exist, it is created and the application's store added to it.
122 | */
123 | - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
124 | {
125 | if (__persistentStoreCoordinator != nil)
126 | {
127 | return __persistentStoreCoordinator;
128 | }
129 |
130 | NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"SnapNotes.sqlite"];
131 |
132 | NSError *error = nil;
133 | __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
134 | if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
135 | {
136 | /*
137 | Replace this implementation with code to handle the error appropriately.
138 |
139 | abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
140 |
141 | Typical reasons for an error here include:
142 | * The persistent store is not accessible;
143 | * The schema for the persistent store is incompatible with current managed object model.
144 | Check the error message to determine what the actual problem was.
145 |
146 |
147 | If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
148 |
149 | If you encounter schema incompatibility errors during development, you can reduce their frequency by:
150 | * Simply deleting the existing store:
151 | [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
152 |
153 | * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
154 | [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
155 |
156 | Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
157 |
158 | */
159 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
160 | abort();
161 | }
162 |
163 | return __persistentStoreCoordinator;
164 | }
165 |
166 | #pragma mark - Application's Documents directory
167 |
168 | /**
169 | Returns the URL to the application's Documents directory.
170 | */
171 | - (NSURL *)applicationDocumentsDirectory
172 | {
173 | return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
174 | }
175 |
176 | @end
177 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotes/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // SnapNotes
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "XcfAppDelegate.h"
12 |
13 | int main(int argc, char *argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([XcfAppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotesTests/SnapNotesTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | xiachufang.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotesTests/SnapNotesTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // SnapNotesTests.h
3 | // SnapNotesTests
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SnapNotesTests : SenTestCase
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotesTests/SnapNotesTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // SnapNotesTests.m
3 | // SnapNotesTests
4 | //
5 | // Created by March Liu on 12-2-24.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "SnapNotesTests.h"
10 |
11 | @implementation SnapNotesTests
12 |
13 | - (void)setUp
14 | {
15 | [super setUp];
16 |
17 | // Set-up code here.
18 | }
19 |
20 | - (void)tearDown
21 | {
22 | // Tear-down code here.
23 |
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample
28 | {
29 | STFail(@"Unit tests are not implemented yet in SnapNotesTests");
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/objc/SnapNotes/SnapNotesTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/objc/SortUsingDescriptors.md:
--------------------------------------------------------------------------------
1 | Objective C 的容器排序
2 | ======================
3 |
4 | 描述符
5 | -----------------
6 |
7 | 下例代码是我从一段单元测试中摘出来的,背景可以参见 LevenshteinDistance 的代码。生产环境的 LevenshteinDistance 算法跟黑科技仓库的一致,只是多了一个很简陋的 buffer,减少内存碎片。所以黑科技的代码是静态方法,这里用的实例方法,但是这个差异不影响这里的功能演示。
8 |
9 | 测试框架用的是 GHUnitTest,这个框架的使用可以在它的 github 仓库中查阅文档,以为黑科技也许也会放出相关的例子。
10 |
11 | 这里重点演示的是使用 NSSortDescriptor 对 NSMutableArray 对象排序,这个排序代码看起来很像 SQL 的 order by 语法。
12 |
13 | 数据源是一组常见的邮箱域名和一组故意写错的无效域名(例如 gmail.com 错写成 gmail。com 这种)。然后由字符串相似度算法计算出每个错误的域名,它对应的正确内容可能是哪一个。
14 |
15 |
16 | {
17 | -(void)testHostsAndSort {
18 | XcfLevenshteinDitstance *ruler = [[XcfLevenshteinDitstance alloc] initWithBufferSize:4096];
19 | NSArray *hosts = [data objectForKey:@"host"];
20 | NSMutableArray *table = [[NSMutableArray alloc] initWithCapacity:[hosts count]^2];
21 |
22 | for (NSString *source in hosts) {
23 | for (NSString *target in hosts) {
24 | NSDictionary *record = [[NSDictionary alloc] initWithObjectsAndKeys:source, @"source",
25 | target, @"target",
26 | [[NSNumber alloc] initWithInt:[ruler fromSource:source toTarget:target]], @"distance", nil];
27 | [table addObject:record];
28 | }
29 | NSArray *descriptors = [[NSArray alloc] initWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"source" ascending:YES],
30 | [NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES], nil];
31 | [table sortUsingDescriptors:descriptors];
32 | }
33 |
34 | for (NSDictionary *record in table) {
35 | NSString *source = [record objectForKey:@"source"];
36 | NSString *target = [record objectForKey:@"target"];
37 | NSNumber *value = [record objectForKey:@"distance"];
38 | GHTestLog(@"from %@ to %@ is %@", source, target, value);
39 | if ([source isEqualToString:target]) {
40 | GHAssertTrue([value intValue]==0, @"from %@ to itself expect zero but got %@", source, value);
41 | }
42 | }
43 |
44 | for (NSDictionary *record in table) {
45 | NSNumber *distance = [record objectForKey:@"distance"];
46 | [record release];
47 | [distance release];
48 | }
49 | [table release];
50 | }
51 |
52 | -(void)testHostsGuess {
53 | XcfLevenshteinDitstance *ruler = [[XcfLevenshteinDitstance alloc] initWithBufferSize:4096];
54 | NSArray *hosts = [data objectForKey:@"host"];
55 | NSArray *invalid = [data objectForKey:@"invalid"];
56 | NSMutableArray *table = [[NSMutableArray alloc] initWithCapacity:[hosts count]*[invalid count]];
57 |
58 | for (NSString *source in invalid) {
59 | for (NSString *target in hosts) {
60 | NSDictionary *record = [[NSDictionary alloc] initWithObjectsAndKeys:source, @"source",
61 | target, @"target",
62 | [[NSNumber alloc] initWithInt:[ruler fromSource:source toTarget:target]], @"distance", nil];
63 | [table addObject:record];
64 | }
65 | NSArray *descriptors = [[NSArray alloc] initWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"source" ascending:YES],
66 | [NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES], nil];
67 | [table sortUsingDescriptors:descriptors];
68 | }
69 |
70 | for (NSDictionary *record in table) {
71 | NSString *source = [record objectForKey:@"source"];
72 | NSString *target = [record objectForKey:@"target"];
73 | NSNumber *value = [record objectForKey:@"distance"];
74 | GHTestLog(@"from %@ to %@ is %@", source, target, value);
75 | GHAssertTrue([value intValue]>0, @"from %@ to %@ should more than zero", source, target);
76 | }
77 |
78 | for (NSDictionary *record in table) {
79 | NSNumber *distance = [record objectForKey:@"distance"];
80 | [record release];
81 | [distance release];
82 | }
83 | [table release];
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/objc/first/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/.DS_Store
--------------------------------------------------------------------------------
/objc/first/slide/.#Untitled:
--------------------------------------------------------------------------------
1 | march@zeromm.local.81739
--------------------------------------------------------------------------------
/objc/first/slide/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/.DS_Store
--------------------------------------------------------------------------------
/objc/first/slide/Untitled:
--------------------------------------------------------------------------------
1 | Caption: Mac OS 的软件正在向 iOS 风格转变
--------------------------------------------------------------------------------
/objc/first/slide/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/.DS_Store
--------------------------------------------------------------------------------
/objc/first/slide/images/iPad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/iPad.png
--------------------------------------------------------------------------------
/objc/first/slide/images/iPhone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/iPhone.png
--------------------------------------------------------------------------------
/objc/first/slide/images/iPod.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/iPod.png
--------------------------------------------------------------------------------
/objc/first/slide/images/iossoft.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/iossoft.jpg
--------------------------------------------------------------------------------
/objc/first/slide/images/mac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/mac.png
--------------------------------------------------------------------------------
/objc/first/slide/images/macsoft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/images/macsoft.png
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.aux:
--------------------------------------------------------------------------------
1 | \relax
2 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
3 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
4 | \global\let\oldcontentsline\contentsline
5 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
6 | \global\let\oldnewlabel\newlabel
7 | \gdef\newlabel#1#2{\newlabelxx{#1}#2}
8 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
9 | \AtEndDocument{\ifx\hyper@anchor\@undefined
10 | \let\contentsline\oldcontentsline
11 | \let\newlabel\oldnewlabel
12 | \fi}
13 | \fi}
14 | \global\let\hyper@last\relax
15 | \gdef\HyperFirstAtBeginDocument#1{#1}
16 | \providecommand*\HyPL@Entry[1]{}
17 | \HyPL@Entry{0<
>}
18 | \@writefile{toc}{\beamer@endinputifotherversion {3.10pt}}
19 | \@writefile{nav}{\beamer@endinputifotherversion {3.10pt}}
20 | \@writefile{nav}{\headcommand {\slideentry {0}{0}{1}{1/1}{}{0}}}
21 | \@writefile{nav}{\headcommand {\beamer@framepages {1}{1}}}
22 | \HyPL@Entry{1<>}
23 | \@writefile{nav}{\headcommand {\slideentry {0}{0}{2}{2/2}{}{0}}}
24 | \@writefile{nav}{\headcommand {\beamer@framepages {2}{2}}}
25 | \HyPL@Entry{2<>}
26 | \@writefile{toc}{\beamer@sectionintoc {1}{Apple 硬件体系}{3}{0}{1}}
27 | \@writefile{nav}{\headcommand {\sectionentry {1}{Apple 硬件体系}{3}{Apple 硬件体系}{0}}}
28 | \@writefile{nav}{\headcommand {\beamer@sectionpages {1}{2}}}
29 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {1}{2}}}
30 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{3}{3/3}{}{0}}}
31 | \@writefile{nav}{\headcommand {\beamer@framepages {3}{3}}}
32 | \HyPL@Entry{3<>}
33 | \newlabel{fig:iPhone}{{1}{4}{Apple 硬件体系\relax }{Doc-Start}{}}
34 | \@writefile{snm}{\beamer@slide {fig:iPhone}{4}}
35 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{4}{4/4}{}{0}}}
36 | \@writefile{nav}{\headcommand {\beamer@framepages {4}{4}}}
37 | \HyPL@Entry{4<>}
38 | \newlabel{fig:iPod}{{2}{5}{Apple 硬件体系\relax }{Doc-Start}{}}
39 | \@writefile{snm}{\beamer@slide {fig:iPod}{5}}
40 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{5}{5/5}{}{0}}}
41 | \@writefile{nav}{\headcommand {\beamer@framepages {5}{5}}}
42 | \HyPL@Entry{5<>}
43 | \newlabel{fig:iPad}{{6}{6}{Apple 硬件体系\relax }{Doc-Start}{}}
44 | \@writefile{snm}{\beamer@slide {fig:iPad}{6}}
45 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{6}{6/6}{}{0}}}
46 | \@writefile{nav}{\headcommand {\beamer@framepages {6}{6}}}
47 | \HyPL@Entry{6<>}
48 | \newlabel{fig:mac}{{7}{7}{Apple 硬件体系\relax }{Doc-Start}{}}
49 | \@writefile{snm}{\beamer@slide {fig:mac}{7}}
50 | \newlabel{fig:Mac}{{3}{7}{Apple 硬件体系\relax }{Doc-Start}{}}
51 | \@writefile{snm}{\beamer@slide {fig:Mac}{7}}
52 | \@writefile{nav}{\headcommand {\slideentry {1}{0}{7}{7/7}{}{0}}}
53 | \@writefile{nav}{\headcommand {\beamer@framepages {7}{7}}}
54 | \HyPL@Entry{7<>}
55 | \@writefile{toc}{\beamer@sectionintoc {2}{Apple 的软件体系}{8}{0}{2}}
56 | \@writefile{nav}{\headcommand {\sectionentry {2}{Apple 的软件体系}{8}{Apple 的软件体系}{0}}}
57 | \@writefile{nav}{\headcommand {\beamer@sectionpages {3}{7}}}
58 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {3}{7}}}
59 | \@writefile{nav}{\headcommand {\slideentry {2}{0}{8}{8/8}{}{0}}}
60 | \@writefile{nav}{\headcommand {\beamer@framepages {8}{8}}}
61 | \HyPL@Entry{8<>}
62 | \newlabel{fig:iossoft}{{4}{9}{Apple 的软件体系\relax }{Doc-Start}{}}
63 | \@writefile{snm}{\beamer@slide {fig:iossoft}{9}}
64 | \@writefile{nav}{\headcommand {\slideentry {2}{0}{9}{9/9}{}{0}}}
65 | \@writefile{nav}{\headcommand {\beamer@framepages {9}{9}}}
66 | \HyPL@Entry{9<>}
67 | \newlabel{fig:MacSoft}{{5}{10}{Apple 的软件体系\relax }{Doc-Start}{}}
68 | \@writefile{snm}{\beamer@slide {fig:MacSoft}{10}}
69 | \@writefile{nav}{\headcommand {\slideentry {2}{0}{10}{10/10}{}{0}}}
70 | \@writefile{nav}{\headcommand {\beamer@framepages {10}{10}}}
71 | \HyPL@Entry{10<>}
72 | \@writefile{toc}{\beamer@sectionintoc {3}{Apple 体系开发技术}{11}{0}{3}}
73 | \@writefile{nav}{\headcommand {\sectionentry {3}{Apple 体系开发技术}{11}{Apple 体系开发技术}{0}}}
74 | \@writefile{nav}{\headcommand {\beamer@sectionpages {8}{10}}}
75 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {8}{10}}}
76 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{11}{11/11}{}{0}}}
77 | \@writefile{nav}{\headcommand {\beamer@framepages {11}{11}}}
78 | \HyPL@Entry{11<>}
79 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{12}{12/12}{}{0}}}
80 | \@writefile{nav}{\headcommand {\beamer@framepages {12}{12}}}
81 | \HyPL@Entry{12<>}
82 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{13}{13/13}{}{0}}}
83 | \@writefile{nav}{\headcommand {\beamer@framepages {13}{13}}}
84 | \HyPL@Entry{13<>}
85 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{14}{14/14}{}{0}}}
86 | \@writefile{nav}{\headcommand {\beamer@framepages {14}{14}}}
87 | \HyPL@Entry{14<>}
88 | \@writefile{nav}{\headcommand {\slideentry {3}{0}{15}{15/15}{}{0}}}
89 | \@writefile{nav}{\headcommand {\beamer@framepages {15}{15}}}
90 | \HyPL@Entry{15<>}
91 | \@writefile{toc}{\beamer@sectionintoc {4}{操作演示阶段}{16}{0}{4}}
92 | \@writefile{nav}{\headcommand {\sectionentry {4}{操作演示阶段}{16}{操作演示阶段}{0}}}
93 | \@writefile{nav}{\headcommand {\beamer@sectionpages {11}{15}}}
94 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {11}{15}}}
95 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{16}{16/16}{}{0}}}
96 | \@writefile{nav}{\headcommand {\beamer@framepages {16}{16}}}
97 | \HyPL@Entry{16<>}
98 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{17}{17/17}{}{0}}}
99 | \@writefile{nav}{\headcommand {\beamer@framepages {17}{17}}}
100 | \HyPL@Entry{17<>}
101 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{18}{18/18}{}{0}}}
102 | \@writefile{nav}{\headcommand {\beamer@framepages {18}{18}}}
103 | \HyPL@Entry{18<>}
104 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{19}{19/19}{}{0}}}
105 | \@writefile{nav}{\headcommand {\beamer@framepages {19}{19}}}
106 | \HyPL@Entry{19<>}
107 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{20}{20/20}{}{0}}}
108 | \@writefile{nav}{\headcommand {\beamer@framepages {20}{20}}}
109 | \HyPL@Entry{20<>}
110 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{21}{21/21}{}{0}}}
111 | \@writefile{nav}{\headcommand {\beamer@framepages {21}{21}}}
112 | \HyPL@Entry{21<>}
113 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{22}{22/22}{}{0}}}
114 | \@writefile{nav}{\headcommand {\beamer@framepages {22}{22}}}
115 | \HyPL@Entry{22<>}
116 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{23}{23/23}{}{0}}}
117 | \@writefile{nav}{\headcommand {\beamer@framepages {23}{23}}}
118 | \HyPL@Entry{23<>}
119 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{24}{24/24}{}{0}}}
120 | \@writefile{nav}{\headcommand {\beamer@framepages {24}{24}}}
121 | \HyPL@Entry{24<>}
122 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{25}{25/25}{}{0}}}
123 | \@writefile{nav}{\headcommand {\beamer@framepages {25}{25}}}
124 | \HyPL@Entry{25<>}
125 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{26}{26/26}{}{0}}}
126 | \@writefile{nav}{\headcommand {\beamer@framepages {26}{26}}}
127 | \HyPL@Entry{26<>}
128 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{27}{27/27}{}{0}}}
129 | \@writefile{nav}{\headcommand {\beamer@framepages {27}{27}}}
130 | \HyPL@Entry{27<>}
131 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{28}{28/28}{}{0}}}
132 | \@writefile{nav}{\headcommand {\beamer@framepages {28}{28}}}
133 | \HyPL@Entry{28<>}
134 | \@writefile{nav}{\headcommand {\slideentry {4}{0}{29}{29/29}{}{0}}}
135 | \@writefile{nav}{\headcommand {\beamer@framepages {29}{29}}}
136 | \HyPL@Entry{29<>}
137 | \@writefile{toc}{\beamer@sectionintoc {5}{学习 Apple 开发体系}{30}{0}{5}}
138 | \@writefile{nav}{\headcommand {\sectionentry {5}{学习 Apple 开发体系}{30}{学习 Apple 开发体系}{0}}}
139 | \@writefile{nav}{\headcommand {\beamer@sectionpages {16}{29}}}
140 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {16}{29}}}
141 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{30}{30/30}{}{0}}}
142 | \@writefile{nav}{\headcommand {\beamer@framepages {30}{30}}}
143 | \HyPL@Entry{30<>}
144 | \@writefile{nav}{\headcommand {\slideentry {5}{0}{31}{31/31}{}{0}}}
145 | \@writefile{nav}{\headcommand {\beamer@framepages {31}{31}}}
146 | \@writefile{nav}{\headcommand {\beamer@partpages {1}{31}}}
147 | \@writefile{nav}{\headcommand {\beamer@subsectionpages {30}{31}}}
148 | \@writefile{nav}{\headcommand {\beamer@sectionpages {30}{31}}}
149 | \@writefile{nav}{\headcommand {\beamer@documentpages {31}}}
150 | \@writefile{nav}{\headcommand {\def \inserttotalframenumber {31}}}
151 |
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.nav:
--------------------------------------------------------------------------------
1 | \beamer@endinputifotherversion {3.10pt}
2 | \headcommand {\slideentry {0}{0}{1}{1/1}{}{0}}
3 | \headcommand {\beamer@framepages {1}{1}}
4 | \headcommand {\slideentry {0}{0}{2}{2/2}{}{0}}
5 | \headcommand {\beamer@framepages {2}{2}}
6 | \headcommand {\sectionentry {1}{Apple 硬件体系}{3}{Apple 硬件体系}{0}}
7 | \headcommand {\beamer@sectionpages {1}{2}}
8 | \headcommand {\beamer@subsectionpages {1}{2}}
9 | \headcommand {\slideentry {1}{0}{3}{3/3}{}{0}}
10 | \headcommand {\beamer@framepages {3}{3}}
11 | \headcommand {\slideentry {1}{0}{4}{4/4}{}{0}}
12 | \headcommand {\beamer@framepages {4}{4}}
13 | \headcommand {\slideentry {1}{0}{5}{5/5}{}{0}}
14 | \headcommand {\beamer@framepages {5}{5}}
15 | \headcommand {\slideentry {1}{0}{6}{6/6}{}{0}}
16 | \headcommand {\beamer@framepages {6}{6}}
17 | \headcommand {\slideentry {1}{0}{7}{7/7}{}{0}}
18 | \headcommand {\beamer@framepages {7}{7}}
19 | \headcommand {\sectionentry {2}{Apple 的软件体系}{8}{Apple 的软件体系}{0}}
20 | \headcommand {\beamer@sectionpages {3}{7}}
21 | \headcommand {\beamer@subsectionpages {3}{7}}
22 | \headcommand {\slideentry {2}{0}{8}{8/8}{}{0}}
23 | \headcommand {\beamer@framepages {8}{8}}
24 | \headcommand {\slideentry {2}{0}{9}{9/9}{}{0}}
25 | \headcommand {\beamer@framepages {9}{9}}
26 | \headcommand {\slideentry {2}{0}{10}{10/10}{}{0}}
27 | \headcommand {\beamer@framepages {10}{10}}
28 | \headcommand {\sectionentry {3}{Apple 体系开发技术}{11}{Apple 体系开发技术}{0}}
29 | \headcommand {\beamer@sectionpages {8}{10}}
30 | \headcommand {\beamer@subsectionpages {8}{10}}
31 | \headcommand {\slideentry {3}{0}{11}{11/11}{}{0}}
32 | \headcommand {\beamer@framepages {11}{11}}
33 | \headcommand {\slideentry {3}{0}{12}{12/12}{}{0}}
34 | \headcommand {\beamer@framepages {12}{12}}
35 | \headcommand {\slideentry {3}{0}{13}{13/13}{}{0}}
36 | \headcommand {\beamer@framepages {13}{13}}
37 | \headcommand {\slideentry {3}{0}{14}{14/14}{}{0}}
38 | \headcommand {\beamer@framepages {14}{14}}
39 | \headcommand {\slideentry {3}{0}{15}{15/15}{}{0}}
40 | \headcommand {\beamer@framepages {15}{15}}
41 | \headcommand {\sectionentry {4}{操作演示阶段}{16}{操作演示阶段}{0}}
42 | \headcommand {\beamer@sectionpages {11}{15}}
43 | \headcommand {\beamer@subsectionpages {11}{15}}
44 | \headcommand {\slideentry {4}{0}{16}{16/16}{}{0}}
45 | \headcommand {\beamer@framepages {16}{16}}
46 | \headcommand {\slideentry {4}{0}{17}{17/17}{}{0}}
47 | \headcommand {\beamer@framepages {17}{17}}
48 | \headcommand {\slideentry {4}{0}{18}{18/18}{}{0}}
49 | \headcommand {\beamer@framepages {18}{18}}
50 | \headcommand {\slideentry {4}{0}{19}{19/19}{}{0}}
51 | \headcommand {\beamer@framepages {19}{19}}
52 | \headcommand {\slideentry {4}{0}{20}{20/20}{}{0}}
53 | \headcommand {\beamer@framepages {20}{20}}
54 | \headcommand {\slideentry {4}{0}{21}{21/21}{}{0}}
55 | \headcommand {\beamer@framepages {21}{21}}
56 | \headcommand {\slideentry {4}{0}{22}{22/22}{}{0}}
57 | \headcommand {\beamer@framepages {22}{22}}
58 | \headcommand {\slideentry {4}{0}{23}{23/23}{}{0}}
59 | \headcommand {\beamer@framepages {23}{23}}
60 | \headcommand {\slideentry {4}{0}{24}{24/24}{}{0}}
61 | \headcommand {\beamer@framepages {24}{24}}
62 | \headcommand {\slideentry {4}{0}{25}{25/25}{}{0}}
63 | \headcommand {\beamer@framepages {25}{25}}
64 | \headcommand {\slideentry {4}{0}{26}{26/26}{}{0}}
65 | \headcommand {\beamer@framepages {26}{26}}
66 | \headcommand {\slideentry {4}{0}{27}{27/27}{}{0}}
67 | \headcommand {\beamer@framepages {27}{27}}
68 | \headcommand {\slideentry {4}{0}{28}{28/28}{}{0}}
69 | \headcommand {\beamer@framepages {28}{28}}
70 | \headcommand {\slideentry {4}{0}{29}{29/29}{}{0}}
71 | \headcommand {\beamer@framepages {29}{29}}
72 | \headcommand {\sectionentry {5}{学习 Apple 开发体系}{30}{学习 Apple 开发体系}{0}}
73 | \headcommand {\beamer@sectionpages {16}{29}}
74 | \headcommand {\beamer@subsectionpages {16}{29}}
75 | \headcommand {\slideentry {5}{0}{30}{30/30}{}{0}}
76 | \headcommand {\beamer@framepages {30}{30}}
77 | \headcommand {\slideentry {5}{0}{31}{31/31}{}{0}}
78 | \headcommand {\beamer@framepages {31}{31}}
79 | \headcommand {\beamer@partpages {1}{31}}
80 | \headcommand {\beamer@subsectionpages {30}{31}}
81 | \headcommand {\beamer@sectionpages {30}{31}}
82 | \headcommand {\beamer@documentpages {31}}
83 | \headcommand {\def \inserttotalframenumber {31}}
84 |
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.out:
--------------------------------------------------------------------------------
1 | \BOOKMARK [2][]{Outline0.1}{Apple 硬件体系}{}% 1
2 | \BOOKMARK [2][]{Outline0.2}{Apple 的软件体系}{}% 2
3 | \BOOKMARK [2][]{Outline0.3}{Apple 体系开发技术}{}% 3
4 | \BOOKMARK [2][]{Outline0.4}{操作演示阶段}{}% 4
5 | \BOOKMARK [2][]{Outline0.5}{学习 Apple 开发体系}{}% 5
6 |
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/first/slide/xcodeTutorial.pdf
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.rel:
--------------------------------------------------------------------------------
1 | ;; RefTeX parse info file
2 | ;; File: /Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex
3 | ;; User: march (March Liu)
4 |
5 | (set reftex-docstruct-symbol '(
6 |
7 |
8 | (xr nil "\\\\\\\\\\\\")
9 |
10 | (index-tags)
11 |
12 | (is-multi nil)
13 |
14 | (bibview-cache)
15 |
16 | (master-dir . "/Users/march/jobs/BlackCookbook/objc/first/slide/")
17 |
18 | (label-numbers)
19 |
20 | (bof "/Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex")
21 |
22 | (toc "toc" " 1 Apple 应用开发体系" "/Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex" nil 2 "1" "\\section{Apple 应用开发体系}" 945)
23 |
24 | ("fig:iPod" "f" nil "/Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex" nil "")
25 |
26 | ("fig:Mac" "f" nil "/Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex" nil "")
27 |
28 | (eof "/Users/march/jobs/BlackCookbook/objc/first/slide/xcodeTutorial.tex")
29 | ))
30 |
31 |
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.snm:
--------------------------------------------------------------------------------
1 | \beamer@slide {fig:iPhone}{4}
2 | \beamer@slide {fig:iPod}{5}
3 | \beamer@slide {fig:iPad}{6}
4 | \beamer@slide {fig:mac}{7}
5 | \beamer@slide {fig:Mac}{7}
6 | \beamer@slide {fig:iossoft}{9}
7 | \beamer@slide {fig:MacSoft}{10}
8 |
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.tex:
--------------------------------------------------------------------------------
1 | \documentclass[utf8x, notes=hide]{beamer}
2 |
3 | %\usepackage[bars]{beamerthemetree} % Beamer Theme v 2.2
4 | \usetheme{boxes} % Beamer theme
5 | \usecolortheme{seahorse} % Beamer color theme
6 | % whale
7 |
8 | \usepackage[boldfont,slantfont]{xeCJK}
9 | \usepackage{fontspec}
10 | \setmainfont{DejaVu Serif}
11 | \setsansfont{DejaVu Sans}
12 | \setmonofont{DejaVu Sans Mono}%{Monaco}
13 | \setCJKmainfont{WenQuanYi Zen Hei}
14 | \setCJKsansfont{WenQuanYi Macro Hei}
15 | \setCJKmonofont{WenQuanYi Micro Hei Mono}
16 | \setCJKfamilyfont{tt}{Monaco}
17 |
18 | \usepackage{color}
19 | \definecolor{listinggray}{gray}{0.9}
20 | \usepackage{xcolor}
21 |
22 | \usepackage{listings}
23 | % \lstset{numbers=left,
24 | % backgroundcolor=\color{listinggray},
25 | % frame=single,
26 | % framexleftmargin=7mm,
27 | % frameshape={RYN}{y}{y}{RYN}}
28 | \usepackage{hyperref}
29 | \usepackage{graphicx}
30 |
31 | \title{Objective C 与 XCode}
32 | \author[刘鑫]{刘鑫 }
33 | \institute{iOS 及 Mac OS 开发简介}
34 |
35 | \begin{document}
36 |
37 | \frame{\titlepage}
38 |
39 | \begin{frame}
40 | \frametitle{关于本课程}
41 | 一个人应该能够换尿布,策划战争,杀猪,开船,设计房子,写十四行诗,结算
42 | 账户,砌墙,接脱臼的骨头,安慰濒死的人,服从命令,发布命令,携手合作,
43 | 独立行动,解数学方程,分析新问题,铲粪,电脑编程,做出可口的饭,善打架,
44 | 勇敢地死去。只有昆虫才专业化。\\
45 | \rightline{——Robert A. Heinlein}
46 | \end{frame}
47 |
48 | %------------------------------------------
49 | \section{Apple 硬件体系}
50 | \begin{frame}
51 | \begin{center}
52 | \begin{Huge}
53 | What's Apple?
54 | \end{Huge}
55 | \end{center}
56 | \end{frame}
57 | %------------------------------------------
58 | \begin{frame}
59 | \frametitle{肾之天敌}
60 | \begin{figure}
61 | \centering
62 | \includegraphics[bb=0 0 609 560,scale=.2]{images/iPhone.png}
63 | \caption{iPhone}
64 | \label{fig:iPhone}
65 | \end{figure}
66 | \end{frame}
67 | %------------------------------------------
68 | \begin{frame}
69 | \frametitle{一个卖 mp3 的公司居然咸鱼翻身了……——孔老师}
70 | \begin{figure}
71 | \centering
72 | \includegraphics[bb=0 0 1003 830,scale=.2]{images/iPod.png}
73 | \caption{iPod}
74 | \label{fig:iPod}
75 | \end{figure}
76 | \end{frame}
77 | %------------------------------------------
78 | \begin{frame}
79 | \frametitle{唯冠出品,中华之光}
80 | \begin{figure}
81 | \centering
82 | \includegraphics[bb=0 0 1004 489,scale=.2]{images/iPad.png}
83 | \label{fig:iPad}
84 | \end{figure}
85 | \end{frame}
86 | %------------------------------------------
87 | \begin{frame}
88 | \frametitle{星巴克利器}
89 | \begin{figure}
90 | \centering
91 | \includegraphics[bb=0 0 964 611,scale=.2]{images/mac.png}
92 | \label{fig:mac}
93 | \caption{各种 MAC}
94 | \label{fig:Mac}
95 | \end{figure}
96 | \end{frame}
97 | %------------------------------------------
98 | \section{Apple 的软件体系}
99 | \begin{frame}
100 | \begin{center}
101 | \Huge{Apple 的软件体系}
102 | \end{center}
103 | \end{frame}
104 | %------------------------------------------
105 | \begin{frame}
106 | \frametitle{iOS —— mp3 厂商咸鱼翻身之秘}
107 | \begin{figure}
108 | \centering
109 | \includegraphics[bb=0 0 250 333,scale=.2]{images/iossoft.jpg}
110 | \caption{iOS 丰富的 APP}
111 | \label{fig:iossoft}
112 | \end{figure}
113 | \end{frame}
114 | %------------------------------------------
115 | \begin{frame}
116 | \frametitle{Mac OS—— Alan Kay 抄袭了它}
117 | \begin{figure}
118 | \centering
119 | \includegraphics[bb=0 0 988 458,scale=.2]{images/macsoft.png}
120 | \caption{Mac OS 的软件正在向 iOS 风格转变}
121 | \label{fig:MacSoft}
122 | \end{figure}
123 | \end{frame}
124 | %------------------------------------------
125 | \section{Apple 体系开发技术}
126 | \begin{frame}[containsverbatim]
127 | \frametitle{Objective C}
128 | \begin{lstlisting}
129 | #import
130 |
131 | int main(int argc, char* argv[]){
132 | printf("hello world!\n");
133 | return 0;
134 | }
135 | \end{lstlisting}
136 | \end{frame}
137 | %------------------------------------------
138 | \begin{frame}
139 | \frametitle{这货不是C}
140 | \begin{center}
141 | \begin{huge}
142 | 等等,哪里不对?
143 | \end{huge}
144 | \end{center}
145 | \end{frame}
146 | %------------------------------------------
147 | \begin{frame}
148 | \frametitle{这货真的不是C}
149 | Objective C 是 C 语言的一个 Smalltalk 风格的面向对象扩展,高度兼容 C。
150 | 是 Apple 各平台的主力开发工具。
151 | \end{frame}
152 | %------------------------------------------
153 | \begin{frame}[containsverbatim]
154 | \frametitle{IDE 实作}
155 | \begin{lstlisting}
156 | #import
157 |
158 | int main (int argc, const char * argv[])
159 | {
160 |
161 | @autoreleasepool {
162 | NSLog(@"Hello, World!");
163 |
164 | }
165 | return 0;
166 | }
167 | \end{lstlisting}
168 | \end{frame}
169 | %------------------------------------------
170 | \begin{frame}
171 | \frametitle{XCode}
172 | XCode 是 Apple 官方推出的 Apple 体系开发工具,用于开发 Apple 各平台
173 | 的 IDE。
174 | \end{frame}
175 |
176 | \section{操作演示阶段}
177 | %------------------------------------------
178 | \begin{frame}
179 | \frametitle{iOS 开发演示}
180 | 演示最简单的 ios 项目。
181 | \end{frame}
182 |
183 | %------------------------------------------
184 | \begin{frame}
185 | \frametitle{来一发吧!}
186 | 演示最简单的 ios 项目建立。
187 | \end{frame}
188 |
189 | %------------------------------------------
190 | \begin{frame}
191 | \frametitle{Objective?}
192 | 演示最简单的类型定义。
193 | \end{frame}
194 |
195 | %------------------------------------------
196 | \begin{frame}
197 | \frametitle{GUI?}
198 | 演示最简单的 cocoa 界面开发。
199 | \end{frame}
200 |
201 | %------------------------------------------
202 | \begin{frame}
203 | \frametitle{MVC?}
204 | 演示并解说 cocoa 的 MVC 结构。
205 | \end{frame}
206 |
207 | %------------------------------------------
208 | \begin{frame}
209 | \frametitle{事件?}
210 | 演示并解说 cocoa 的事件绑定。
211 | \end{frame}
212 |
213 | %------------------------------------------
214 | \begin{frame}
215 | \frametitle{Debug?}
216 | 演示并解说 cocoa 的一些 debug 操作。
217 | \end{frame}
218 |
219 | %------------------------------------------
220 | \begin{frame}
221 | \frametitle{谁动了我的内存?}
222 | Objective C 的内存管理基于 alloc/dealloc 机制。需要程序员细心管理。
223 | \end{frame}
224 |
225 | %------------------------------------------
226 | \begin{frame}
227 | \frametitle{谁动了我的对象?}
228 | Objective C 通过 init/release 机制管理对象结构的构造和释放。
229 | \end{frame}
230 |
231 | %------------------------------------------
232 | \begin{frame}
233 | \frametitle{谁动了我的引用技术?}
234 | Objective C 通过 retain/release 机制管理对象结构的构造和释放。
235 | \end{frame}
236 |
237 | %------------------------------------------
238 | \begin{frame}
239 | \frametitle{谁动了我的属性?}
240 | \begin{itemize}
241 | \item retain/assign
242 | \item strong/weak
243 | \end{itemize}
244 | \end{frame}
245 |
246 | %------------------------------------------
247 | \begin{frame}
248 | \frametitle{autorelease?}
249 | AutoRelease 机制适用长生命周期的对象,不建议过度使用。
250 | \end{frame}
251 |
252 | %------------------------------------------
253 | \begin{frame}
254 | \frametitle{托管给工具?}
255 | GC 机制性能底下,新项目建议使用 arc 机制。
256 | \end{frame}
257 |
258 | %------------------------------------------
259 | \begin{frame}
260 | \frametitle{我的内存哪儿去了?}
261 | 介绍 profile 工具
262 | \end{frame}
263 |
264 | %------------------------------------------
265 | \begin{frame}
266 | \frametitle{我的代码可靠吗?}
267 | 介绍 analyze 工具。
268 | \end{frame}
269 |
270 | %------------------------------------------
271 | \begin{frame}
272 | \frametitle{我的项目质量高吗?}
273 | 介绍 Unit Test 工具 GHUnitTest。
274 | \end{frame}
275 |
276 |
277 | \section{学习 Apple 开发体系}
278 | %------------------------------------------
279 | \begin{frame}
280 | \begin{center}
281 | 推荐开发书籍。
282 | \end{center}
283 | \end{frame}
284 |
285 | \begin{frame}
286 | \begin{center}
287 | 我们的项目中使用的第三方组件。
288 | \end{center}
289 | \end{frame}
290 |
291 | \begin{frame}
292 | \frametitle{再见!}
293 | \begin{center}
294 | 谢谢大家!\\
295 | \rightline{Power By \LaTeX{}}
296 | \end{center}
297 | \end{frame}
298 |
299 | \end{document}
--------------------------------------------------------------------------------
/objc/first/slide/xcodeTutorial.toc:
--------------------------------------------------------------------------------
1 | \beamer@endinputifotherversion {3.10pt}
2 | \beamer@sectionintoc {1}{Apple 硬件体系}{3}{0}{1}
3 | \beamer@sectionintoc {2}{Apple 的软件体系}{8}{0}{2}
4 | \beamer@sectionintoc {3}{Apple 体系开发技术}{11}{0}{3}
5 | \beamer@sectionintoc {4}{操作演示阶段}{16}{0}{4}
6 | \beamer@sectionintoc {5}{学习 Apple 开发体系}{30}{0}{5}
7 |
--------------------------------------------------------------------------------
/objc/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/hello
--------------------------------------------------------------------------------
/objc/hello.m:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | int main(int argc, char* argv[]){
4 | printf("hello world!\n");
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/objc/helloObjc.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/helloObjc.m
--------------------------------------------------------------------------------
/objc/helloObject:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/objc/helloObject
--------------------------------------------------------------------------------
/objc/mainmenu/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 |
3 | #import
4 |
5 | @interface AppDelegate : NSObject
6 |
7 | -(IBAction) quit:(id)sender;
8 |
9 | @end
10 |
--------------------------------------------------------------------------------
/objc/mainmenu/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 |
3 | #import "AppDelegate.h"
4 | #import "MainMenu.h"
5 |
6 | @implementation AppDelegate
7 |
8 | -(void) applicationDidFinishLaunching:(NSNotification *)notification {
9 | NSApplication *app = [NSApplication sharedApplication];
10 | MainMenu *mainMenu = [[MainMenu alloc] init];
11 |
12 | mainMenu.quitItem.target = self;
13 | mainMenu.quitItem.action = @selector(quit:);
14 |
15 | app.mainMenu = mainMenu;
16 | }
17 |
18 | -(IBAction) quit:(id)sender {
19 | [NSApp terminate:self];
20 | }
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/objc/mainmenu/AppDelegate.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/objc/mainmenu/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrincipalClass
6 | NSApplication
7 |
8 |
9 |
--------------------------------------------------------------------------------
/objc/mainmenu/MainMenu.h:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 | #import
3 |
4 | @interface MainMenu:NSMenu {
5 |
6 | }
7 |
8 | @property (strong, nonatomic) IBOutlet NSMenuItem* quitItem;
9 | @property (strong, nonatomic) IBOutlet NSMenuItem* aboutItem;
10 |
11 | @end
12 |
--------------------------------------------------------------------------------
/objc/mainmenu/MainMenu.m:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 | #import "MainMenu.h"
3 |
4 | @implementation MainMenu
5 | @synthesize quitItem, aboutItem;
6 |
7 | -(id) init {
8 | // the title will be ignore
9 | self = [super initWithTitle:@"Main Menu"];
10 | if(self){
11 | // NSMenu.menuBarVisible = YES;
12 |
13 | // this title will be ignore too
14 | NSMenuItem * appItem = [[NSMenuItem alloc] initWithTitle:@"App Item" action:Nil keyEquivalent:@""];
15 | [self addItem:appItem];
16 | // this title will be ignore too
17 | NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@"application"];
18 | self.aboutItem = [[NSMenuItem alloc] initWithTitle:@"about" action:Nil keyEquivalent:@""];
19 | [appMenu addItem:self.aboutItem];
20 | [appMenu addItem:[NSMenuItem separatorItem]];
21 | self.quitItem = [[NSMenuItem alloc] initWithTitle:@"quit" action:Nil keyEquivalent:@""];
22 | [appMenu addItem:self.quitItem];
23 | [self setSubmenu:appMenu forItem:appItem];
24 |
25 | // this title will be ignore too
26 | NSMenuItem * windowItem = [[NSMenuItem alloc] initWithTitle:@"Window Item" action:Nil keyEquivalent:@""];
27 | [self addItem:windowItem];
28 | NSMenu *windowMenu = [[NSMenu alloc] initWithTitle:@"window"];
29 | [windowMenu addItemWithTitle:@"hide me" action:Nil keyEquivalent:@""];
30 | [windowMenu addItemWithTitle:@"hide others" action:Nil keyEquivalent:@""];
31 | [self setSubmenu:windowMenu forItem:windowItem];
32 | }
33 | return self;
34 | }
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/objc/mainmenu/MainMenu.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/objc/mainmenu/Makefile:
--------------------------------------------------------------------------------
1 | CC=clang
2 | BUILD=$(CC) -fobjc-arc
3 | BUILDD=$(BUILD) -g
4 | LINK=$(BUILD) -framework Cocoa
5 | OUT=sample
6 | APP=sample.app
7 | INFO=Info.plist
8 | SOURCES=MainMenu.m AppDelegate.m main.m
9 | OBJS=MainMenu.o AppDelegate.o main.o
10 |
11 | .PHONY: clean help
12 |
13 | release: build
14 | make package
15 |
16 | debug: buildd
17 | make package
18 |
19 | package:
20 | mkdir -p $(APP)/Contents/MacOS
21 | cp $(OUT) $(APP)/Contents/MacOS/
22 | cp $(INFO) $(APP)/Contents
23 |
24 | run:
25 | open $(APP)
26 |
27 | build:
28 | $(BUILD) -c $(SOURCES)
29 | make link
30 |
31 | buildd:
32 | $(BUILDD) -c $(SOURCES)
33 | make link
34 |
35 | link:
36 | $(LINK) -o $(OUT) $(OBJS)
37 |
38 | analyze:
39 | $(BUILD) --analyze $(SOURCES)
40 |
41 | clean:
42 | -rm -f mytest $(OBJS)
43 | -rm -f *~
44 | -rm -f $(OUT)
45 | -rm -rf $(APP)
46 |
47 | help:
48 | -echo "make release|debug|run|analyze|clean|help"
49 |
--------------------------------------------------------------------------------
/objc/mainmenu/README.md:
--------------------------------------------------------------------------------
1 | A OS X APP Without XCode
2 | ========================
3 | This create by editor(Emacs), use .h, .m, Info.plist and Makefile.
4 |
5 | It show a sample app without any window but a main menu.
6 |
7 | The first menu while become app menu, so the app name will override
8 | menu title.
9 |
10 | I make it support arc.
11 |
12 | With Info.plist, you can ignore [NSApp run] in main function.
13 |
--------------------------------------------------------------------------------
/objc/mainmenu/main.m:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import
3 | #import "AppDelegate.h"
4 |
5 | int main(int argc, const char *argv[]) {
6 | @autoreleasepool {
7 | NSApplication *app = [NSApplication sharedApplication];
8 | id delegate = [[AppDelegate alloc] init];
9 | app.delegate = delegate;
10 |
11 | return NSApplicationMain(argc, (const char**)argv);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/objc/mainmenu/main.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/objc/noxcode/Makefile:
--------------------------------------------------------------------------------
1 | CC=clang
2 | BUILD=$(CC) -fobjc-arc
3 | LINK=$(BUILD) -framework Cocoa
4 |
5 | .PHONY: all run clean
6 | all: build
7 | mkdir -p mytest.app/Contents/MacOS
8 | cp mytest mytest.app/Contents/MacOS/
9 |
10 | run: all
11 | open mytest.app
12 |
13 | build: myWindow.o myView.o main.o
14 | $(LINK) -o mytest myWindow.o myView.o main.o
15 |
16 | myWindow.o:
17 | $(BUILD) -c myWindow.m
18 |
19 | myView.o:
20 | $(BUILD) -c myView.m
21 |
22 | main.o:
23 | $(BUILD) -c main.m
24 |
25 | clean:
26 | -rm mytest myWindow.o myView.o main.o
27 | -rm *~
28 | -rm -r mytest.app
29 |
--------------------------------------------------------------------------------
/objc/noxcode/README.md:
--------------------------------------------------------------------------------
1 | A OS X APP Without XCode
2 | ========================
3 | This create by editor(Emacs), use .h, .m and Makefile.
4 |
5 | The sample code from http://forums.macnn.com/t/209595/cocoa-without-nib-file-need-help .
6 | I rewrite some code, and reate a Makefile for project build and run.
7 |
8 | I make it support arc.
9 |
10 |
--------------------------------------------------------------------------------
/objc/noxcode/main.m:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import
3 | #import "myWindow.h"
4 | #import "myView.h"
5 |
6 | int main(int argc, const char *argv[]) {
7 | @autoreleasepool {
8 | myView *view = [[myView alloc] initWithFrame:NSMakeRect(0, 100, 200, 200)];
9 | NSWindow *window = [[myWindow alloc] initWithContentRect:NSMakeRect(50, 100, 200, 300)
10 | styleMask:NSTitledWindowMask | NSResizableWindowMask
11 | backing:NSBackingStoreBuffered
12 | defer:YES];
13 |
14 | NSTextField *text=[[NSTextField alloc] initWithFrame:NSMakeRect(10, 60, 180, 32)];
15 | text.stringValue = @"sample text";
16 | NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 180, 32)];
17 | [button setBezelStyle:NSRoundedBezelStyle];
18 | [button setTitle:@"Quit"];
19 | [button setTarget:NSApp];
20 | [button setAction:@selector(terminate:)];
21 |
22 | [window setTitle:@"test1"];
23 |
24 | [[window contentView] addSubview:view];
25 | [[window contentView] addSubview:text];
26 | [[window contentView] addSubview:button];
27 |
28 | [NSApplication sharedApplication];
29 | [window makeKeyAndOrderFront:nil];
30 | [NSApp run];
31 | }
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/objc/noxcode/myView.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import
3 |
4 | @interface myView : NSView {
5 |
6 | }
7 | @end
8 |
--------------------------------------------------------------------------------
/objc/noxcode/myView.m:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import "myView.h"
3 |
4 | @implementation myView
5 |
6 | -(void) drawRect:(NSRect)rect {
7 | NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(10, 10, 180, 180)];
8 | [[NSColor greenColor] set];
9 | [path fill];
10 | NSLog(@"myView: drawRect:");
11 | }
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/objc/noxcode/myWindow.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import
3 |
4 | @interface myWindow : NSWindow
5 | @end
6 |
--------------------------------------------------------------------------------
/objc/noxcode/myWindow.m:
--------------------------------------------------------------------------------
1 | #import "myWindow.h"
2 |
3 | @implementation myWindow
4 |
5 | -(BOOL) canBecomeKeyWindow {
6 | return YES;
7 | }
8 |
9 | @end
10 |
--------------------------------------------------------------------------------
/objc/statusmenu/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 |
3 | #import
4 |
5 | @interface AppDelegate : NSObject
6 |
7 | @property (strong, nonatomic) IBOutlet NSStatusItem *statusItem;
8 |
9 | -(IBAction) quit:(id)sender;
10 |
11 | @end
12 |
--------------------------------------------------------------------------------
/objc/statusmenu/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 |
3 | #import "AppDelegate.h"
4 | #import "MainMenu.h"
5 |
6 | @implementation AppDelegate
7 | @synthesize statusItem;
8 |
9 | -(void) applicationDidFinishLaunching:(NSNotification *)notification {
10 | self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
11 | self.statusItem.title = @"dwarf clip";
12 | MainMenu *menu = [[MainMenu alloc] init];
13 | menu.quitItem.target = self;
14 | menu.quitItem.action = @selector(quit:);
15 | self.statusItem.menu = menu;
16 | }
17 |
18 | -(IBAction) quit:(id)sender {
19 | [NSApp terminate:self];
20 | }
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/objc/statusmenu/AppDelegate.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/objc/statusmenu/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSPrincipalClass
6 | NSApplication
7 |
8 |
9 |
--------------------------------------------------------------------------------
/objc/statusmenu/MainMenu.h:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 | #import
3 |
4 | @interface MainMenu:NSMenu {
5 |
6 | }
7 |
8 | @property (strong, nonatomic) IBOutlet NSMenuItem* quitItem;
9 | @property (strong, nonatomic) IBOutlet NSMenuItem* aboutItem;
10 |
11 | @end
12 |
--------------------------------------------------------------------------------
/objc/statusmenu/MainMenu.m:
--------------------------------------------------------------------------------
1 | /* -*- mode:objc -*- */
2 | #import "MainMenu.h"
3 |
4 | @implementation MainMenu
5 | @synthesize quitItem, aboutItem;
6 |
7 | -(id) init {
8 | // the title will be ignore
9 | self = [super initWithTitle:@"Main Menu"];
10 | if(self){
11 | // NSMenu.menuBarVisible = YES;
12 |
13 | // this title will be ignore too
14 | NSMenuItem * appItem = [[NSMenuItem alloc] initWithTitle:@"App Item" action:Nil keyEquivalent:@""];
15 | [self addItem:appItem];
16 | // this title will be ignore too
17 | NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@"application"];
18 | self.aboutItem = [[NSMenuItem alloc] initWithTitle:@"about" action:Nil keyEquivalent:@""];
19 | [appMenu addItem:self.aboutItem];
20 | [appMenu addItem:[NSMenuItem separatorItem]];
21 | self.quitItem = [[NSMenuItem alloc] initWithTitle:@"quit" action:Nil keyEquivalent:@""];
22 | [appMenu addItem:self.quitItem];
23 | [self setSubmenu:appMenu forItem:appItem];
24 |
25 | // this title will be ignore too
26 | NSMenuItem * windowItem = [[NSMenuItem alloc] initWithTitle:@"Window Item" action:Nil keyEquivalent:@""];
27 | [self addItem:windowItem];
28 | NSMenu *windowMenu = [[NSMenu alloc] initWithTitle:@"window"];
29 | [windowMenu addItemWithTitle:@"hide me" action:Nil keyEquivalent:@""];
30 | [windowMenu addItemWithTitle:@"hide others" action:Nil keyEquivalent:@""];
31 | [self setSubmenu:windowMenu forItem:windowItem];
32 | }
33 | return self;
34 | }
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/objc/statusmenu/MainMenu.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/objc/statusmenu/Makefile:
--------------------------------------------------------------------------------
1 | CC=clang
2 | BUILD=$(CC) -fobjc-arc
3 | BUILDD=$(BUILD) -g
4 | LINK=$(BUILD) -framework Cocoa
5 | OUT=sample
6 | APP=sample.app
7 | INFO=Info.plist
8 | SOURCES=MainMenu.m AppDelegate.m main.m
9 | OBJS=MainMenu.o AppDelegate.o main.o
10 |
11 | .PHONY: clean help
12 |
13 | release: build
14 | make package
15 |
16 | debug: buildd
17 | make package
18 |
19 | package:
20 | mkdir -p $(APP)/Contents/MacOS
21 | cp $(OUT) $(APP)/Contents/MacOS/
22 | cp $(INFO) $(APP)/Contents
23 |
24 | run:
25 | open $(APP)
26 |
27 | build:
28 | $(BUILD) -c $(SOURCES)
29 | make link
30 |
31 | buildd:
32 | $(BUILDD) -c $(SOURCES)
33 | make link
34 |
35 | link:
36 | $(LINK) -o $(OUT) $(OBJS)
37 |
38 | analyze:
39 | $(BUILD) --analyze $(SOURCES)
40 |
41 | clean:
42 | -rm -f mytest $(OBJS)
43 | -rm -f *~
44 | -rm -f $(OUT)
45 | -rm -rf $(APP)
46 |
47 | help:
48 | -echo "make release|debug|run|analyze|clean|help"
49 |
--------------------------------------------------------------------------------
/objc/statusmenu/README.md:
--------------------------------------------------------------------------------
1 | A OS X APP Without XCode
2 | ========================
3 | This create by editor(Emacs), use .h, .m, Info.plist and Makefile.
4 |
5 | It show a sample app without any window but a status bar menu.
6 |
7 | The app menu and the window menu while become the status bar menu's
8 | submenu.
9 |
10 | I make it support arc.
11 |
12 | With Info.plist, you can ignore [NSApp run] in main function.
13 |
--------------------------------------------------------------------------------
/objc/statusmenu/main.m:
--------------------------------------------------------------------------------
1 | /* -*- mode: objc -*- */
2 | #import
3 | #import "AppDelegate.h"
4 |
5 | int main(int argc, const char *argv[]) {
6 | @autoreleasepool {
7 | NSApplication *app = [NSApplication sharedApplication];
8 | id delegate = [[AppDelegate alloc] init];
9 | app.delegate = delegate;
10 |
11 | return NSApplicationMain(argc, (const char**)argv);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/objc/statusmenu/main.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | files
6 |
7 |
8 | diagnostics
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/python/MetaClass/Zero.py:
--------------------------------------------------------------------------------
1 | #!/bin/env python2.7
2 | #coding:utf8
3 |
4 | """
5 | 元类编程演示
6 | ===============
7 | 仅限于 Python 2.x 的演示
8 |
9 | metaclass
10 | ====================
11 | 调用对象成员时,Python 先查找对象的定义,然后是 metaclass,然后是父类。
12 |
13 | 需要引入来自多个类型的定义,但是又不想使用多继承时,metaclass 是一个可选的方法。
14 |
15 | Python 2 中,可以通过定义类成员 __metaclass__ 引入元类。在 Python 3 中,
16 | 我们使用形如 class X(metaclass=Meta) 的方式。
17 |
18 | type.__new__
19 | ====================
20 | 经常在介绍 metaclass 的文章里出现的形如
21 |
22 | ::
23 | class MetaClass(type):
24 | def __new__(meta, name, bases, attr):
25 | ...
26 | type.__new__(meta, name, bases, attr)
27 |
28 | 的示例其实有点误导人,type.__new__ 只是 metaclass 编程中常用到的一个技巧。
29 | 但是它本身跟 metaclass 没什么必然联系。type.__new__ 构造出一个类型而非普通的实例对象,
30 | 这样,只要像函数一样调用这个类型,就会构造出实例对象,这就是我们通常在 Python
31 | 代码中定义对象的形式
32 |
33 | ::
34 | obj = MyClass(param) #type.__new__ 返回的结果就是 MyClass 之类的东西
35 |
36 | 通常 metaclass 编程会用到这个方法,主要是为了通过重载 __new__ 定义,抢在 __init__ 之前
37 | 做一些魔术动作,例如加载一些实例变量,但是如果没有这个需要的话,metaclass 就跟普通的类定义
38 | 没什么区别,只是将 metaclass 与类定义组合起来,合并成为一个类而已。
39 |
40 | 真正的魔法是 type.__new__ ,它可以在运行时动态的构造新的类型。我在 socrates
41 | 项目中使用过这个技巧。
42 |
43 | """
44 | import math
45 | import copy
46 |
47 | class MetaVector3(type):
48 | def __new__(meta, name, bases, attrs):
49 | #attrs["__abs__"] = MetaVector3.__abs__
50 | return type.__new__(meta, name, bases, attrs)
51 |
52 | def __abs__(self):
53 | return self.x**2+self.y**2+self.z**2
54 |
55 | class Vector(object):
56 | def __init__(self, x, y):
57 | """obj = Vector(int, int)
58 | 向量类型的构造方法,接收两个整型作为两个坐标
59 | """
60 | self.x = x
61 | self.y = y
62 |
63 | def __abs__(self):
64 | """
65 | >>> vec = Vector(3, 4)
66 | >>> abs(vec)
67 | 5.0
68 | """
69 | return math.sqrt(self.x**2+self.y**2)
70 |
71 | class Vector3(Vector):
72 | #这里 metaclass 覆盖了父类的 abs 运算,提供一个三维版本,
73 | #如果没有这行代码,就会调用二维的 abs 运算,doctest 会出错。
74 | __metaclass__ = MetaVector3
75 | """
76 | >>> vec = Vector3(2, 2, 2)
77 | >>> abs(vec)
78 | 3.4641016151377544
79 | """
80 | def __init__(self, x, y, z):
81 | super(Vector3, self).__init__(x, y)
82 | self.z=z
83 |
84 | def defineMetaVector3(z):
85 | """三维向量元类,将二维向量扩展为三维向量。
86 | 用元类构造一个新平面上的向量类型,修改元类之后,求模变成三维运算。
87 | >>> vec = defineMetaVector3(2)(2, 2)
88 | >>> abs(vec)
89 | 3.4641016151377544
90 | """
91 | absFunc = lambda self:math.sqrt(self.x**2+self.y**2+z**2)
92 | return type("Vector3On%s"%z, (Vector,), {"z":z,"__abs__":absFunc})
93 |
94 | if __name__=="__main__":
95 | import doctest
96 | doctest.testmod()
97 |
--------------------------------------------------------------------------------
/python/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiachufang/BlackCookbook/b73252ffab8921cdfa1dc96def22723c6e7e0997/python/README.md
--------------------------------------------------------------------------------
/python/levenshtein/ditstance.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #coding:utf8
3 |
4 | def ditstance(source, target):
5 | """ ditstance(source, target)->int return the levenshtein ditstance
6 | >>> ditstance("126.com", "127.com")
7 | 1
8 | >>> ditstance("127.com", "126.com")
9 | 1
10 | >>> ditstance("hotmail.com", "hotmail.com")
11 | 0
12 | >>> ditstance("", "")
13 | 0
14 | >>> ditstance("sina.com", "")
15 | 8
16 | >>> ditstance("", "gmail.com")
17 | 9
18 | >>> ditstance("sina.com", "sina.cn")
19 | 2
20 | >>> ditstance("qq.cn", "qq.com")
21 | 2
22 | >>> ditstance("139.com", ".139.com")
23 | 1
24 | >>> ditstance("qq.", "qq.com")
25 | 3
26 | >>> ditstance("gmail.com", ".gmail.com")
27 | 1
28 | >>> ditstance(".gmail.com", "gmail.com")
29 | 1
30 | """
31 | src_length = len(source)+1
32 | tgt_length = len(target)+1
33 |
34 | if src_length == 1:
35 | return tgt_length - 1
36 | if tgt_length == 1:
37 | return src_length - 1
38 |
39 | matrix = [range(tgt_length)]
40 | for i in range(1, src_length):
41 | row = [0]*tgt_length
42 | row[0] = i
43 | matrix.append(row)
44 |
45 | for i in range(1, src_length):
46 | src_char = source[i-1]
47 | for j in range(1, tgt_length):
48 | tgt_char = target[j-1]
49 | cost = 0 if src_char == tgt_char else 1
50 | above = matrix[i-1][j]+1
51 | left = matrix[i][j-1]+1
52 | diag = matrix[i-1][j-1]+cost
53 | value = min(above, left, diag)
54 | matrix[i][j]=value
55 |
56 | return matrix[src_length-1][tgt_length-1]
57 |
58 | if __name__=="__main__":
59 | import doctest
60 | doctest.testmod()
61 |
--------------------------------------------------------------------------------
/python/sa/My2InnoDB.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #coding:utf8
3 | #将mysql数据库中所有的 myisam 表升级为 innodb
4 | import sqlalchemy as sa
5 | #示例中的 mysql 服务器的超级用户只允许操作系统信任登录
6 | db = 'db'
7 | engine=sa.create_engine("mysql://127.0.0.1/%s"%db)
8 | for row in engine.execute("SHOW TABLE STATUS from %s where engine='MyISAM'"%db):
9 | print "upgrade %s's engine"%row["name"]
10 | engine.execute("alter table %s engine InnoDB"%row["name"])
11 |
--------------------------------------------------------------------------------
/python/sumit.py:
--------------------------------------------------------------------------------
1 | '''
2 | 找出一个锯齿数组里长度大于5的子数组
3 | 在符合要求的子数组里的数据里找出所有偶数
4 | 如果数据小于10的话乘以2,大于10的除以2
5 | 最后统计符合要求的数据的和
6 | '''
7 | inputdata = [
8 | [2,8,9,13,72,67,88,35,44],
9 | [33,28,47,2,10,45,66,92],
10 | [22,34,60,43,0,72,52],
11 | [10,11,53,58]
12 | ]
13 |
14 | #经同行测试,如果先生成 list 再sum,对
15 | #此示例来说,速度更快。
16 | def sumIt(_input):
17 | return sum(sum(item *2 if item < 10 else item/2
18 | for item in data_area
19 | if item%2 == 0)
20 | for data_area in _input
21 | if len(data_area)>5)
22 |
23 | print sumIt(inputdata)
24 |
--------------------------------------------------------------------------------
/ruby/README.md:
--------------------------------------------------------------------------------
1 | # Ruby
2 |
3 | Ruby 可以视作 Smalltalk 的脚本化成果。是现代流行语言中最纯粹的面向对象语言(以Smalltalk定义的面向对象思想为准)。
4 |
5 | 我们现在虽然没有使用 Ruby 进行产品开发的需要,但是了解这个语言,有助于启发我们的开发工作,
6 | 特别是系出同门的 Objective C 和处于竞争地位的 Python。
7 |
8 | Ruby 也广受 Java 社区的欢迎。
9 |
10 | Ruby 的风格还被视作 Perl 语言的发展方向。
11 |
12 | ## Convert To icns
13 |
14 | convert2icns.rb 接受一个 png 文件作为参数,最终输出一个 icns,中间产物是一个 iconset 目录。
15 |
16 | 为保证精细度,原始素材不应该小于1024*1024。
17 |
18 | 因为是自用脚本,还比较简陋,没有做严格的出错检查……
19 |
20 | 依赖 RMagicK
21 |
--------------------------------------------------------------------------------
/ruby/convert2icns.rb:
--------------------------------------------------------------------------------
1 | #/usr/bin/env irb
2 |
3 | require "RMagicK"
4 | require "FileUtils"
5 |
6 | filename = ARGV[0]
7 |
8 | image = Magick::Image::read(filename)
9 | puts image[0]
10 |
11 | image512r = image[0].resize(1024, 1024)
12 | image512 = image[0].resize(512, 512)
13 | image256 = image[0].resize(256, 256)
14 | image128 = image[0].resize(128, 128)
15 | image64 = image[0].resize(64, 64)
16 | image32 = image[0].resize(32, 32)
17 | image16 = image[0].resize(16, 16)
18 |
19 | dirpath = filename.split(".")[0]+".iconset"
20 |
21 | FileUtils::mkdir_p(dirpath)
22 |
23 | image512r.write(dirpath+"/icon_512x512@2x.png")
24 | image512.write(dirpath+"/icon_512x512.png")
25 | image512.write(dirpath+"/icon_256x256@2x.png")
26 | image256.write(dirpath+"/icon_256x256.png")
27 | image256.write(dirpath+"/icon_128x128@2x.png")
28 | image128.write(dirpath+"/icon_128x128.png")
29 | image64.write(dirpath+"/icon_32x32@2x.png")
30 | image32.write(dirpath+"/icon_32x32.png")
31 | image32.write(dirpath+"/icon_16x16@2x.png")
32 | image16.write(dirpath+"/icon_16x16.png")
33 |
34 | cmd = 'iconutil -c icns "'+dirpath+'"'
35 |
36 | puts cmd
37 |
38 | exec cmd
39 |
--------------------------------------------------------------------------------
/ruby/create_readme.rb:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #现在是 2012-02-21 Tue 15:11 ,刚刚我在根目录下执行如下代码,为每个子目录生成了
3 | #一个空的 README.md
4 |
5 | Dir['**'].each { |f| exec "touch #{f}/README.md" if File.directory?f}
6 |
--------------------------------------------------------------------------------
/ruby/jekyll-galleriffic/make-galleriffic:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rvm use default do ruby
2 |
3 | # for all png in the dir path, ouput the small version (75x75)
4 | # and large version(512x512) into the dirs.
5 | # see the galleriffic dir is subdir in a dir named images.
6 | # see the template file in my home bin (will reflact)
7 | # see the template file will out put to _include/DA/ and named
8 | # galleriffice dir name
9 |
10 | require "RMagicK"
11 | include Magick
12 | require "Liquid"
13 |
14 | large = 512.0
15 | medium = 320.0
16 | small = 75.0
17 |
18 | origin_path = Dir.pwd()
19 | gname = ARGV[0]
20 | path = "images/"+gname
21 |
22 | Dir.chdir(path)
23 |
24 | large_dir = "large"
25 | medium_dir = "medium"
26 | small_dir = "small"
27 |
28 | images = []
29 |
30 | if not Dir.exist?(large_dir) then
31 | Dir.mkdir(large_dir)
32 | end
33 |
34 | if not Dir.exist?(medium_dir) then
35 | Dir.mkdir(medium_dir)
36 | end
37 |
38 | if not Dir.exist?(small_dir) then
39 | Dir.mkdir(small_dir)
40 | end
41 |
42 | Dir.glob("*.png") do |image_name |
43 | image = Image::read(image_name).first
44 | max = [image.columns, image.rows].max
45 | large_name = large_dir+"/"+image_name
46 | if max > large then
47 | scale = large/max
48 | image.resize(image.columns*scale, image.rows*scale).write large_name
49 | else
50 | image.write large_name
51 | end
52 |
53 | image = Image::read(image_name).first
54 | max = [image.columns, image.rows].max
55 | medium_name = medium_dir+"/"+image_name
56 | if max > medium then
57 | scale = medium/max
58 | image.resize(image.columns*scale, image.rows*scale).write medium_name
59 | else
60 | image.write medium_name
61 | end
62 |
63 | small_name = small_dir+"/"+image_name
64 | if max > small then
65 | scale = small/max
66 | image.resize(image.columns*scale, image.rows*scale).write small_name
67 | else
68 | image.write small_name
69 | end
70 | images << File.basename(image_name, ".png")
71 | end
72 |
73 | Dir.chdir(origin_path)
74 | template = File.read "/Users/march/bin/template.html"
75 | @template = Liquid::Template.parse(template)
76 | re = @template.render("images"=>images, "galleriffic"=>gname)
77 | if not Dir.exist? "_includes/DA" then
78 | Dir.mkdir "_includes/DA"
79 | end
80 | tfile = File.open("_includes/DA/"+gname, "w+")
81 | tfile.write re
82 | tfile.close
83 |
--------------------------------------------------------------------------------
/ruby/jekyll-galleriffic/template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
19 |
20 |
23 |
{{images|first}}
24 |
{{images|first}}
25 |
26 |
27 |
28 |
29 |
30 | {% for image in images %}
31 | -
32 |
33 |
34 |
35 |
36 | {% endfor %}
37 |
38 |
39 |
40 |
41 |
42 |
43 |
98 |
--------------------------------------------------------------------------------