2018年10月5日 星期五

如何在 golang 裡面引用 gitlab private repo

參考文章:https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository

原文是用 gitlab.company.com 當範例,這邊改成一般帳號並加入一些說明。

  1. 先連到帳號頁面產生 private access token,權限需要有 read_repository
    https://gitlab.com/profile/account
  2. 修改 git global 設定將剛剛產生的 token 加入 http.extrahdeader 參數:
    $ git config --global http.extraheader "PRIVATE-TOKEN: 你的access token"
  3. 修改 git global 設定將github 的 ssh 連線方式替換成 https:
    $ git config --global url."git@gitlab.com:你的帳號".insteadOf "https://gitlab.com/你的帳號"
  4. 完成後就可以正常使用 go get 下載 private repo :
    $ go get gitlab.com/slv922/private_repo

Go Module (vgo) 使用方法

對於 vgo 的使用方式其實一直都不是很清楚
Google 到一篇覺得不錯的文章,紀錄一下。

原文:
https://tonybai.com/2018/07/15/hello-go-module/


2018年7月31日 星期二

讓 Gin 的 HTML Template 與 Vue.js 不衝突的方法

        
如果有同時使用 Gin 及 Vue.js 的話,會發現在 HTML Render 變數時會有衝突,
這時候可以在 Vue.js 裡面加一行宣告,改變 Vue.js 呈現變數的方法

delimiters: ['&{', '}']

這樣在 HTML 中就可以使用 &{foo} 的方式去寫 Vue.js 中的變數,不會有衝突了

2018年6月13日 星期三

加入 .gitignore 後才刪除遠端目錄方法

有時不小心 push 上去後才發現有某些目錄忘記加到 .gitignore
這時候可以用下面的方法

git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master

原文:
https://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore

2018年6月6日 星期三

讓 Mac 的圖片預覽功能(QuickLook) 支援 WebP 格式的圖片

WebP (發音weppy) 是由 Google 開發的新一代圖片檔格式,但目前 Mac 的預覽功能 (在檔案上面按空白鍵那個功能) 還不支援,我們可以透過安裝外掛的方式,就可以預覽 WebP 的圖片檔囉。

只要在 Terminal 中輸入以下指令,就安裝完成了

curl -L https://raw.github.com/emin/WebPQuickLook/master/install.sh | sh


成果:


參考:

2018年5月30日 星期三

讓 Linux 主機查詢 DNS 時優先查找 IPV4 IP

如主機環境無法連 IPV6,但是要連線的 FQDN 有 IPV6 與 IPV4 兩種 IP
連線時就必須等 IPV6 連線逾時才會嘗試連 IPV4 IP
此時可新增如下設定,就會優先查 IPV4 IP

# vim /etc/gai.conf

precedence ::ffff:0:0/96 100

2018年5月18日 星期五

ssh 指定預設登入的使用者

 ssh 預設在建立連線時,會帶目前登入的使用者名稱,但實際上我們幾乎不會用目前登入的使用者名稱去連對方的機器,這時候只要在登入的家目錄設定一個 .ssh/config 檔案,就可以了

Host *
    User

Host example
    HostName example.net
    User buck

注意 .ssh/config 的權限需要是 600 才行

Bootstrap-Vue Table 綁定 row click 方法

藏在 document 的 Event 裡面...
找半天沒看到,結果 Google 看到 Github issue 也有人在討論 XD
<b-table bordered striped hover 
         :items="environments"
         :fields="fields"
         :current-page="currentPage"
         :per-page="perPage"
         :filter="filter"
         v-model="shownItems"
         @row-clicked="myRowClickHandler"
>
  <template slot="actions" scope="environment">
    <b-btn size="sm" @click="log(environment.item)">Details</b-btn>
  </template>
</b-table>
methods: {
  myRowClickHandler(record, index) {
    // 'record' will be the row data from items
    // `index` will be the visible row number (available in the v-model 'shownItems')
    log(record); // This will be the item data for the row
  }
}
https://github.com/bootstrap-vue/bootstrap-vue/issues/774
https://bootstrap-vue.js.org/docs/components/table#component-reference

2018年5月14日 星期一

Ubuntu 18.04 server 網卡配置設定

Ubuntu 18.04 採用了 netplan 來管理網路, 設定檔的部分採用 yaml 格式來撰寫,
預設路徑位於 /etc/netplan/, 設定好後執行 netplan apply 就套用新的設定了。

官網有很詳細的說明跟範例: https://netplan.io/examples

2018年4月19日 星期四

Python 計算巢狀式串列 (nested list ) 中某個元素的總數加總

好吧,nested list 不知道中文要怎麼翻譯比較順,就先叫他巢狀式串列吧 XD

假設有一個 list 集合的資料結構長這樣,我們想要計算書本的總數
[
    {'name':'James', 'books':["Python", "Java", "Golang", "C++"]},
    {'name':'Amy', 'books':["Node.js", "C"]},
    {'name':'Danny', 'books':["Perl", "JavaScript"]}
]
這時候可以先用 for 迴圈將所有 books 元素拉出來再計算 books 元素的長度,最後加總起來就可以了
sum = 0
for x in list:
    sum += len(x['books'])
print(sum)
我喜歡用一行寫法,簡潔快速
print(sum([len(x['books']) for x in list]))

2018年4月17日 星期二

使用 docker-compose 直接更新運行中 docker 的方法

如果有正在運行的 docker 想要更新資料,
可以透過下面的指令直接更新,且不用重啟 docker,
實在太好用了😍

docker-compose up -d --no-deps --build svc1

其中的 <service-name> 要和 docker-compose.yml 中設定的一樣

如何在 golang 裡面引用 gitlab private repo

參考文章:https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository 原文是用 gitlab.company.com 當範例,這邊改成一般帳號...