TrinoDB cli 中將query 結果輸出成csv 的方式

剛好工作上用到,記錄一下…. 這樣以後再用到時就只要稍微改一下相關的參數就好了XD

trino --server localhost:8080 \
 --user george \
 --execute 'SELECT * FROM A as a
  LEFT JOIN b ON a.id = b.id
  WHERE a.id > 0' \
 --output-format CSV > ~/workspace/mds_object.csv

Reference:

Google 的新程式語言Carbon

Google 最近發表了新的程式語言 Carbon, 其主要的目的是用來作為C++的後繼語言;從目前的資訊可以知道,它的角色比較像是 Kotlin 之於 Java, 除了強調現代化的編程方式以外,且能夠繼續支援舊有的C++程式庫(這點其實蠻吸引人的XD)。

通常看到C++程式語言的繼任者,現在大概都會想到Rust吧,但其實定位不太一樣…

Rust 在設計之初主要是作為更安全的系統語言為出發點而設計的,所以它並不相容於既有的C++程式,所以對於已經有許多C++ 程式的組織而言,使用Rust 就相當於要改寫許多內部的程式…

Carbon在這邊則採用類似於Kotlin的模式,新的語法但又可與公司現有的C++程式一起編譯的特性,想必正式GA之後應該可以有不錯的發展…

Reference:

Mac上遇到的warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

這個問題之前遇到過幾次,每次都是透過iTerm2連接到remote linux server時跳出警告… 雖然問題不大,但昨天連到自家的機器又遇到一樣的問題時,還是決定來找一下解決方式!

這個警告主要影響的是使用者在iTerm2上的畫面顯示,只要用到UTF-8的地方會一直出現警告 !

解決方式

網路上找了一下相關的解決方式以後,大概可以分為兩種方式處理:

Server 端的解決方式

將下列的設定加入到 /etc/environment 裡面

LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Client 端的解決方式(Mac)

將下列兩行環境變數加入到使用者的 ~/.bashrc~/.zshrc(基本上看client端這邊的shell環境)

export LC_ALL=en_US.UTF-8
export LANG=US.UTF-8

我目前採用Client端的解決方式,再重新做 source ~/.zshrc以後,目前就沒在遇到問題了!

Reference:

如何寫好Logs

寫好Log對我而言一直是一項重要的技能, 因為它可以讓問題發生時, 讓開發者用最短的時間找到並解決問題… 剛好在Hacker News上看到這篇 Logging in Python like a PRO , 順便紀錄一下這位作者的一些觀點…

好的Log所需具備的特性

* Descriptive
* Contextual
* Reactive

They’re descriptive in the sense that they give you a piece of information, they’re contextual because they give you an overview of the state of things at the moment, and finally, they’re reactive because they allow you to take action only after something happened (even though your logs are sent/consumed real-time, there’s not really something you can do to change what just happened).

https://guicommits.com/how-to-log-in-python-like-a-pro/

簡單來說如果一段log可以具備上述三個特性, 作者就認為可以讓log的讀者能夠更輕鬆的定位問題的發生點, 以及相對應的事件背景 !

Log 的時機點

As a rule of thumb consider logging:

* At the start of relevant operations or flows (e.g. Connection to third-party, etc);

* At any relevant progress (e.g. Authentication successful, got a valid response code, etc);

* At the conclusion of an operation (e.g. EITHER succeeded or failed);

https://guicommits.com/how-to-log-in-python-like-a-pro/

至於說何時要寫Log呢? 作者這邊指出事件的起始點, 相關的處理進度發生時, 以及事件處理完成時都是適合Log的時間點 !!!

Python 下的Logging的一些範例設定

Python上的一些Log設定我就不太熟了, 先紀錄一下之後可以看看….

總結

這篇文章算是簡單的提要了寫Log時的一些大方向, 這樣之後要寫也蠻適合當參考…

Reference:

透過Dehydrated來設定Let’s encrypt

之前是使用Certbot來更新我這個網誌的Let’s encrypt certificate,運作上也還算正常,但自動更新cert這邊常常更新不了(這部分感覺應該是我設定上的問題)…

後來在公司上, DK有提到了dehydrated這個輕量化的Let’s enrypt 設定工具,實際上去快速看了一下它的repoistory以後,真的覺得對於一般的Linux 環境使用上蠻友善的(因為它所需要的工具通常都是Linux 系統預設的工具)。

快速掃完以後,直接進入正題關於設定上的相關指令… (這邊直接參考 DK 的 wiki上的設定)

安裝Dehydrated

# using a temporary directory to download the dehydrated
cd ~/tmp
wget "https://raw.githubusercontent.com/dehydrated-io/dehydrated/master/dehydrated"
chmod +x dehydrated
sudo mv dehydrated /usr/local/bin/

Dehydrated環境設定

# create directories that dehydrated will need
sudo mkdir -p /etc/dehydrated /var/www/dehydrated

#change to the dehydrated dir
cd /etc/dehydrated

# setup the config
echo 'OCSP_MUST_STAPLE=yes' | sudo tee -a config
echo 'KEYSIZE=2048' | sudo tee -a config
echo 'WELLKNOWN=/var/www/dehydrated' | sudo tee -a config

# setup the domain file
echo 'blog.gechen.org' | sudo tee -a domains.txt
 

設定Nginx

這邊的範例主要是透過Nginx來當做之後dehydrated 執行時,用來回應Let’s encrypt 的challenge…

下面就直接貼Nginx 的對應domain的範例設定檔

server {
     listen 80;
     server_name blog.gechen.org;
     rewrite ^(.*) https://$host$1 permanent;
 }

server {
     listen 443 ssl;
     server_name blog.gechen.org;
     
     index index.php;
     ssl_certificate /etc/dehydrated/certs/blog.gechen.org/fullchain.pem;
     ssl_certificate_key /etc/dehydrated/certs/blog.gechen.org/privkey.pem;


     # ... skip some configs

   
     # this part is for dehydrated
     location /.well-known/acme-challenge/ {
        alias /var/www/dehydrated;
     }
 }

執行Dehydrated 來更新Let’s encrypt certs

如果是第一次使用 dehydrated 則要額外執行下面指令

sudo dehydrated --register --accept-terms

透過下面的指令來做Let’s encrypt certificate的申請/更新

# the following command will apply/renew certificates for the domains in file: /etc/dehydrated/domains.txt
sudo dehydrated -c

# or we can also directly use command below to apply for specific domain certificate
sudo dehydrated -c -d blog.gechen.org

設定自動更新certificate的cron jobs

這邊直接引用DK 大大的wiki範例來設定 weekly 的憑證更新…

echo -e '#!/bin/bash\nexport PATH=/usr/sbin:/usr/bin:/bin:"${PATH}"\nsleep $(expr $(printf "%d" "0x$(hostname | md5sum | cut -c 1-8)") % 86400); dehydrated -c && ( service nginx reload )' | sudo tee /etc/cron.weekly/dehydrated; sudo chmod 755 /etc/cron.weekly/dehydrated 

References:

透過jq 將json檔案格式輸出成 env格式

剛好工作上有這個需求, 就順便找了一下看 jq 指令是否可以簡單的做到這件事…

測試了下面的指令以後, 看起來真的是頗好用, 一行指令就可以把 json 轉成 env 了!

cat example.json| jq -r 'to_entries[] | [.key,.value] | join("=")' > example.env

Reference:

Database diff

從DK的blog上看到的分享工具 data-diff 後, 快速看了一下它的說明文件以後, 感覺這東西有需求的話應該會蠻不錯用的!

看起來可以比對多個data source的資料表, 而且預計支援的資料庫或相關服務也蠻多是市面上常見的… 蠻適合以後有需要時再來試看看.

Reference: