Skip to content

Instantly share code, notes, and snippets.

View ForrestSu's full-sized avatar
😀
coding

ForrestSu ForrestSu

😀
coding
View GitHub Profile

golang.org rate limiter:

	rl := rate.NewLimiter(1000000, 1)
 
	last := time.Now()
	for i := 0; i < 10; i++ {
		rl.Wait(context.Background())
		cur := time.Now()
		fmt.Println("last", cur.Sub(last))
 last = cur
@ForrestSu
ForrestSu / cloc_go_without_testing.sh
Last active December 28, 2022 05:30
仅统计 Go 源代码行数 (不含测试文件)
# 思路: 使用 cloc 的匹配规则,再排除test.go 文件即可;
## 方式一:使用 cloc 工具
1 统计 Go 源代码行数 (含测试文件)
cloc --match-f '\.go$' .
2 仅统计 Go 测试文件行数
cloc --match-f '_test\.go$' .
3 仅统计 Go 源代码行数 (不含测试文件)
@ForrestSu
ForrestSu / userscript-remove-woa-watermark.js
Last active July 28, 2022 13:33 — forked from imyelo/userscript-remove-woa-watermark.js
UserScript - Remove WOA Watermark
// ==UserScript==
// @name Remove WOA Watermark
// @version 0.1
// @author yelo <zhihuzeye@gmail.com>
// @match *://km.woa.com/**
// @match *://csig.lexiangla.com/**
// @match *://mk.woa.com/**
// @match *://iwiki.woa.com/**
// @match *://qcloud.oa.com/**
// @match *://ieop.oa.com/**
@ForrestSu
ForrestSu / clean_code.md
Created April 28, 2022 03:57 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@ForrestSu
ForrestSu / struct_to_map.go
Last active April 26, 2022 12:52
Golang Struct To Map By JSON tag
// StructToMap 将 struct 对象编码为 map
func StructToMap(data interface{}) map[string]string {
reflectValue := reflect.ValueOf(data)
if reflectValue.Kind() == reflect.Ptr {
reflectValue = reflectValue.Elem()
}
reflectType := reflectValue.Type()
kvs := make(map[string]string)
for i := 0; i < reflectValue.NumField(); i++ {
tag := reflectType.Field(i).Tag.Get("json")