Skip to content

Instantly share code, notes, and snippets.

View tomcatzh's full-sized avatar

Zhang Xiaofeng tomcatzh

  • Amazon Web Service
  • Guangzhou, China
View GitHub Profile
@tomcatzh
tomcatzh / parseHumanSize.c
Created June 15, 2019 10:05
parseHumanSize #c #atoi
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 December 9, 2017 02:30 — forked from bancek/cue_to_mp3.py
CUE splitter using ffmpeg (to mp3)
cue_file = 'file.cue'
d = open(cue_file).read().splitlines()
general = {}
tracks = []
current_file = None
@tomcatzh
tomcatzh / gzip_compress_reader.go
Last active April 3, 2024 09:30
Wrap a reader to a gzip compress reader using gzip writer :-P
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)
}
#!/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`
#!/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 October 10, 2015 08:37
iOS Shadowsocks chinese website white list 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 October 10, 2015 07:42
iOS Shadowsocks chinese website white list 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 April 1, 2015 06:35
Golang readline and writeline
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 August 29, 2015 14:17
How to using json parser in golang
package main
import (
"encoding/json"
"fmt"
"time"
)
// The custom time format for json
type MyTime time.Time
@tomcatzh
tomcatzh / gist:8f3cd4d652c29db54cdc
Created March 17, 2015 02:47
GoConvey ShouldPanic系列Assertions的用法

GoConvey ShouldPanic系列Assertions的用法

GoConvey简介

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

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

GoConvey初步用法