Skip to content

Instantly share code, notes, and snippets.

Avatar

Zhang Xiaofeng tomcatzh

View GitHub Profile
@tomcatzh
tomcatzh / parseHumanSize.c
Created Jun 15, 2019
parseHumanSize #c #atoi
View parseHumanSize.c
uintmax_t parseHumanSize (const char* s) {
char *endp = (char *)s;
int sh;
errno = 0;
uintmax_t x = strtoumax(s, &endp, 10);
if (errno || endp == s) {
errno = EINVAL;
goto ERROR;
}
@tomcatzh
tomcatzh / cue_to_mp3.py
Created Dec 9, 2017 — forked from bancek/cue_to_mp3.py
CUE splitter using ffmpeg (to mp3)
View cue_to_mp3.py
cue_file = 'file.cue'
d = open(cue_file).read().splitlines()
general = {}
tracks = []
current_file = None
@tomcatzh
tomcatzh / gzip_compress_reader.go
Last active Aug 26, 2017
Wrap a reader to a gzip compress reader using gzip writer :-P
View gzip_compress_reader.go
func NewGzipReader(source io.Reader) io.Reader {
r, w := io.Pipe()
go func() {
defer w.Close()
zip, err := gzip.NewWriterLevel(w, gzip.BestSpeed)
defer zip.Close()
if err != nil {
w.CloseWithError(err)
}
View Get EC2 List to Bastion .ssh_config
#!/bin/bash
if [ -z $1 ]; then
FILTER='Name=instance-state-code,Values=16'
else
FILTER=$1
fi
IDs=`aws ec2 describe-instances --filters "$FILTER" | jq '.Reservations[].Instances[].InstanceId' -r`
View My user data for create a new EC2 instance
#!/bin/sh
yum update -y
yum --enablerepo=epel install jq bash-completion -y
cat <<EOT >> /etc/profile.d/aws-cli.sh
if [ $SHELL = "/bin/bash" ]; then
complete -C '/usr/bin/aws_completer' aws
fi
@tomcatzh
tomcatzh / auto.pac
Last active Oct 10, 2015
iOS Shadowsocks chinese website white list pac
View auto.pac
// Based on whitelist v1.2 by https://github.com/n0wa11
function FindProxyForURL(url, host) {
var PROXY = 'SOCKS 127.0.0.1:1983';
if (isPlainHostName(host)) return 'DIRECT';
if (/^\d+\.\d+\.\d+\.\d+$/g.test(host)) return 'DIRECT';
var rules = [
[
'cn',
'lan',
@tomcatzh
tomcatzh / auto.pac
Created Oct 10, 2015
iOS Shadowsocks chinese website white list pac
View auto.pac
// Based on whitelist v1.2 by https://github.com/n0wa11
function FindProxyForURL(url, host) {
var PROXY = 'SOCKS 127.0.0.1:1983';
if (isPlainHostName(host)) return 'DIRECT';
if (/^\d+\.\d+\.\d+\.\d+$/g.test(host)) return 'DIRECT';
var rules = [
[
'cn',
'lan',
@tomcatzh
tomcatzh / readwrite.go
Created Apr 1, 2015
Golang readline and writeline
View readwrite.go
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
@tomcatzh
tomcatzh / json_example.go
Last active Aug 29, 2015
How to using json parser in golang
View json_example.go
package main
import (
"encoding/json"
"fmt"
"time"
)
// The custom time format for json
type MyTime time.Time
@tomcatzh
tomcatzh / gist:8f3cd4d652c29db54cdc
Created Mar 17, 2015
GoConvey ShouldPanic系列Assertions的用法
View gist:8f3cd4d652c29db54cdc

GoConvey ShouldPanic系列Assertions的用法

GoConvey简介

GoConvey是一款优秀的Golang测试框架,可以快速优雅的开发Golang的测试用例,并且提供自动化的测试支持。

同时GoConvey框架提供了丰富的Assertions支持,其中ShouldPanic系列的Assertions提供了优雅的在测试用例中测试Golang panic的方法。

GoConvey初步用法

You can’t perform that action at this time.