leetcode-88-merge-sorted-array
題目You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing order.
The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n ele ...
leetcode-80-remove-duplicates-from-sorted-array-ii
題目Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same.
Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. It ...
leetcode-26-remove-duplicates-from-sorted-array
題目Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.
Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:
Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initiall ...
leetcode-27-remove-element
題目Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.
Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:
Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as ...
Meta 商品目錄新增影片實作 - video[0].url 到底是甚麼?
前言Meta 在 2024/05/20 發布了可以提升廣告投放成效的 新方法,就是在商品目錄中上傳影片的方式。但是,到底要怎麼把影片塞到商品目錄,是一個大問題,於是造就了這篇不斷測試的文章。
文件解讀根據 Meta 官方說明文件,可以在原先的商品目錄上傳一個叫 video[0].url 的欄位,而且單個商品,可以上傳至多 20 的影片,如: video[1].url ~ video[19].url。但是,這個欄位名稱真的太特別,不像一般 price 欄位,方便解讀。所以讓人很困惑。
此外,目前商品目錄的格式有很多種,包含 csv, xml, google sheet 等等。如果 video[0].url 要轉換成 xml 格式,tag 又要取名成甚麼,文件並沒有寫得很清楚,因為我們主要是用 API 產出 xml 格式的商品目錄。
後來,找到了這篇 文件,貌似有點頭緒。如果格式是 csv,欄位名稱真的是 video[0].url。
要注意的是,商品目錄中有影片的商品數量限制,目前不能超過 30000 個。
xml 格式也有附上範例,欄位名稱要叫 <v ...
GKE 如何綁對外的固定 IP ? 利用 VPC 網路、Cloud Router、搭配 Cloud NAT 設定 External IP Address
前言近期,客戶需要主動提供商品資料給我們,而且是要是用提供 api 的方式,但是需要綁固定 IP。也就是說,只有客戶允許的 IP 列表 ( 白名單 ) 才能讀到 api 的資料。但我們的服務是使用 GKE 的 Cronjob,所以問題就變成: 要怎麼在 GKE 上綁固定 IP 呢?
概念透過建立 VPC ( Virtual Private Cloud ) 來控制 GKE 內部網路的串連、分配子網路。並經由 Cloud Router 來處理與 外網或其他 VPC 連接的路由,最後經由 Cloud NAT 來管理出站流量。此時,出站流量就可以綁定固定的 External IP,這樣所有從 VPC 出去的請求都會有固定的 IP。
檢查 Node 節點 IP在 GKE 中,Pod 通常會使用節點 (Node) 的外部 IP 來進行對外的 API 請求。可以使用指令 kubectl get nodes -o wide 來查看節點的外部 IP。
即便使用 Cloud NAT 綁固定 IP 後,執行 kubectl get nodes -o wide 顯示的 EXTERNAL-IP 也會是 No ...
WSL2 移動到非 C 槽的 HDD - Docker Desktop | Node.js | PosrgreSQL | google cloud SDK 要用 windows 還是 Linux 版本?
前言我一直以為正在使用的 windows 電腦只有 128G 的 SSD。工作一年多以來,發現空間嚴重不足,實在是撐不下去了。本來想換 Mac,但覺得太貴,想說先升級硬體看看,沒想到居然解鎖了 1T 的 HDD 硬碟!!
原來,門市人員跟我說,我的硬碟被鎖起來了,所以電腦上才看不到。解鎖步驟也意外簡單,就是按右鍵解鎖而已,真的很奇葩。所以,當下我簡單換了電池 ( NTD 3500 ) + 記憶體 ( 16 GB | NTD 2000 ),SSD 等我備份完畢再來換,目前詢價是 480 GB,2500,也是很特別的規格 🤔。
因為 SSD 容量真的太小了,所以我打算 把整個 WSL2 和 Docker 搬到 HDD 裡面。雖然可能會跑比較慢,但也許是目前折衷最好的辦法。
WSL2 搬移
Terminal 使用 Window PowerShell
查看 wsl 版本: wsl -l --all -v
將系統資料匯出,把整個 WSL2 系統 + 資料匯出成壓縮檔: wsl --export Ubuntu-22.04 D:\wsl-ubuntu22.04.tar
取消目前正在使 ...
如何靠部落格流量賺廣告費 - 加入 Google Analytics 4 和 Google Adsense 吧
前言除了用 Google Search Console 追蹤網站流量,最常用的應該就是 GA4 ( Google Analytics 4 ),GA4 是用來追蹤網站使用者數據的強大工具,只要安裝專屬的追蹤碼,就可以追蹤網站的流量、事件等數據。
加入 Google Analytics 4
申請 Google Analytics 帳戶
新增資料串流: 登入 GA,點選左下角 管理> 資料收集與修改 > 資料串流 > 點選新增串流 > 網頁,接著把串流名稱 ( 可任意填 )、串流網址填好,點選新增
獲取評估 ID: 新增完資料串流就會跳出評估 ID
修改 _config.butterfly.yaml, 把評估 ID ( G 開頭的一串代碼 ) 填到 # Google Analytics 區塊中
_config.butterfly.yaml12# Google Analyticsgoogle_analytics: G-xxxxx
驗證
按右鍵,檢查網頁原始碼,打開 chrome dev tool ( 開發工具 ),切到 Element 頁籤,搜尋 ...
從工程師的角度看待廣告 Part1 - 事件篇
前言菜鳥工程師剛進入廣告投放業,對於廣告投放在做甚麼,可說是一點都不了解。光是搞懂廣告的 domain knowledge 可能就要花一段時間。本篇文章將分享透過工程師的角度看待廣告投放工程,以及介紹日常廣告後台相關的疑難雜症,但不會琢磨於更深層的廣告知識及策略,比較著重技術上的實作觀念。。
廣告工程概念介紹了解廣告前,可能要先了解廣告中的一些重要的角色,如
廣告代理商
廣告商 ( 如: Google, Meta )
以電商來說,在投廣告的過程中,可能會發現自己投的成效不是那麼好,所以會找廣告代理商的協助。廣告代理商通常會蒐集、並分析使用者的行為等數據,以製定投遞廣告的策略,來提升廣告投放的成效。
關於廣告的成效,個人認為比較黑盒子一點,因為我們不知道廣告商內部競價的演算法,所以只能靠廣告商提供的成效數字,如轉換率、轉換次數等,來判定廣告的成效。
也就是說,透過這些廣告成效的數字,不斷修正廣告投遞的模式,最後形成一套所謂的「廣告投遞策略」,之後在投廣告時,可以依循這樣的策略及經驗,保持一致的廣告成效。
網站發送事件在廣告投遞的過程,透過事件的發送可以更了解使用者的行為。但是發送事件 ...
使用 Uvicorn 監聽 FastAPI 框架的 web server,但是 reload 卻失效?
前言前陣子接到公司新的專案,打開專案發現 docker-compose.yml 都寫好了,很興奮直接 docker compose <service> 然後開始修改好一些商業邏輯,存檔後,以為 uvicorn 自動會 reload server。結果,存檔後甚麼事都沒有發生 !!!
接著,我把整個 docker image 刪掉重建,然後再重啟一個 contanier。疑好了?! 有吃到最新的商業邏輯,但我不會每次都要重建 image 吧? 實在是太麻煩 🤯
發現 uvicorn reload 的問題我研究了一下 docker-compose.yml 到底做了甚麼事,其中我要用到的 service 如下:
docker-compose.yml123456789101112131415161718192021222324supplier-api: <<: *dev build: context: ./services/ dockerfile: supplier/docker/api.Dockerfile ports: - '8 ...