Skip to content

Instantly share code, notes, and snippets.

View lifei6671's full-sized avatar
💭
I may be slow to respond.

Minho lifei6671

💭
I may be slow to respond.
View GitHub Profile
@lifei6671
lifei6671 / snowflake.go
Created July 3, 2020 10:40 — forked from asyncins/snowflake.go
[snowflake-go]
package main
import (
"errors"
"fmt"
"sync"
"time"
)
const (
@lifei6671
lifei6671 / compile_nginx.sh
Last active April 23, 2020 10:28
最优编译nginx脚本
./configure --prefix=/opt/websuite/nginx \
--conf-path=/opt/config/nginx/nginx.conf \
--modules-path=/opt/websuite/nginx/modules \
--error-log-path=/opt/logs/nginx/error.log \
--http-log-path=/opt/logs/nginx/access.log \
--pid-path=/opt/run/nginx --user=websuite \
--group=websuite \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
@lifei6671
lifei6671 / gotin.go
Created September 15, 2019 01:42
golang实现in_array功能
package gotin
import (
"errors"
"reflect"
"sort"
)
var (
ErrUnSupportHaystack = errors.New("haystack must be slice, array or map")
@lifei6671
lifei6671 / ip.go
Created September 11, 2019 09:37
判断字符串是否是IPV4格式
func IsIpv4(s string) bool {
var p [IPv4len]byte
for i := 0; i < IPv4len; i++ {
if len(s) == 0 {
// Missing octets.
return false
}
if i > 0 {
if s[0] != '.' {
return false
@lifei6671
lifei6671 / event.go
Last active May 30, 2019 05:53
简单事件模拟器
type eventGenerator struct {
eventCh chan int
ctx context.Context
cancel context.CancelFunc
}
func NewEventGenerator(ctx context.Context) *eventGenerator {
// better to get context from others place, even this is a most up level controller
// because you can use `context.Background()` as argument if this is the most up level one
ctx, cancel := context.WithCancel(ctx)
@lifei6671
lifei6671 / roundrobin.go
Created April 17, 2019 02:29
一个支持Nginx算法和lvs算法的负载均衡库
package roundrobin
// RR: 基于 权重round robin算法的接口
type RR interface {
Next() interface{}
Add(node interface{}, weight int)
RemoveAll()
Reset()
}
@lifei6671
lifei6671 / curl.php
Last active August 24, 2017 08:00
PHP使用CURL发起请求
<?php
/**
* 发起一个自定义请求
* @param string $url
* @param string $method
* @param array $options
* @param array $headers
* @param array $vars
* @return HttpResponse|string
@lifei6671
lifei6671 / forward.sh
Created August 17, 2017 02:58
Windows端口转发
netsh interface portproxy add v4tov4 listenport=3333 connectaddress=172.17.30.42 connectport=3306
@lifei6671
lifei6671 / snowflake.php
Created August 15, 2017 01:49
PHP实现的snowflake算法
/**
* 使用 snowflake 算法生成递增的分布式唯一ID.
* 该算法支持 15 条业务线,4 个数据中心,每个数据中心最多 128 台机器,每台机器每毫秒可生成 4096 个不重复ID.
*/
class Snowflake
{
const SEQUENCE_BITS = 12;
const MILLISECOND_BITS = 39;
const BUSINESS_ID_BITS = 4;
const DATA_CENTER_ID_BITS = 2;