起初先在Flickr網頁注意到這個:
按下open就會直接帶你到App store下載Flickr App, 這就是iOS6開始有的Smart App Banners, 覺得頗有趣的, 就去看了原始碼查了一下作法:
以上這是Flickr的HTML裡面的, 作法很簡單, 就只是在HTML內放個"apple-itunes-app"的meta tag, 指定app-id和參數(非必須)
Android應該也要加個這東西才對呀.....
bower install jQuerybower會把jQuery 安裝到"components/jQuery" 目錄裡
{在Heroku deploy node.js app有個很方便的地方是,當你做git push 後,它會根據package.json自動幫你安裝相關的node.js 模組,但不幸的是它並不支援bower,只支援npm
dependencies: {
"JQuery": "*"
}
}
node_modules/.bin/npm install bowerBingo! 這樣可行, bower一樣被安裝到 node_modules/.bin底下, 加上 "2"的邏輯到"bin/compile"後就大功告成了,
npm install git://github.com/julianshen/passport-flickr.git#master這方式是直接把git url給npm, 不過要deploy上heroku就麻煩了, 還好寫在package.json裡也是沒問題的
"dependencies": { "passport-flickr": "git://github.com/julianshen/passport-flickr.git#master"}這還蠻簡單的, 只是把原先寫version的地方換成git URL就好, 在Heroku上也是沒問題的
"Go was born out of frustration with existing languages and environments for systems programming."Go 是為了作為一個系統語言(systems programming language)而存在的, 它跟天下知名的C語言有同一個父親 - Ken Thompson , 作為一個系統語言, 它並不是直譯式語言, 也非跑在虛擬機(virtual machine)上, 而是貨真價實的像C一樣是先編譯(compile), 而且也是屬於strong and static type的語言, 這表示, 變數型別是預先宣告/決定的, 而且是不能半路變更的, 變數可以像這樣宣告:
var StrVariable string這邊跟C, Java之類的語言不同的地方是, 型別定義是在後面不是放前面, 剛看到時我以為我會不習慣, 但卻花沒很多時間就適應了, 可能是我在很早以前寫過PASCAL的關係吧, PASCAL也是類似的寫法
var IntVariable int
strVariable2 := "Hello Go"這敘述並不代表Go也有dynamic typed的設計, 其實這設計是同時結合了宣告跟指定(assignment), strVariable2並不是沒有型別或動態型別, 因為":="的關係, 使得strVariable2一開始就被宣告成後面值的型別, 因此上面那行跟下面一樣:
var strVariable2 string同理, "intVariable2 := 1"這敘述表示intVariable一開始就被宣告成整數(因為1是整數), 所以它還是一個strong typed的設計, 這邊比較要注意到的一個陷阱是"="和":=", 在已宣告過型別的變數, 是用正常的"="來指定值, 但在未宣告的變數, 必須要用 ":="
strVariable2 = "Hello Go"
type MyString string
type User struct {之後, 你就可以用MyString或是User來宣告變數, 像是
Uid int
Name string
}
var M1 MyString"type MyString string"有點像是C語言的typedef, 可以讓你以另一個型別(MyString)來替代原本的型別(string), 但它其實還有個妙用, 在後面會再提到
var User1 User
User2 := User {1, "julian"}
func (u *User) Hi() {這邊"Hi()"就是屬於"User"的一個方法, 呼叫"User2.Hi()"即可執行它, 方法跟一般的函數一樣, 所不同的是, 前面多了一個"(u *User)" 以這例子來說, 這邊就是定義了"Hi()"的母體是 *User (*是指標- pointer的意思, 就不在這邊解釋)
fmt.Printf("Hi! I'm %s. The %d user.\n", u.Uid, u.Name)
}
type MyInterface interface {但你不需要宣告某個型別"實作"了這個interface, 在Go, interface反而比較有"暗示"(imply)的意味, 也就是, 下面的例子, 不用任何宣告, 你可以把MyString自動當成它也可以是一個MyInterface:
Foo()
}
func (s MyString) Foo() {}因為在MyInterface的定義中, 它含有一個"Foo()", 當你替MyString宣告了一個"Foo()"的方法時, 就自動讓MyString變成了一個實作了MyInterface的型別
import facebook "github.com/julianshen/FacebookGoSDK"這樣是import一個在github上的package, 當你使用"go run"或"go get"之類的來編譯執行程式時, Go自動會上github幫你把這些相關的package取回, 用這個Heroku buildpack做出的環境一樣適用
"Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, it is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for."簡而言之, Go的目標是一個簡單又有效率的語言, 加上一開始設計就考慮網路以及多核, 就姑且說它適合server端的開發吧
http.Handle("/", http.FileServer(http.Dir("./static")))這範例讓你可以把靜態檔案放在"static"目錄下, 假設你在static目錄下放一個a.html, 那這行的目的就是可以讓你用 http://your_app_host/a.html來存取它
try {
.....
} finally {
in.close();
}
在finally區塊內去做一些善後的工作, 以確保這些善後工作可以在程式執行後不管有沒錯誤發生都可以被執行到, 在Go中, 用的則是defer:
6becnna--------1bea
Do not communicate by sharing memory; instead, share memory by communicating.這是在Go的concurrent programming裡一個很重要的精神, concurrent programming也是Go裡面一個相當重要的部份, 它已是語言本身的一部分
require('./underscore.js');
var a = [1, 23, 6, 11, 25, 12, 33, 11, 4];
_.forEach(a, function(v) {
console.log(v);
});
// Export the Underscore object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `_` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else {
root['_'] = _;
}
var _us = require('./underscore.js');
var a = [1, 23, 6, 11, 25, 12, 33, 11, 4];
_us.forEach(a, function(v) {
console.log(v);
});
npm install underscore就可以裝好了, code裡面也只需要用"var _us = require('underscore')"
2. 取得Registration ID後將ID送至ServerGCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { Log.v(TAG, "Already registered"); }
When users uninstall an application, it is not automatically unregistered on GCM. It is only unregistered when the GCM server tries to send a message to the device and the device answers that the application is uninstalled. At that point, you server should mark the device as unregistered (the server will receive a NotRegistered error).
require('android');由這code看, 主要有兩個部分, 一個是一個名為android的module, 一個是alog這個global object (Node本身已有"log", 為避免衝突, 改名為alog)
alog.d('tag', 'message1'); //debug log
alog.e('tag', 'var a=', a, ' found', 1, 'error'); //error log
Source code: https://github.com/julianshen/node-android/blob/master/jni/node-v0.8.8/android/node_android.cc不過這樣不夠, 因為我要的不是只有"log", 而是要像"alog.d"這樣的東西, 因此又多了一個android.js來處理:
var binding = process.binding('android');
function log(level, args) {
var tag = args[0];
var len = args.length;
var objs = [];
for(var i = 1; i < len; i++) {
objs.push(args[i]);
}
var msg = objs.join(' ');
binding.log(level, tag, msg);
}
var alog = {
v: function() {
log(binding.ANDROID_LOG_VERBOSE, arguments);
},
d: function() {
log(binding.ANDROID_LOG_DEBUG, arguments);
},
i: function() {
log(binding.ANDROID_LOG_INFO, arguments);
},
w: function() {
log(binding.ANDROID_LOG_WARN, arguments);
},
e: function() {
log(binding.ANDROID_LOG_ERROR, arguments);
}
};
global.alog = alog;