This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*使用golang实现一个函数,功能是生成一串6位数的随机数字字符串*/ | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*使用golang实现一个灰度策略函数 | |
实际开发中,我们通常会组合使用上文中提到的灰度策略,实现灵活的灰度配置,以应对复杂业务场景。 | |
具体的过程,用语言描述就是: | |
首先外层还是要有全局开关,用于紧急情况下执行急停; | |
当请求到来后,先校验全局开关是否打开,如果打开,则继续判断是否满足白名单;否则直接返回,继续执行原有逻辑; | |
如果命中白名单,则直接执行灰度业务逻辑;否则继续判断是否满足百分比灰度; | |
计算当前灰度维度id对100取模结果,判断结果是否小于等于百分比阈值,如果满足,则表示命中灰度,执行灰度业务逻辑,反之则表示其不满足当前灰度,继续执行原有业务逻辑。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
type Item struct { | |
Top int | |
Value string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httptest" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"sync" | |
"time" | |
) | |
func main() { | |
log.SetFlags(log.Ltime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package faninout | |
import ( | |
"fmt" | |
) | |
func main() { | |
randomNumbers := []int{13, 44, 56, 99, 9, 45, 67, 90, 78, 23} | |
// generate the common channel with inputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder