Skip to content

Instantly share code, notes, and snippets.

View VillanCh's full-sized avatar
:octocat:
a little of busy for coding

v1ll4n VillanCh

:octocat:
a little of busy for coding
View GitHub Profile
@VillanCh
VillanCh / unquote_cstyle_string.go
Created March 11, 2022 10:04
解析C风格的字符串 Quote
func UnquoteCStyleString(raw string) (string, error) {
state := ""
results := ""
hexBuffer := ""
scanner := bufio.NewScanner(bytes.NewBufferString(raw))
scanner.Split(bufio.ScanBytes)
index := 0
for scanner.Scan() {
@VillanCh
VillanCh / icmpping.go
Created January 14, 2020 08:33
ICMP 协议 Ping
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// taken from http://golang.org/src/pkg/net/ipraw_test.go
package ping
import (
"bytes"
@VillanCh
VillanCh / 2fa.go
Created January 8, 2020 07:46
2fa 双因子认证
// 2fa provides a simple end-to-end example of server side support for google authenticator.
// It sets up a secret for a single user, generates a QR code as a PNG file that the user
// can scan into Google Authenticator, and then prompts the user for a token that the user
// copies from the Authenticator app. We validate the token and print out whether it is valid or not.
package main
import (
// "crypto/rand"
"encoding/base32"
"fmt"
@VillanCh
VillanCh / 公共资源.txt
Created September 9, 2018 02:54
公共资源
根据文件头信息判断文件后缀或者mimetypes: https://www.garykessler.net/library/file_sigs.html
mime公开信息:https://cgit.freedesktop.org/xdg/shared-mime-info/
@VillanCh
VillanCh / exec_with_timeout.go
Created April 22, 2018 06:41
Golang: Execute with a Timeout
package main
import (
"bytes"
"fmt"
"os/exec"
"time"
)
type killCmdForce func(exec.Cmd)
@VillanCh
VillanCh / yaml_load_env.py
Created April 7, 2018 03:19
Using PyYaml load env vars
#
# load yaml by env variables
#
import yaml, os, re
pattern = re.compile( '^\$\{(.*?)(:(.*))?\}$' )
yaml.add_implicit_resolver ( "!env", pattern )
def env_construction(loader, node):
value = loader.construct_scalar(node)
env_var_name, _, default = pattern.match(value).groups()
@VillanCh
VillanCh / tree.md
Created January 23, 2018 13:28 — forked from upsuper/tree.md
一行 Python 实现树

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!