Skip to content

Instantly share code, notes, and snippets.

@zwh8800
zwh8800 / datetime.lua
Last active August 30, 2024 12:16
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 / 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 / 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
package main
import (
"fmt"
"log"
zmq "github.com/pebbe/zmq4"
uuid "github.com/satori/go.uuid"
)
@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 ""
}
@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
}