AD

2023-07-18

多個 github 帳號的 ssh key 設定

你有沒有遇過一種情況⋯⋯ 

你需要在自己的一台機器上,有用多個 github 帳號;比方一個是公司的,一個是自己的。

而且因為 github 每個帳號會要求不同 ssh key,所以不要想什麼一支 key 用所有帳號的事XD

那要怎麼設定不同帳號用不同的key呢?
開啟 ssh 的目錄下的 config 檔案(~/.ssh/config) 

config 可以這樣設定: 

Host github.com

    IdentityFile ~/.ssh/id_ed25519 #你的 ssh key 

    User your_user_name

Host github.com-work     #假設是工作的github帳號,加個-work好了

    Hostname github.com

    IdentityFile /.ssh/id_ed25519_2 #你工作帳號的 ssh key 

    User your_2nd_user_name

設定好之後,clone repo 就可以:

用自己的 ssh key
git clone git@github.com:repo_owner/repo_name.git
用你工作帳號的 ssh key
git clone git@github.com-work:repo_owner/repo_name.git

這樣就完成了~

2023-02-01

[Leetcode] 217. Contains Duplicate

紀錄一下自己一看到題目時的做法~


英文題目  https://leetcode.com/problems/contains-duplicate/

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. 


Example 1:

Input: nums = [1,2,3,1]

Output: true


Example 2:

Input: nums = [1,2,3,4]

Output: false


Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2]

Output: true


Constraints:

1 <= nums.length <= 105

-109 <= nums[i] <= 109


2023-01-06

[小記] 用 /etc/hosts 來測試網站被牆時可能的狀況

最近遇到一個 issue,某個客戶用我們的網站無法登出,但客戶公司的其他人和我們的 QA 都無法重現這個問題。

幾份工作下來,原本以為只有一位客戶遇到,QA 又無法重現的這種,開發大概是不會修了;沒想到目前工作新來的這位開發和前端團隊討論了一下,加上不斷重播客戶錄影,發現客戶console有個我們使用的第三方 tracking 服務的 js,在客戶那邊載入有問題,導致 ReferenceError 而無法登出。所以後來開發 handle 了錯誤,讓載入錯誤還是能登出。

一開始覺得有點難驗證,畢竟第三方網站掛掉可遇不可求,開發也修改成錯的路徑 demo 給我看原本不能登出,而修改後是能夠登出的。

---

對於無法重現我一直耿耿於懷,想說這個開發都這麼盡責的推測問題然後修正,我有沒有辦法真的重現問題呢?在我自己的電腦上牆掉那個第三方網站,不知道是不是要架一個 proxy 來擋網站還是什麼;後來和設定過一堆網站、網路環境的朋友聊天,他說改一下 /etc/hosts 就可以啦。

對啊!完全沒想到!/etc/hosts 真的是太好用了!!

於是我把第三方網站指到127.0.0.1,真的重現了客戶錄影中無法登出的狀況,而修正後可以正確登出。

以後要試試被牆的狀況就有最簡單的方法了~

真是太感謝開發和朋友了!


2022-12-08

[Python + Selenium] webdriver.get() 設置最長等待時間

webdriver.get(url) 到一個頁面後,會等到頁面載入完成(onload 事件觸發) ,然後再將控制權交回給測試 script。

在網路不穩定的情況下,或網站也些問題時,等到頁面 onload 可能非常久。
webdriver.get 預設的 timeout 在某些不同的 webdriver 中可能到5分鐘之久。

所以可以用 set_page_load_timeout() 設定一個最長的頁面等待時間:

from selenium import webdriver

driver = webdriver.Chrome()
driver.set_page_load_timeout(20) #傳入最長等待秒數

try:
    driver.get("http://www.example.com")
    
except TimeoutError:
    print("Timed out waiting for page to load.")

以上將頁面的最長等待時間設為20秒,等候頁面超過20秒會拋出 TimeoutError。

2022-07-01

[小記] Docker selenium/standalone-chrome 遇到 ConnectionResetError(104, 'Connection reset by peer')

這是一篇其實沒什麼真正問題的筆記,但花了幾個小時才解決,記錄一下。
 
我們的 Jenkins pipline 會起一個 selenium/standalone-chrome 的 docker,用類似這樣的方式起:
  docker run -d -p 4444:4444 selenium/standalone-chrome 

每次跑完都會 stop 這個 container。 

code 是類似這樣連 remote webdriver 的: webdriver.Remote("http://localhost:4444/wd/hub",options=options) 

其他專案的 docker compose 執行 selenium/standalone-chrome 後,用一樣的 code 都沒問題,但這次卻一直遇到以下的錯誤:
 Execute case encounter an error: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) 

還有一次是這樣的錯誤: Execute case encounter an error: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) 

後來才發現是因為 docker 還在啟動⋯⋯

如果文章有幫助到你可以在 LikeCoin 上幫我拍手喔