Skip to content

Instantly share code, notes, and snippets.

View axiaoxin's full-sized avatar
🌙
不忙着圆缺 春天不走远

axiaoxin axiaoxin

🌙
不忙着圆缺 春天不走远
View GitHub Profile
@axiaoxin
axiaoxin / generateRandomDigits.go
Last active December 5, 2023 08:25
使用golang实现一个函数,功能是生成一串6位数的随机数字字符串
/*使用golang实现一个函数,功能是生成一串6位数的随机数字字符串*/
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
@axiaoxin
axiaoxin / GrayStrategy.go
Created December 5, 2023 03:59
使用golang实现一个灰度策略函数
/*使用golang实现一个灰度策略函数
实际开发中,我们通常会组合使用上文中提到的灰度策略,实现灵活的灰度配置,以应对复杂业务场景。
具体的过程,用语言描述就是:
首先外层还是要有全局开关,用于紧急情况下执行急停;
当请求到来后,先校验全局开关是否打开,如果打开,则继续判断是否满足白名单;否则直接返回,继续执行原有逻辑​;
如果命中白名单,则直接执行灰度业务逻辑;否则继续判断是否满足百分比灰度;
计算当前灰度维度id对100取模结果,判断结果是否小于等于百分比阈值,如果满足,则表示命中灰度,执行灰度业务逻辑,反之则表示其不满足当前灰度,继续执行原有业务逻辑。
@axiaoxin
axiaoxin / svgcheckbx_cleaned.js
Created July 22, 2022 02:21 — forked from GianlucaGuarini/svgcheckbx_cleaned.js
Cleaned version of the svgcheckbx.js file used in this demo http://tympanus.net/Development/AnimatedCheckboxes/
;(function(document, window, undefined) {
// wrap always your modules to avoid the namespace pollution
// use always the strict statement
'use strict';
// you do not need to wrap all your code in an if statement...
if (!document.createElement('svg').getAttributeNS) return;
// shortcut to select any DOM element
var $ = document.querySelectorAll.bind(document),
// create an array with all the inputs to uste
// BTW I am sure that this solution is neither correct but it comes from the original code logic
@axiaoxin
axiaoxin / go-redis-bitmap.go
Last active December 7, 2021 02:20
go-redis bitmap demo
func appendBytes(bs []byte, b byte) []byte {
var a byte
for i := 0; i < 8; i++ {
a = b
b <<= 1
b >>= 1
switch a {
case b:
bs = append(bs, '0')
default:
@axiaoxin
axiaoxin / sort.go
Created October 28, 2021 03:44
sort by time and top
package main
import (
"fmt"
"sort"
)
type Item struct {
Top int
Value string
@axiaoxin
axiaoxin / Upgrade vim
Created July 23, 2020 08:02 — forked from yevrah/Upgrade vim
Update to Vim8 on Centos 7
################################################################################
# Method 1: Install using rpm packages (credit to DarkMukke)
#
rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm
rpm --import http://mirror.ghettoforge.org/distributions/gf/RPM-GPG-KEY-gf.el7
# WARNING: removing vim-minimal uninstalls `sudo` if you skip the second step
# make sure to at least run `yum install sudo`
yum -y remove vim-minimal vim-common vim-enhanced
@axiaoxin
axiaoxin / mockHTTPServer.go
Last active December 27, 2018 09:25
mockHTTPServer.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
@axiaoxin
axiaoxin / mutex.go
Created December 17, 2018 03:23
Ways to limit concurrent resource use
package main
import (
"log"
"sync"
"time"
)
func main() {
log.SetFlags(log.Ltime)
@axiaoxin
axiaoxin / faninout.go
Last active December 13, 2018 12:07
Go Patterns
package faninout
import (
"fmt"
)
func main() {
randomNumbers := []int{13, 44, 56, 99, 9, 45, 67, 90, 78, 23}
// generate the common channel with inputs
@axiaoxin
axiaoxin / gen_ips.py
Created March 2, 2018 05:43
gen_ips.py
from IPy import IP
start_ip = IP('181.0.0.3')
count = 1000
filename = '%sips.txt' % count
ips = [IP(start_ip.int() + i).strNormal() + '\n' for i in range(count)]
with open(filename, 'w') as f:
f.writelines(ips)