[TIL] Push Go 1.6 code to heroku and add Deploy to Heroku button

Publish to Heroku Init git and commit your code. git init git add . git commit -m "init project" Login heroku heroku login Using Golang backpack heroku create -b https://github.com/kr/heroku-buildpack-go.git Vendoring: For Go 1.6 (refer here) go get -u github.com/tools/godep Save your dependency godep save github.com/kkdai/githubrss Submit your depdendency git add . git commit -m "godep" Push your complete code to Heroku git push heroku master Add “Deploy to Heroku” copy app.json (refer more spec here) Remember must include buildpack. And all buildpack list here. Make sure your buildpack sync with what you use In my case, I use https://github.com/kr/heroku-buildpack-go.git: "buildpacks": [ { "url": "https://github.com/kr/heroku-buildpack-go.git" }, { "url": "heroku/go" } All app.json sample as follow (refer to rss-webserver):
繼續閱讀

程式設計週記[2016/03/25]: Docker歡慶三歲.. Docker生態圈已經日漸茁壯

這是什麼? 程式週記主要內容如下: Gihub project 介紹: 主要會貼一些github,但是會盡量寫上一些有用的評語(或是我容易想到的關鍵詞)幫助以後查詢 網路文章心得: 會寫些心得,強迫自己閱讀. “程式週記”並且定期週期性更新. 大部分內容在我的twitter都會有,這邊只是將一些簡單的心得與感想註解一下. 本週摘要 本週時間花在Survey 各種IoT Big Data的架構與各種元件的用法,因為Docker三週年聚會,也花了不少時間玩Docker. 比較少時間來弄Golang.下周應該繼續看分散式系統才對. Go Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template 這個Go template 效能有點恐怖.. 20x faster than html/template!! “Go Learn: Some rookie Go mistakes we made (And how we recovered from them)” 不少值得看的粗心錯誤,挑出幾個很容易犯的: Naked return (先定義好的return value) 會讓整個function 更難閱讀(因為return不需要再帶回傳值). 並且很容易少回傳幾個參數而造成回傳沒有意義的初始值. Map 的concurrency 不穩定性 (可以參考Go FAQ: Atomic_Maps),要寫concurrency program 要儘量避免使用map 同場加印: Gist上面有人提供Go地雷Landmines 主要是for i scope interface pointer 前面提到Naked return與容易踩到scope問題. vim-go 1.5 Release vim-go release新版 New in 1.5 (1) fatih/motion 提供函式檢索的功能 (2) GoAlternate 可以快速切換test跟原本檔案 A microservice toolkit 號稱有著相當多microservice功能的 toolkit,並且具有pluggable(可拔插)功能的設計.感覺很酷… jsonparser: Alternative JSON parser for Go that does not require schema 相當快速的json parser(根據作者測試),甚至可以比”encoding/json” 快上九倍. 其實有附上跟一些其他json parser的效能比較表,可以參考看看. 同場加映: https://github.com/mailru/easyjson 也說他比 “ encoding/json”快上不少… 不過他跟jsonparser沒有比過效能.. 倒底”encoding/json”是有多慢呢 XDDD Python Android/JAVA/NODE.JS Docker docker-NAT-router: Docker container that functions as a simple NAT router. Linux iptables MASQUERADE provides network address...
繼續閱讀

[TIL] docker-compose yaml文件檔案格式問題

快速紀錄一下: 在Windows 的Quick Start Terminal (Toolbox)下,如果git下載 docker-compose.yml下來會無法順利讀到. 原因是unix的文件檔案在Windows底下會無法正確閱讀. (CRLF問題) 解決方式: 參考這篇吧 �[31mERROR�[0m: In file '.\docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration option 此外,如果很聰明地使用了vagrant來進入ubuntu VM中跑docker-compose.如果不小心把檔案寫到了跟Widows共享的資料夾內,一樣會有相同的問題. 結論: MacOSX/Linux 的Docker最安全… Windows好危險 XDDD
繼續閱讀

[TIL] Vagrant installation and docker installation

起因 想要分享檔案在VM跟電腦,其實VBOX本身有點麻煩.比起VBOX,vagrant反而提供比較簡單的方式. 步驟 //Check vagrant box list vagrant list //init vagrant init ubuntu/trusty64 //update for vagrant shared folder // editing Vagrantfile // --> config.vm.synced_folder "./data", "/vagrant_data" //startup vagrant up //login vagrant ssh //Save bot vagrant package --output BOT_NAME //Install about basic component sudo apt-get install build-essential openssl sudo apt-get install -y pkg-config sudo apt-get install -y libcairo2-dev //Install about docker sudo apt-get update sudo apt-get install apt-transport-https ca-certificates sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D //edit /etc/apt/sources.list.d/docker.list // deb https://apt.dockerproject.org/repo ubuntu-wily main sudo apt-get update sudo apt-get purge lxc-docker sudo apt-cache policy docker-engine sudo apt-get install docker-engine sudo service docker start //Docker-compose curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose //Docker-machine curl -L https://github.com/docker/machine/releases/download/v0.6.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine && \ chmod +x /usr/local/bin/docker-machine //Install npm curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs sudo apt-get update sudo apt-get install nodejs-legacy sudo apt-get install...
繼續閱讀

程式設計週記[2016/03/18]:AlphaGo的勝利代表機器學習對於選擇這件事情已經更加熟練

這是什麼? 程式週記主要內容如下: Gihub project 介紹: 主要會貼一些github,但是會盡量寫上一些有用的評語(或是我容易想到的關鍵詞)幫助以後查詢 網路文章心得: 會寫些心得,強迫自己閱讀. “程式週記”並且定期週期性更新. 大部分內容在我的twitter都會有,這邊只是將一些簡單的心得與感想註解一下. 本週摘要 本週依舊圍繞在AlphaGo與機器學習上,不過工作上的長官給了我很好的學習方向. 對於新的事物,我們只要搞懂三件事情(不論你有沒有興趣) 為何以前做不到? 以前的困難是什麼? 這一次做到的原因是什麼? 突破點是什麼? 對於相關技術未來的展望? 這個禮拜花了不少時間先思考該如何寫專案,確定好整個方向與架構後才開始動手.想不到卻相當的迅速. Go A very minimal but flexible golang web application framework, providing a robust set of features for building single & multi-page, web applications. http://kataras.github.io/iris/ minimal but flexible golang web application framework for #golang, and the performance benchmark is perfect Official golang implementation of the Ethereum protocol http://ethereum.github.io/go-ethereum/ 類似於blockchain的系統(我不是很確定該用哪種名稱來統稱這種系統). groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases. groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases. 類似於memcached,可以透過key來cache資料. Python Flappy Bird hack using Deep Reinforcement Learning (Deep Q-learning). 用Tensorflow (深度學習) 玩#FalppyBird 聽說可以玩360關 AlphaGo: A replication of DeepMind’s 2016 Nature publication, “Mastering the game of Go with deep neural networks and tree search,” details of which can be found on their website. 使用Python 建立的AlphaGo Deep Learning Engine. Ruby jekyll-now:...
繼續閱讀

[TIL] About Go template usage

起因 想要試著寫RSS render,其實並沒有那麼困難. 步驟 先建立一個 tmpl file (ex: atom.tmpl) <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title></title> <link></link> <atom:link href="" rel="self" type="application/rss+xml" /> <description></description> <pubDate></pubDate> <lastBuildDate></lastBuildDate> <item> <title></title> <description></description> <pubDate></pubDate> <guid></guid> <link></link> </item> </channel> </rss> 然後再Code裡面,去使用html/template func AtomRender() string { var r SomeStuct //讀入template t, err := template.ParseFiles("atom.tmpl") if err != nil { log.Fatal(err) } // log.Println("parse template") //產生io.writer buffer buf := new(bytes.Buffer) //讀取資料 err = t.Execute(buf, r) // log.Println("execute it") if err != nil { log.Fatal(err) } // log.Println("get rss:", buf.String()) return buf.String() } 雷 ”+”, “-“ charactor handle 想要在html 裡面parse +或是-,可別直接當成string. //定義成 template.HTML RssNow template.HTML // t.RssNow = template.HTML(SomeString) 跟RFC822對於W3C Feed Validator的問題 問題: Hi All, I trying to write a feed render and I found the time.Format(time.RFC822) is not valid by W3C feed validator . Here is the code http://play.golang.org/p/mfzLKsuVOW Not sure if it is a issue, or I misunderstanding. 得到解答: try time.RFC1123.seems to be close enough –> RFC1123 seems much...
繼續閱讀