Skip to content

Instantly share code, notes, and snippets.

View chaleaoch's full-sized avatar
😃
Golang

Zhichao,Feng chaleaoch

😃
Golang
View GitHub Profile
@chaleaoch
chaleaoch / demo.go
Last active April 19, 2023 06:13
for select 用法, 当channel被关闭, 利用ok判断并重置为nil. select 将忽略
go func() {
// in for-select using ok to exit goroutine
for {
select {
case x, ok := <-in1:
if !ok {
in1 = nil
}
// Process
case y, ok := <-in2:
@chaleaoch
chaleaoch / ipint.go
Created November 30, 2022 09:11 — forked from ammario/ipint.go
Golang IP <-> int conversion
func ip2int(ip net.IP) uint32 {
if len(ip) == 16 {
panic("no sane way to convert ipv6 into uint32")
}
return binary.BigEndian.Uint32(ip)
}
func int2ip(nn uint32) net.IP {
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, nn)
import threading
import time
import multiprocessing
lock = threading.Lock()
def thread_target():
lock.acquire()
@chaleaoch
chaleaoch / flask skeleton folder tree
Created March 28, 2022 07:28 — forked from efazati/Py Flask Skeleton
flask folders and files structure
.
├── deploy.py
├── project
│   ├── application.py
│   ├── apps
│   │   ├── articles
│   │   │   ├── forms.py
│   │   │   ├── __init__.py
│   │   │   ├── models.py
│   │   │   └── views.py