發表文章

Executing exe on Mac

Enjoy a bottle of Wine... http://winebottler.kronenberg.org/

Android doPost request encoding problem

日前在開發一個Android上的doPost需求時候 發現在呼叫伺服端主機時候,均會有中文亂碼問題 後來文獻中找到應該是輸入參數時候需要在轉碼一次(或者說指定用UTF-8) 下面是各通用的doPost方法 供有需要的人參考:   public String getDataFromUrl(String url, Map<String, String> params) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); String result = null; Log.d(TAG, "Params: " + params); try { List<NameValuePair> pairs = null; if(params != null){ pairs = new ArrayList<NameValuePair>(params.size()); for(String k : params.keySet()){ String v = params.get(k); pairs.add(new BasicNameValuePair(k,v)); } } httppost.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8 )); // Finally, execute the request HttpResponse webServerAnswer = httpclient.execute(httppost); Log.d(TAG, ">>>" + httppost.getURI()); Log.d(TAG, ">>>" + httppost.getParams()); HttpEntity httpEntity = web...

Python + MySQL 效能增進

下面是一篇Python使用SSCursor做MySQL資料查詢的文章 其中使用SSCursor做大量資料查詢時,可以更有效能 有興趣的人,可以參考一下: http://fcamel-life.blogspot.com/2010/08/python-mysql.html 下面是可用的Code,可以參考: import MySQLdb from MySQLdb.cursors import SSCursor db = MySQLdb.connect(host="db_ip_address", user="db_user", passwd="db_password", db="db_name") sql = "SELECT * FROM some_table" cursor = db.cursor(cursorclass=SSCursor) #cursor = db.cursor() cursor.execute(sql) result = cursor.fetchall() try:   for record in result:     print record[0] finally:   cursor.close()   db.close()

Node.js Send Mail

Node.js做送Mail的動作相當簡單,下面是步驟,給大家參考: 1. 安裝mail套件 simonsuteki-MacBook-Pro:NodeJSWS simonsu$ sudo npm install mail Password: mail@0.2.3 ../../node_modules/mail  └── reparse@0.1.2 2. 編寫程式:sendMail.js (紅色部份修改為自己的信箱與密碼,綠色部份一需求修改) var sys = require('sys'), mail = require('mail').Mail({ host: ' smtp.gmail.com ', port: 587, username: ' me@gmail.com ', password: ' **password** ' }); mail.message({ from: ' sender@example.net ', to: [' recipient@somewhere.org '], subject: 'Hello from Node.JS' }) . body('Node speaks SMTP!') .send(function(err) { if (err) throw err; sys.debug('Sent!'); }); 3. 執行寄送: simonsuteki-MacBook-Pro:NodeJSWS simonsu$ node sendMail.js  DEBUG: Sent!

MySQL @ Mac

啓動Mac上MySQL sudo /Library/StartupItems/MySQLCOM/MySQLCOM start 停止MySQL sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop 設定alias來取代啓動的指令 alias start_mysql = "/Library/StartupItems/MySQLCOM/MySQLCOM start" alias stop_mysql = "/Library/StartupItems/MySQLCOM/MySQLCOM stop"

Nice lightware text tool

Sublime Text 2 http://www.sublimetext.com/2

Mac上的Benchmark

Mac上有各指令模式的效能測試工具:ApacheBench(ab) 挺方便的喔 simonsuteki-MacBook-Pro:~ simonsu$ ab -n 10000 -c 50   http://localhost:3000/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software:         Server Hostname:        localhost Server Port:            3000 Document Path:          / Document Length:        277 bytes Concurrency Level:      50 Time taken for tests:   20.230 seconds Complete requests: ...