Skip to content

Instantly share code, notes, and snippets.

View whchi's full-sized avatar
:octocat:

whchi whchi

:octocat:
View GitHub Profile
@whchi
whchi / env-to-json.sh
Created December 16, 2025 09:09
convert env file data to json
#!/usr/bin/env bash
# This script converts environment variables to a JSON object.
# Usage: ./env-to-json.sh [.env file path]
set -euo pipefail
ENV_FILE="${1:-.env}"
# Function to escape JSON strings
json_escape() {
# 1. 安裝 pyenv(用 Homebrew,超簡單)
brew install pyenv
# 2. 加入 pyenv 到你的 shell(zsh,macOS 預設)
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
# 3. 安裝 Python 2.7.18(pyenv 會自動偵測 arm64 並編譯,過程約 2-5 分鐘)
@whchi
whchi / Dockerfile
Last active October 29, 2025 08:37
bun with prisma and distroless example
FROM oven/bun:1.3.1 AS build
WORKDIR /app
# Cache packages installation
COPY package.json package.json
COPY bun.lock bun.lock
COPY ./prisma ./prisma
RUN bun install --frozen-lockfile
@whchi
whchi / change_postgres_ownership.sql
Last active August 6, 2025 07:43
change_postgres_ownership.sql
DO
$$
DECLARE
rec RECORD;
BEGIN
-- 更改表 (Tables)
FOR rec IN
SELECT n.nspname, c.relname
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
@whchi
whchi / watermark.ts
Created March 6, 2025 03:07
adding watermark to pdf using sharp.js & pdf-lib.js
async createWaterMark({
width,
height,
text,
fontSize,
fontColor,
opacity,
}: CreateWaterMarkDto) {
const svg = `
<svg width="${width}" height="${height}">
@whchi
whchi / dumpdbschema.py
Created February 24, 2025 09:19
dump sqlalchemy database schema in python
from sqlalchemy import MetaData
from sqlalchemy.sql.ddl import CreateTable
import typer
from app.helpers import app_path
from database.connection import engine
app = typer.Typer()
@whchi
whchi / gist:45abd5692cff93dc00b20abc4b4c3f73
Created December 13, 2024 08:12
sonarqube gitlab yml
check-sonarqube-pr:
stage: check
image:
name: sonarsource/sonar-scanner-cli:11
entrypoint: ['']
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
allow_failure: true
rules:
@whchi
whchi / measureUsage.ts
Created December 9, 2024 07:58
評估某個 function 的 usage
/**
* usage measureResourceUsage(async()=>{}, logger, label)
* @param func
* @param logger
* @param label
* @private
*/
async measureUsage<T>(
func: () => Promise<T>,
logger: Logger,
@whchi
whchi / google-auth.js
Created November 20, 2024 03:54
google-auth
export const googleLoginActions = {
getAuthUrl: () => {
const query = {
client_id: oauth_google.client_id,
redirect_uri: oauth_google.redirect_uri,
response_type: "code",
scope: oauth_google.scopes,
}
const url = new URL(oauth_google.endpoint)
url.search = new URLSearchParams(query).toString()
@whchi
whchi / dto.php
Created October 7, 2024 10:25
php dto example
<?php
class BaseDto
{
/**
* Constructor that dynamically sets properties based on the given associative array
*
* @param array $data The data to be used for setting properties
*/
public function __construct(array $data)