Skip to content

Instantly share code, notes, and snippets.

@jerryan999
jerryan999 / specification_pattern.go
Created July 13, 2023 15:27
specification pattern in golang
package main
import "fmt"
type Employee struct {
name string
age int
salary int
location string
}
@jerryan999
jerryan999 / use_duckdb_do_sql.py
Created May 17, 2023 11:44
how to use duckdb to query local or s3 files and then do some analysis
import duckdb
import json
import os
import shutil
import time
import gzip
import os
conn = duckdb.connect(database="cloudfront-log2.db", read_only=False)
@jerryan999
jerryan999 / 04:00:00_04:59:59_S0.json
Last active May 12, 2023 00:34
使用duckdb进行ETL操作: 解析本地cloud logging传送过来的日志json,分区输出成多个parquet文件
{"httpRequest":{},"insertId":"8bw4pxf29tneo","jsonPayload":{"body":{"deviceInfo":{"appId":"art.puzzle.games.xxx.coloring.free.game","brand":"google","country":"CN","deviceType":"mobile","model":"Pixel 4","osVersion":"11","platform":"ANDROID","screenH":2236,"screenW":1080,"version":"10"},"events":[{"event":"scanSucceed1","info":{"adId":"111111","adjustId":"111111","deviceId":"xxxxx","firebaseId":"111111"},"param":{"code":{"s":"https://xxxxxx"},"code_type":{"s":"QR_CODE"},"count":{"i":12345},"source":{"s":"scanner"},"sum":{"d":12345.123},"type":{"s":"URI"}},"properties":{"country":"yyyyyy","name":"xxxx"},"timestamp":1683608090000},{"event":"scanSucceed2","info":{"adId":"111111","adjustId":"111111","deviceId":"xxxxx","firebaseId":"111111"},"param":{"code":{"s":"https://xxxxxx"},"code_type":{"s":"QR_CODE"},"count":{"i":12345},"source":{"s":"scanner"},"sum":{"d":12345.123},"type":{"s":"URI"}},"properties":{"country":"yyyyyy","name":"xxxx"},"timestamp":1683608090000},{"event":"scanSucceed4","info":{"adId":"111111",
@jerryan999
jerryan999 / get-contract-creation-block.go
Last active July 26, 2023 18:17
How to Get Smart Contract Creation Block Time
package main
import (
"context"
"fmt"
"log"
"math/big"
"sync"
"github.com/ethereum/go-ethereum/common"
package main
import (
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"
"go.uber.org/ratelimit"
@jerryan999
jerryan999 / boredape.json
Last active September 23, 2023 13:00
How to decode smart contract transation
[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"maxNftSupply","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"in
@jerryan999
jerryan999 / find_empty.go
Last active March 5, 2023 23:18
Solve Sudoku in Golang
func findNextEmpty(board [][]byte) (byte, byte, error) {
for j := byte(0); j < 9; j++ {
for i := byte(0); i < 9; i++ {
if board[j][i] == '.' {
return j, i, nil
}
}
}
return byte(0), byte(0), errors.New("no empty cell to fill in")
}
@jerryan999
jerryan999 / chromedp_init.go
Last active August 6, 2022 15:23
How to use chromedp to do a bunch of screenshot tasks on Mac
var (
CHROME_EXEC_PATH = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
USER_DATA_DIR = fmt.Sprintf("/Users/%s/Library/Application Support/Google/Chrome/", GetCurrentUserName())
PROFILE_DIRECTORY = "Default"
)
func GetCurrentUserName() string {
currentUser, _ := user.Current()
username := currentUser.Username
return username
@jerryan999
jerryan999 / Dockerfile
Last active July 20, 2022 16:20
python-application-docker
FROM python:3.9.13-slim as python-deps
RUN apt-get update -y && apt-get install -y gcc
WORKDIR /usr/app
RUN python -m venv /usr/app/venv
ENV PATH="/usr/app/venv/bin:$PATH"
COPY requirements.txt ./
RUN pip install --upgrade pip==20.1.1 && \
pip install -r requirements.txt && \
rm requirements.txt
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {