使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)就是这样!
| func UnquoteCStyleString(raw string) (string, error) { | |
| state := "" | |
| results := "" | |
| hexBuffer := "" | |
| scanner := bufio.NewScanner(bytes.NewBufferString(raw)) | |
| scanner.Split(bufio.ScanBytes) | |
| index := 0 | |
| for scanner.Scan() { |
| // 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" |
| // 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" |
| 根据文件头信息判断文件后缀或者mimetypes: https://www.garykessler.net/library/file_sigs.html | |
| mime公开信息:https://cgit.freedesktop.org/xdg/shared-mime-info/ |
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "os/exec" | |
| "time" | |
| ) | |
| type killCmdForce func(exec.Cmd) |
| # | |
| # 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() |
使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)就是这样!