Skip to content

Instantly share code, notes, and snippets.

@zwh8800
zwh8800 / rwlock.go
Created June 16, 2016 07:02
读写锁不能这么用。。。
func (bus *EventBus) find(register *Register) int {
bus.registersLock.RLock()
defer bus.registersLock.RUnlock()
for i := 0; i < len(bus.registers); i++ {
if bus.registers[i] == register {
return i
}
}
return -1
}
@zwh8800
zwh8800 / json.go
Created June 22, 2016 07:09
美丽的debug
package util
import "encoding/json"
func JsonStringify(obj interface{}, intent bool) string {
if intent {
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return ""
}
package main
import (
"fmt"
"log"
zmq "github.com/pebbe/zmq4"
uuid "github.com/satori/go.uuid"
)
@zwh8800
zwh8800 / json.cs
Last active May 9, 2017 10:34
json parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Dynamic;
namespace Json
{
public class Json
@zwh8800
zwh8800 / range.lua
Created May 22, 2017 08:41
range in lua using coroutine
function range(n)
return coroutine.wrap(function()
for i = 1, n, 1 do
coroutine.yield(i)
end
end)
end
function main()
for i in range(10) do
@zwh8800
zwh8800 / datetime.lua
Last active February 21, 2023 10:28
lua ISO 8601 datetime parser - https://repl.it/IQuI/5
function parse_json_date(json_date)
local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%+%-])(%d?%d?)%:?(%d?%d?)"
local year, month, day, hour, minute,
seconds, offsetsign, offsethour, offsetmin = json_date:match(pattern)
local timestamp = os.time{year = year, month = month,
day = day, hour = hour, min = minute, sec = seconds}
local offset = 0
if offsetsign ~= 'Z' then
offset = tonumber(offsethour) * 60 + tonumber(offsetmin)
if xoffset == "-" then offset = offset * -1 end
@zwh8800
zwh8800 / case-sensitive-fs.bash
Created May 26, 2017 08:20
create a case sensitive filesystem on macOS
sudo hdiutil create ~/Documents/case-sensitive.dmg -volname "case-sensitive" -size 10g -fs "Case-sensitive HFS+"
sudo hdiutil mount ~/Documents/case-sensitive.dmg
cd /Volumes/case-sensitive
@zwh8800
zwh8800 / 66.go
Created August 2, 2017 12:58
66.go
// quu..__
// $$$b `---.__
// "$$b `--. ___.---uuudP
// `$$b `.__.------.__ __.---' $$$$" .
// "$b -' `-.-' $$$" .'|
// ". d$" _.' |
// `. / ..." .' |
// `./ ..::-' _.' |
// / .:::-' .-' .'
// : ::''\ _.' |
@zwh8800
zwh8800 / shadowsocksr
Created September 6, 2017 05:37
shadowsocksr init script for openrc
#!/sbin/openrc-run
name=shadowsocksr
cfgfile="/usr/local/shadowsocksr/user-config.json"
command="/usr/local/shadowsocksr/shadowsocks/server.py"
command_args="--pid-file /var/run/shadowsocksr.pid -c /usr/local/shadowsocksr/user-config.json"
pidfile="/var/run/shadowsocksr.pid"
start_stop_daemon_args=""
command_background="yes"
command_user="root"
{"channels":[{"name":"CCTV-1综合高清","url":"http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8"},{"name":"CCTV-3综艺高清","url":"http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8"},{"name":"CCTV-5+体育赛事高清","url":"http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8"},{"name":"CCTV-6电影高清","url":"http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8"},{"name":"CCTV-8电视剧高清","url":"http://ivi.bupt.edu.cn/hls/cctv8hd.m3u8"},{"name":"CHC高清电影","url":"http://ivi.bupt.edu.cn/hls/chchd.m3u8"},{"name":"北京卫视高清","url":"http://ivi.bupt.edu.cn/hls/btv1hd.m3u8"},{"name":"北京文艺高清","url":"http://ivi.bupt.edu.cn/hls/btv2hd.m3u8"},{"name":"北京纪实高清","url":"http://ivi.bupt.edu.cn/hls/btv11hd.m3u8"},{"name":"湖南卫视高清","url":"http://ivi.bupt.edu.cn/hls/hunanhd.m3u8"},{"name":"浙江卫视高清","url":"http://ivi.bupt.edu.cn/hls/zjhd.m3u8"},{"name":"江苏卫视高清","url":"http://ivi.bupt.edu.cn/hls/jshd.m3u8"},{"name":"东方卫视高清","url":"http://ivi.bupt.edu.cn/hls/dfhd.m3u8"},{"name":"安徽卫视高清","url":"http://ivi.bupt.edu.cn/hls/ahhd.m3u8"},{"name":"黑龙江卫视高清","url":"http://ivi.bupt.edu.cn/hls/hljhd.m3u8"},{"name":"辽宁卫