Skip to content

Instantly share code, notes, and snippets.

View KScaesar's full-sized avatar

Caesar M. Tsai KScaesar

View GitHub Profile
type ReadCacheProxy[Input, ViewModel any] struct {
ReadCache func(input *Input) (output *ViewModel, err error)
ReadDatabase func(input *Input) (output *ViewModel, err error)
WriteCache func(output *ViewModel) error
Key string
Locks *sync.Map
}
@KScaesar
KScaesar / commit-msg
Created July 3, 2024 15:28
check git commit-msg
#!/bin/sh
commit_msg_file=$1
commit_msg=$(cat "$commit_msg_file")
date_regex="^[0-9]{4}-[0-9]{2}-[0-9]{2}"
if ! echo "$commit_msg" | grep -qE "$date_regex"; then
echo "Error: commit message must start with a date in YYYY-MM-DD format."
exit 1
fi
@KScaesar
KScaesar / doc.md
Last active July 1, 2024 02:08
data schema example

說明

委刊項(campaign)通常指的是一個有計畫、有組織的廣告活動或宣傳活動。 這些活動通常是為了達成特定的市場目標或促進產品或服務的銷售而設計的。 一個廣告委刊項可能包括多種媒體形式,如電視、網路、報紙、廣播、社交媒體等,並且會有特定的時間框架和預算。

Redis Data Schema

key XXX

@KScaesar
KScaesar / multiplex.py
Created January 5, 2024 17:15
message mux tool for python
from dataclasses import dataclass, field, ClassVar
from typing import Callable, Union, Optional, Any
from enum import Enum
Pattern = Union[Enum, str, int]
Message = Any
MessageHandler = Callable[[Message], None]
MessageDecorator = Callable[[MessageHandler], MessageHandler]

mongo shell

db.variousInstance.aggregate([
    {
        $match: {}
    },
    {
        $sort: {createAt: -1},
    },
    {
@KScaesar
KScaesar / main.go
Created February 12, 2020 06:11
測試 go 介面的動態執行
// main.go
package main
type Duck interface {
Quack()
}
type Cat struct {
Name string
}
@KScaesar
KScaesar / stringSearch.js
Last active April 13, 2019 09:46
Rabin-Karp 演算法 多模式匹配
function RabinKarpSet(string s[1~K], string patterns[1~N])
//用hash table or Cuckoo Filter 來儲存敏感詞彙相關資料
set hsSet := emptySet
//前置處理
foreach p in patterns
insert hash(p[1~M]) into hsSet
hs := hash(s[1~M])
//匹配運算
type T struct {
}
var p *T
func New() *T {
if p == nil {
p = new(T)
}
return p
//問題1用到的struct
type IssuesSearchResult struct {
TotalCount int `json:"total_count"`
//為什麼使用 struct pointer 作內嵌欄位
//不能直接定義為
//Items []Issue ?
Items []*Issue
}
//問題1用到的struct
package main
import (
"fmt"
"net/http"
"sync"
)
var mu sync.Mutex
var count int