Skip to content

Instantly share code, notes, and snippets.

View hezhizhen's full-sized avatar

Zhizhen He hezhizhen

  • Shanghai, China
  • 11:09 (UTC +08:00)
View GitHub Profile
@hezhizhen
hezhizhen / sha256sum.go
Last active November 14, 2023 07:58
implement `echo -n $id | sha256sum` in Go
package main
import (
"crypto/sha256"
"fmt"
"strconv"
)
func main() {
fmt.Println(sha256sum(16888)) // dfaf07638f5e92673ef23f8c8878afe8f3580d0fde7fb54b23e841626c3bedbc
@hezhizhen
hezhizhen / sort_version.go
Last active August 7, 2024 06:48
Sort versions for every language
package main
import (
"fmt"
"sort"
"github.com/Masterminds/semver/v3"
)
type Language struct {
@hezhizhen
hezhizhen / main.go
Last active June 8, 2023 18:52
Print numbers in K goroutines for N times. For example, 3 goroutines print 1 2 and 3 respectively and the output should be like 123123123...
package main
import (
"fmt"
"sync"
)
func main() {
printNumbersInKGoroutinesForNTimes(3, 10) // 123123123123123123123123123123
}
@hezhizhen
hezhizhen / generate_certificate.sh
Last active October 18, 2021 06:18
#Certificate
# 生成私钥
$ openssl genrsa -out ssl.key 2048
# 对私钥进行加密
$ openssl rsa -in ssl.key -des3 -out encrypted.key
# 私钥生成证书请求(根据需求选择加密私钥或者非加密私钥)
$ openssl req -new -key ssl.key -out ssl.csr -sha256
# 用 ca 证书给证书请求签证
$ openssl x509 -req -in ssl.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out ssl.crt -days 365 -sha256
@hezhizhen
hezhizhen / main.go
Last active October 18, 2021 06:24
use #Kubernetes API to execute `kubectl exec` to save stdin to a file
package main
import (
"bytes"
"context"
"os"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
@hezhizhen
hezhizhen / append_slice.go
Last active May 4, 2018 06:59
Append to slice when ranging
package main
import "fmt"
func main() {
v := []int{1,2,3}
for i := range v {
v = append(v, i)
}
fmt.Println(v)
@hezhizhen
hezhizhen / hello-world.go
Last active May 4, 2018 06:58
hello world
package main
import "fmt"
func main() {
fmt.Println("hello world")
}