一瓶水 一張不怕晒的臉 我出發了
相當充實的一天
從汐萬路上山
拉瓦那咖啡
風櫃嘴
冷水崛
野柳
金包里老街
朱銘博物館
十八王宮廟
石門風力發電
石門劉家肉粽
老梅綠色礁岩海岸
富貴角燈塔
富基漁港
石門婚紗廣場
白沙灣、淺水灣
漁人碼頭
環了整個台北市,全長約80公里,可以從一早玩到晚上 :)
$ cd ./phonegap-phonegap-26d211b/lib/ios/bin $ ./create ~/my-phonegap com.phonegap my-phonegap $ ./update_cordova_subproject ~/my-phonegap/my-phonegap.xcodeproj/
dyld: lazy symbol binding failed: Symbol not found: _objc_retain
Referenced from: /var/mobile/Applications/81EB9778-1819-454F-BF09-5D7CA2706A1A/phonegap.app/phonegap
Expected in: /usr/lib/libobjc.A.dylib
dyld: lazy symbol binding failed: Symbol not found: _objc_storeStrong
Referenced from: /var/mobile/Applications/81EB9778-1819-454F-BF09-5D7CA2706A1A/phonegap.app/phonegap
Expected in: /usr/lib/libobjc.A.dylib
ERROR: Start Page at 'www/index.html' was not found原來是 www 加進專案的方式有問題,正確的步驟如下:在專案按右建選擇"Add file to (project name)",選擇 www 資料夾,並勾選 "Copy items into destination group's" folder (if needed)",Folders 選擇 "Create folder references for any added folders"
server { listen 80; server_name www.domain.com; location ~* /profile/[a-m] { proxy_pass http://server0.domain.com; } location ~* /profile/[n-z] { proxy_pass http://server1.domain.com; } }
server { listen 80; server_name www.domain.com; location ~* /profile/[0-9]*[02468]$ { proxy_read_timeout 10s; proxy_pass http://server0.domain.com; } location ~* /profile/[0-9]*[13579]$ { proxy_pass http://server1.domain.com; } }
server { listen 80; server_name www.my-domain.com; location ~* /profile/[a-m] { rewrite ^(.*) http://server0.domain.com$1 permanent; } location ~* /profile/[n-z] { rewrite ^(.*) http://server1.domain.com$1 permanent; } }
#import "Flurry.h" #import "FlurryAds.h" - (void)applicationDidFinishLaunching:(UIApplication *)application { [Flurry startSession:@"YOUR_API_KEY"]; [FlurryAds initialize:rvc]; }
#import "FlurryAds.h" - (void)viewWillAppear:(BOOL)animated { [FlurryAds isAdAvailableForSpace:@"FrontPage" view:self.view size:BANNER_TOP timeout:1000]; }
$ gcc -g -o hello hello.c
$ gdb ./hello
$ gdb -d /home/brian/test ./hello
$ gdb ./hello 12238
(GDB) run若要帶參數的話
run (init parameter) Ex: (GDB) run -h localhost -p 8080
b (filename):(line num) Ex: (GDB) b hello.c:5
(GDB) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x000000000040049c in main at hello.c:5
d (breakpoint id) Ex: (GDB) d 1
(GDB) bt #0 hello () at hello.c:9 #1 0x00000000004004cf in main () at hello.c:14
(GDB) bt full #0 hello () at hello.c:9 i = 0 #1 0x00000000004004cf in main () at hello.c:14 No locals.
p (variable) Ex: (GDB) p iValue (GDB) p *stEmployee
f (frame num) EX: (GDB) f 3
(GDB) nStep into (會跳入 function)
(GDB) sContinue
(GDB) c
(GDB) handle SIGUSR nostop noprint
(GDB) i handle Signal Stop Print Pass to program Description SIGHUP Yes Yes Yes Hangup SIGINT Yes Yes No Interrupt SIGQUIT Yes Yes Yes Quit SIGILL Yes Yes Yes Illegal instruction SIGTRAP Yes Yes No Trace/breakpoint trap有關 signal 的部分可以參考 http://sourceware.org/gdb
(GDB) thread
(GDB) thread 3
(GDB) thread apply all bt (GDB) thread apply all bt full
sudo chmod 644 /dev/bpf*解決!
#include <signal.h> struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGPIPE, &sa, 0);
purge -- force disk cache to be purged (flushed and emptied)Disk I/O的速度遠小於 Memory,所以 OS 會把常用的資料 cache 一份在 memory,這樣就不用每次都跑去 disk了。而此指令就是把這些 cache 釋放掉摟。
$ gcc -o test test.c test.c:2:23: error: json/json.h: No such file or directory test.c: In function 'main': test.c:8: warning: assignment makes pointer from integer without a cast test.c:12: warning: assignment makes pointer from integer without a cast表示 include 的 header file 找不到,預設會去找 /usr/include、/usr/local/include,若 library 安裝在其他目錄,可以在 compile 時加上 -I/opt/json-c-0.9/include。
$ gcc -o test test.c -I/opt/json-c-0.9/include /tmp/ccMCrNFo.o: In function `main': test.c:(.text+0x9): undefined reference to `json_object_new_object' test.c:(.text+0x17): undefined reference to `json_object_new_string ... test.c:(.text+0xc1): undefined reference to `json_object_put' collect2: ld returned 1 exit status表示 link library 失敗,compile 時要加上 -ljson
$ gcc -o test test.c -I/opt/json-c-0.9/include -ljson /usr/bin/ld: cannot find -ljson collect2: ld returned 1 exit status表示找不到 libjson.so 的 library 檔案,預設的搜尋路徑 /lib、/lib64、/usr/lib、/usr/local/lib, 若 library 安裝在其他地方,在 compile 時要加上 -L/opt/json-c-0.9/lib 來增加搜尋的路徑。
$ gcc -Wall -o test test.c test2.o -I/opt/json-c-0.9/include -L/opt/json-c-0.9/lib -ljson test.c: In function 'main': test.c:23: warning: implicit declaration of function 'sub_func'出現此 warning,表示你用的 function 在 .c 檔中有定義,但是没有在對應的 header 檔中宣告。
$./test ./test: error while loading shared libraries: libjson.so.0: cannot open shared object file: No such file or directory表示 runtime 時 load 不到指定的 library,環境變數 $LD_LIBRARY_PATH 要加入 share library 路徑,LD_LIBRARY_PATH=/opt/json-c-0.9/lib
{ "name": "Brian", "sex": 0, "data": { "education": "master", "profession": "engineer" } }
struct json_object *root, *data; root = json_object_new_object(); json_object_object_add(root, "name", json_object_new_string("Brian")); json_object_object_add(root, "sex", json_object_new_int(0)); data = json_object_new_object(); json_object_object_add(data, "education", json_object_new_string("master")); json_object_object_add(data, "profession", json_object_new_string("engineer")); json_object_object_add(root, "data", data); // Output to string printf("%s", json_object_to_json_string(root)); // Decrease counter and free object json_object_put(data); json_object_put(root);
struct json_object *root, *name, *sex, *data, *edu, *prof; root = json_tokener_parse(json_string); // Use is_error() to check the result, don't use "j_root == NULL". if (is_error(j_root)) { printf("parse failed."); exit(-1); } name = json_object_object_get(root, "name"); sex = json_object_object_get(root, "sex"); data = json_object_object_get(root, "data"); // If parse fail, object is NULL if (data != NULL) { edu = json_object_object_get(data, "education"); prof= json_object_object_get(data, "profession"); } if (!name || !sex|| !edu || !prof) { printf("parse failed."); json_object_put(root); exit(-1); } // Fetch value printf("name=%s", json_object_get_string(name)); printf("sex=%d", json_object_get_int(sex)); printf("education=%s", json_object_get_string(edu)); printf("profession=%s", json_object_get_string(prof)); // Free json_object_put(root);
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp2 World!') app = webapp2.WSGIApplication([ ('/', MainPage) ], debug=True)
application: helloworld version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: /.* script: helloworld.py
ERROR 2012-06-20 07:37:47,561 wsgi.py:189] Traceback (most recent call last): File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 187, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in _LoadHandler raise ImportError('%s has no attribute %s' % (handler, name)) ImportError:has no attribute app
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp2 World!') app = webapp2.WSGIApplication([ ('/', MainPage) ], debug=True) def main(): from paste import httpserver httpserver.serve(app, host='127.0.0.1', port='8080') if __name__ == '__main__': main()
$ python main.py serving on http://127.0.0.1:8080
$ tar zxvf Python-2.7.2.tgz $ cd Python-2.7.2 $ ./configure && make && make install
$ tar zxvf distribute-0.6.27.tar.gz $ cd distribute-0.6.27 $ python setup.py build $ python setup.py install
$ tar zxvf pip-1.1.tar.gz $ cd pip-1.1 $ python setup.py build $ python setup.py install
$ pip install virtualenv $ virtualenv /opt/env
$ source /opt/env/bin/activate可以看到command line提示改變 (pyenv)brian@localhost:~$
cursor.execute('SELECT * FROM `user` WHERE user=%s AND password=%s;', usr, pwd)所有的參數都會根據其資料型態來取代 format string,特殊字元自然就會被跳脫了。
cursor.execute('SELECT * FROM `user` WHERE username="%s";', username) cursor.execute('SELECT * FROM `user` WHERE id=%d;', my_id)
cursor.execute('SELECT * FROM `user` WHERE user=%s AND password=%s;' % (usr, pwd))
def p(fmt, *arg): print fmt % arg # 傳多個參數 s1 = "hello" s2 = "world" p("%s %s", s1, s2) # 把 list 的 element 當作參數 l = ["Allen", "Billy", "Elmer"] p("%s %s %s", *tuple(l)) # 混合模式 l = ["Allen", "Billy", "Elmer"] s = "hello" p("%s, %s %s %s", *((s, ) + tuple(l)))Output:
hello world Allen Billy Elmer hello, Allen Billy Elmer
以 (x, y) 座標為中心,找尋方圓 n 公里以內的點
----------------------------- id | lat | lng ----+-----------+------------ 1 | 25.151000 | 121.549000 2 | 25.010000 | 121.574000 3 | 25.070000 | 121.589000
台灣地區: 兩地經緯度相差 0.5度:距離相差約 50公里 兩地經緯度相差 0.1度:距離相差約 10公里 兩地經緯度相差 0.05度:距離相差約 5公里 兩地經緯度相差 0.01度:距離相差約 1公里
$ defaults write com.apple.screencapture location ~/Desktop/Snapshot $ killall SystemUIServer
$ defaults write com.apple.screencapture location ~/Desktop/ $ killall SystemUIServer
$ defaults write com.apple.screencapture name "Snapshot" $ killall SystemUIServer
----------------- user | country -------+--------- tony | US tony | HK kelly | USQuery:
INSERT INTO `trip` (`user`, `country`) SELECT 'tony', 'US' FROM DUAL WHERE NOT EXISTS ( SELECT 1 FROM `trip` WHERE `user` = "tony" AND `country` = "US" LIMIT 1 );* 想 INSERT 的 table 可以跟檢查存在性的 table 不同個。
------------------------------ user | email -----------+------------------ olivia | olivia@email.com andy_wang | andy@email.com andy_lin | (NULL)Query:
UPDATE `profile` SET `email` = "andy@email.com" WHERE `user` = "andy_lin" AND NOT EXISTS (SELECT 1 FROM `profile` WHERE `email` = "andy@email.com");但你會發現 mysql execute query 會有下面錯誤:
You can't specify target table 'profile' for update in FROM clause應該改成:
UPDATE `profile` SET `email` = "andy@email.com" WHERE `user` = "andy_lin" AND NOT EXISTS (SELECT * FROM (SELECT 1 FROM `profile` WHERE `email` = "andy@email.com") temp);
>>> l = [3, 2, 5, 4, 1] >>> l.sort() >>> l [1, 2, 3, 4, 5] >>> l.sort(reverse=True) >>> l [5, 4, 3, 2, 1]
>>> l = [3, 5, 4] >>> sorted(l) [3, 4, 5] >>> l [3, 5, 4]根據element的運算結果
>>> l = ["tom", "Michael", "jenny"] >>> l.sort(key=str.lower) >>> l ['jenny', 'Michael', 'tom']
>>> d = {"b": 1, "a": 3, "c": 2} >>> d {'a': 3, 'c': 2, 'b': 1} >>> sorted(d) ['a', 'b', 'c'] >>> for key in sorted(d): ... "%s: %d" % (key, d[key]) ... 'a: 3' 'b: 1' 'c: 2'
>>> l = [{"id": 3, "name": "john"}, {"id": 2, "name": "brandon"}, {"id": 1, "name": "susan"}] >>> l [{'id': 3, 'name': 'john'}, {'id': 2, 'name': 'brandon'}, {'id': 1, 'name': 'susan'}] >>> def my_func(d): ... return d['id'] ... >>> l.sort(key=my_func) >>> l [{'id': 1, 'name': 'susan'}, {'id': 2, 'name': 'brandon'}, {'id': 3, 'name': 'john'}]
>>> l.sort(key=lambda d:d['id']) >>> l [{'id': 1, 'name': 'susan'}, {'id': 2, 'name': 'brandon'}, {'id': 3, 'name': 'john'}]
>>> l.sort(key=lambda d:d['name']) >>> l [{'id': 2, 'name': 'brandon'}, {'id': 3, 'name': 'john'}, {'id': 1, 'name': 'susan'}]
Undefined symbols for architecture x86_64: "___builtin_object_size", referenced from: _BlurImageScanlines.omp_fn.1 in magick_libGraphicsMagick_la-effect.o _XShearImage.omp_fn.0 in magick_libGraphicsMagick_la-shear.o _YShearImage.omp_fn.1 in magick_libGraphicsMagick_la-shear.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make[1]: *** [magick/libGraphicsMagick.la] Error 1 make: *** [all] Error 2
SELECT * FORM `article` OFFSET LIMIT 10取第二頁:
SELECT * FORM `article` OFFSET LIMIT 10 OFFSET 10取第三頁:
SELECT * FORM `article` OFFSET LIMIT 10 OFFSET 20
sdb_conn = SDBConnection(...) # Skip first 20 items query = "SELECT COUNT(*) FORM `article` OFFSET LIMIT 20" rs = sdb_conn.select(sdb_domain, query=query) # Get target page query = "SELECT * FORM `article` OFFSET LIMIT 10" rs2 = sdb_conn.select(sdb_domain, query=query, next_token=rs.next_token) for item in rs2: ...