Skip to content

Instantly share code, notes, and snippets.

View ktlast's full-sized avatar

ktlast ktlast

View GitHub Profile
@ktlast
ktlast / io_benchmark.sh
Created September 11, 2025 07:00
IO benchmark
#!/bin/bash
io_benchmark() {
# Fixed block size and initial conditions
local bs_size=4 # MB fixed
local count=512 # start count
local timeout_val=1 # seconds initial timeout
local tmpfile="/tmp/io_spike"
local min_count=1 # stop at count=1
local max_timeout=64 # stop at timeout=64s
@ktlast
ktlast / g-back-main.sh
Created July 19, 2025 09:13
Git switch back and sync to default branch, then delete the feature branch
g-back-main () {
# Determine current and default branch names
local current_branch default_branch
current_branch=$(git symbolic-ref --short HEAD)
# Try to detect default branch (main or master)
if git show-ref --quiet refs/remotes/origin/main; then
default_branch="main"
elif git show-ref --quiet refs/remotes/origin/master; then
default_branch="master"
@ktlast
ktlast / handy-kubectl.sh
Last active July 11, 2025 02:21
Working with aliases with `kubectl` to have simpler commands while operating Kubernetes cluster.
#!/bin/bash
#
# Usage:
# [Basic]
# n <namespace>
# kgn deploy
# kgn pod
# kdn pod <pod_name>
# ...etc
#
import time
CONSTANT_STRINGS = (
"0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" # 移除 i, I, l, o, O
)
def to_custom_radix(num: int, string_pool: str) -> str:
q, r = divmod(num, len(string_pool))
@ktlast
ktlast / glance-tw-stock.sh
Last active June 19, 2024 10:38
用 shellscript 上班看台股
#!/bin/bash
# Author: ktlast
# Blog/Doc: https://ktlast.com/p/glance-tw-stock-cli%E5%81%87%E5%A6%82%E4%BD%A0%E9%9C%80%E8%A6%81%E7%94%A8-cli-%E4%B8%8A%E7%8F%AD%E5%81%B7%E7%9C%8B%E7%9B%A4/
# shellcheck source=./
set -e
TSE_API_URL_PREFIX='https://mis.twse.com.tw/stock/api/getStockInfo.jsp?json=1&delay=0&ex_ch='
REFRESH_INTERVAL=${1:-3}
OUTPUT_ENV_FILE=${2:-"./.glance.sh.env"}
@ktlast
ktlast / info-demo.sh
Created February 19, 2024 06:23
Show section line as prefix for info logs/messages
#!/bin/bash
function info_start {
echo "╷ "
}
function info_body {
echo "│ $*"
}
@ktlast
ktlast / curl-slack.md
Last active November 14, 2023 09:49
Curl-Slack-Attachment: Send attachments payload to slack via curl; uses single quotes to form payload with variables.

Send slack attachment via curl

I. Bot Token

  • Note those single & double quotes around variables.
  • Note there are backticks around $(hostname -I) to style it as code block.
TITLE="$1"
MESSAGE="$2"
@ktlast
ktlast / tw-stock-api.md
Last active June 19, 2024 10:35
證交所 API
# Left rotate
def lrot(byte_string, offset):
for i in range(offset):
byte_string = byte_string[1:]+byte_string[0]
return byte_string
# Transfer num to binary (string), e.g "00101011"
def b(num, bits=8):
if -num > 2**(bits-1) or num > 2**(bits-1) - 1:
# coding=utf-8
import smtplib
import csv
from email.mime.text import MIMEText
# Prepare a template as mail body.
def get_template():
with open("Mail\\Text\\Template\\Path", "r", encoding="utf-8") as template_txt:
template = template_txt.read()
return template