Skip to content

Instantly share code, notes, and snippets.

@luw2007
luw2007 / time.go
Last active November 28, 2019 08:37
AddMonths 增加月份,有许多神奇的case需要处理,例如 1月31日 - 2月28日, 3月31日 - 4月30日。 总的逻辑为,到达下一个月的同一天,若无效前推至有效
package main
import (
"fmt"
"testing"
"time"
)
// WHY:
//
@luw2007
luw2007 / trimspace.go
Created May 19, 2019 13:17
TrimSpace remove space, also in sentence. like: " a \t\r\n b " -> "a b"
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
)
func isSpace(b byte) bool {
switch b {
@luw2007
luw2007 / logger.go
Created November 17, 2018 06:04
Go logging for human
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 August 21, 2018 08:58
redis 事件处理和网络协议
#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. */
"""
redis proxy
用来展示redis协议
"""
import asyncio
redis_addr = ('127.0.0.1', 6379)
proxy_addr = ('127.0.0.1', 6380)
//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 August 6, 2018 10:47
自动为git项目打版本号。保存为/usr/loca/bin/tag,chmod +x /usr/loca/bin/tag。 在git目录执行tag 即可
#!/bin/sh
# 版本号类似于 MAJOR.MINOR.PATCH 遵循 Semantic Versioning 2.0.0:
# MAJOR: 主版本号,不兼容的修改,如:底层重构、框架层变动
# MINOR:次版本号,向前兼容的修改,如:增加新功能、代码优化
# PATCH: 小版本号,修复bug
PREFIX=v
DEFAULT_VERSION=0.0.0
# 获取git版本号
0xA62D03dA4F56043663859c9173E8E6ad9A24C40a
@luw2007
luw2007 / four.go 
Last active March 14, 2019 15:50
google 面试题:输出连续的1、2、3、4到4个文件
package main
import (
"bytes"
"fmt"
"strconv"
)
const STEP, NUM = 4, 40
@luw2007
luw2007 / bit.go
Last active September 20, 2021 08:25
业务中经常需要对redis执行一组连续的 gitbit ,即 gitbits 。以下通过 getrange 方法来优化 getbits 的速度。redis 的 bit 并非按照自然顺序排序,所以需要计算。
package redis
import (
r "github.com/garyburd/redigo/redis"
)
type Pool struct {
r.Pool
}