Skip to content

Instantly share code, notes, and snippets.

View leafsummer's full-sized avatar
🎯
Focusing

LeafSummer leafsummer

🎯
Focusing
View GitHub Profile
@leafsummer
leafsummer / interactive_python_shell.py
Created July 2, 2019 02:36
[interactive shell for click]
#!/usr/bin/env python
import click
@click.group()
def main():
"""
simple command manage tool
"""
@leafsummer
leafsummer / timeoutset.go
Created June 10, 2019 09:40
[timeoutset with golang]
package main
import (
"sync"
"time"
)
type TimeoutSet struct {
sync.RWMutex
time map[string]time.Time
@leafsummer
leafsummer / leakybuf.go
Created June 10, 2019 07:12
[leakybuf]
// Package leakybuf provides leaky buffer.
// It's based on the example in Effective Go.
package leakybuf
type LeakyBuf struct {
bufSize int // size of each buffer
freeList chan []byte
}
// NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each
@leafsummer
leafsummer / subssr.sh
Created June 10, 2019 06:40
[subssr]
#!/bin/bash
# Usage:
# bash <(curl -s https://raw.githubusercontent.com/mixool/script/debian-9/subssr.sh)
# wget --no-check-certificate https://raw.githubusercontent.com/mixool/script/debian-9/subssr.sh && chmod +x subssr.sh && bash subssr.sh
declare -A my_ss_dic
declare -A my_ssr_dic
declare -A my_sub_dic
######################################################## EDIT BELOW ########################################################
@leafsummer
leafsummer / log_for_color.go
Created June 5, 2019 03:23
[log for color]
package main
// This logging trick is learnt from a post by Rob Pike
// https://groups.google.com/d/msg/golang-nuts/gU7oQGoCkmg/j3nNxuS2O_sJ
import (
"flag"
"fmt"
"io"
"log"
@leafsummer
leafsummer / exec_cmd.go
Last active May 17, 2019 13:01
[exec the command in shell]
package main
import (
"os/exec"
"runtime"
"strings"
"github.com/axgle/mahonia"
)
package main
import (
"path/filepath"
"fmt"
"os"
"strings"
"log"
)
@leafsummer
leafsummer / etcd_lock.go
Created May 7, 2019 07:40
[etcd lock by golang]
package main
import (
"context"
"fmt"
"go.etcd.io/etcd/clientv3"
"time"
)
func main() {
@leafsummer
leafsummer / get_local_ip.go
Last active May 6, 2019 11:02
[get local ip with golang]
package main
import (
"net"
"fmt"
)
func GetLocalIP() (ipv4 string, err error) {
var (
addrs []net.Addr
@leafsummer
leafsummer / wtforms_translations.py
Created April 29, 2019 08:41
[wtforms translations]
from flask_wtf import FlaskForm
class MyFlaskForm(FlaskForm):
class Meta(FlaskForm.Meta):
def get_translations(self, form):
return get_translations(["zh", "en"])
def fetch_an_error(self):
message = ""
for _, messages in self.errors.iteritems():