Hank to hanker - Learning Note
一個成功的拳擊手, 就是在眾多的打擊和跌倒後爬起來。人生亦如是。
2013年8月2日 星期五
2013年8月1日 星期四
[Python ] Compare two list only return matched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list1 = [1, 2, 3] | |
list2 = [3, 4, 5, 6] | |
# method 1 | |
print list(set(list1) & set(list2)) | |
# method 2 | |
print [d for d in list1 if d in list2] |
2013年7月15日 星期一
[NodeJS] Express 3.x 整合i18n-node實現多語言網站 - use i18n-node implement multilanguage website with express 3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var express = require('express') | |
, routes = require('./routes') | |
, user = require('./routes/user') | |
, http = require('http') | |
, path = require('path') | |
, i18n = require('i18n'); | |
// i18n configure | |
i18n.configure({ | |
locales: ['en', 'de'], | |
cookie: 'yourcookiename', | |
directory: __dirname + '/locales' | |
}); | |
var app = express(); | |
// all environments | |
app.set('port', process.env.PORT || 3000); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(express.favicon()); | |
app.use(express.logger('dev')); | |
app.use(express.bodyParser()); | |
app.use(express.cookieParser()); | |
app.use(express.methodOverride()); | |
app.use(i18n.init); // Should always before app.route | |
app.use(app.router); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
// development only | |
if ('development' == app.get('env')) { | |
app.use(express.errorHandler()); | |
} | |
app.get('/', function (req, res) { | |
res.render('index', { | |
'name': 'Hank', | |
'result': res.__n('Result: %d cat', 'Result: %d cats', 3) | |
}); | |
}); | |
http.createServer(app).listen(app.get('port'), function(){ | |
console.log('Express server listening on port ' + app.get('port')); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout | |
block content | |
h1 #{__('Hello')} #{name} | |
h2= __('Hello %s', 'Hank') | |
p #{result} |
[Nginx] 自定義error page - nginx custom error page
在這使用的是預設路徑, 也可以改成自己放error page的路徑
server { listen 80; server_name my-domain-name.com; error_page 500 502 503 504 /error.html; location = /error.html { root html; } location / { } }
2013年7月14日 星期日
[Nginx] 使用Nginx proxy_pass 時保留 host header
原本我使用 nginx 的 proxy_pass 只設定這樣
vim /usr/local/etc/nginx/site-enabled/site
server { listen 80; server_name my-domain-name.com; location / { proxy_pass http://hank.local:8210; } }
但是在後端程式從 header 裡判斷 host 會一直找到 hank.local:8210 而不是 my-domain-name.com
後來找到一個方法可以保留 header 到 proxy 裡, 加上 proxy_set_header Host $http_host 即可
server { listen 80; server_name my-domain-name.com; location / { proxy_pass http://hank.local:8210; proxy_set_header Host $http_host; } }
重新讀取 nginx 設定檔
sudo nginx -s reload
2013年7月8日 星期一
[Mac] 英文單字或句子不會唸? 讓Mac直接幫你念出來。
常看到一個英文單字或句子時, 不懂得怎麼唸, 秉持勤勉精神, 想努力學習一下, 但總是沒有很好的工具可以快速方便的唸出不懂怎麼唸的句子, 只要妳是用Mac, 內建就有功能能做到
突然發現Mac有個say指令, 可以直接在terminal底下唸出輸入的文字
say - Convert text to audible speech直接在指令後面接上要說出的單字或句子
$ say Hello
或是指定說出一個檔案內的內容
$ say -f article.txt
也可以指定語音檔取代內建的語音, 或是使用其他內建的語音
$ say -v ?
看看更多的附加功能
$ man say
對於學習英文唸法時很有用 :)
訂閱:
文章 (Atom)