Skip to content

Instantly share code, notes, and snippets.

@luw2007
luw2007 / time.go
Last active Nov 28, 2019
AddMonths 增加月份,有许多神奇的case需要处理,例如 1月31日 - 2月28日, 3月31日 - 4月30日。 总的逻辑为,到达下一个月的同一天,若无效前推至有效
View time.go
package main
import (
"fmt"
"testing"
"time"
)
// WHY:
//
@luw2007
luw2007 / trimspace.go
Created May 19, 2019
TrimSpace remove space, also in sentence. like: " a \t\r\n b " -> "a b"
View trimspace.go
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
)
func isSpace(b byte) bool {
switch b {
@luw2007
luw2007 / logger.go
Created Nov 17, 2018
Go logging for human
View logger.go
package log
import (
"bytes"
"path"
"time"
"github.com/gin-gonic/gin"
"github.com/lestrrat/go-file-rotatelogs"
"github.com/pkg/errors"
@luw2007
luw2007 / ae.c
Last active Aug 21, 2018
redis 事件处理和网络协议
View ae.c
#ifndef __AE_H__
#define __AE_H__
#include <time.h>
#define AE_OK 0
#define AE_ERR -1
#define AE_NONE 0 /* No events registered. */
#define AE_READABLE 1 /* Fire when descriptor is readable. */
View redis_proxy.py
"""
redis proxy
用来展示redis协议
"""
import asyncio
redis_addr = ('127.0.0.1', 6379)
proxy_addr = ('127.0.0.1', 6380)
View epoll.c
//http://www.it165.net/os/html/201308/5868.html
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/epoll.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
@luw2007
luw2007 / tag
Created Aug 6, 2018
自动为git项目打版本号。保存为/usr/loca/bin/tag,chmod +x /usr/loca/bin/tag。 在git目录执行tag 即可
View tag
#!/bin/sh
# 版本号类似于 MAJOR.MINOR.PATCH 遵循 Semantic Versioning 2.0.0:
# MAJOR: 主版本号,不兼容的修改,如:底层重构、框架层变动
# MINOR:次版本号,向前兼容的修改,如:增加新功能、代码优化
# PATCH: 小版本号,修复bug
PREFIX=v
DEFAULT_VERSION=0.0.0
# 获取git版本号
@luw2007
luw2007 / four.go 
Last active Mar 14, 2019
google 面试题:输出连续的1、2、3、4到4个文件
View four.go 
package main
import (
"bytes"
"fmt"
"strconv"
)
const STEP, NUM = 4, 40
@luw2007
luw2007 / bit.go
Last active Nov 28, 2018
业务中经常需要对redis执行一组连续的 gitbit ,即 gitbits 。以下通过 getrange 方法来优化 getbits 的速度。redis 的 bit 并非按照自然顺序排序,所以需要计算。
View bit.go
package redis
import (
r "github.com/garyburd/redigo/redis"
)
type Pool struct {
r.Pool
}
You can’t perform that action at this time.