Skip to content

Instantly share code, notes, and snippets.

View wcp1231's full-sized avatar

加牛不辣 wcp1231

View GitHub Profile
@wcp1231
wcp1231 / README.md
Last active March 17, 2024 15:53
A simple snowflake conflict test

A simple snowflake conflict test

# defult: -i=2 -t=20 -u=100
> java SimpleSnowflakeTest.java
Generators QPS: [ 187 181]      Total IDs: 4176   (368 /s)      Conflicts: 1139  (104/s)        27.275%

# -t=20 -u=200 => 20 tokens pre 200 ms (100/s)
> java SimpleSnowflakeTest.java -t=20 -u=200
Generators QPS: [ 100 99]]      Total IDs: 3404   (199 /s)      Conflicts: 1062  (52 /s)        31.199%
@wcp1231
wcp1231 / cpu_throttling.go
Created May 17, 2021 09:43
测试 CPU Throttling 的简单程序
package main
import (
"crypto/sha512"
"flag"
"log"
"syscall"
"time"
)
@wcp1231
wcp1231 / ds.lua
Created November 22, 2015 05:15
wrk + lua 行为压测脚本
local function assign(dist, source)
for k,v in pairs(source) do dist[k] = v end
end
M = {}
local actions = {}
actions.__mt = {}
actions.__mt.__index = {
method = 'GET',
@wcp1231
wcp1231 / keybase.md
Created June 8, 2015 04:51
Keybase proof

Keybase proof

I hereby claim:

  • I am wcp1231 on github.
  • I am wcp1231 (https://keybase.io/wcp1231) on keybase.
  • I have a public key whose fingerprint is 17FC 73FF 2142 3B77 BA36 AF4E 5F55 40D9 90F8 4418

To claim this, I am signing this object:

@wcp1231
wcp1231 / gist:bdb6e5b003c264b1632a
Created July 4, 2014 08:57
Trampoline in python
# python has no tail recursion optimization.
def f(n):
if n == 0: return 1
return n * f(n-1)
f(5000)
# > RuntimeError: maximum recursion depth exceeded
# so, we can use trampoline
def f(n):
@wcp1231
wcp1231 / gist:7873868
Created December 9, 2013 15:24
OSX和Linux下用Ruby启动简单的Web Server。类似于 Python -m SimpleHTTPServer
ruby -run -e httpd . -p 5000
@wcp1231
wcp1231 / change_version.sh
Created September 28, 2013 14:40
修改静态文件路径版本的单行的ruby脚本,作用同之前的python脚本。直接在shell里执行即可
# 已知的bug是,如果一个元素分成几行就不会被匹配上
ruby -i.bak -rdate -pe '$_.gsub!(/(<(script|link|img)[^@%>]*=["][^"]*\.(js|css|png|jpg))/) {%Q|#{$1}?#{DateTime.now.strftime "%Y%m%d%H"}|}' ./**/*.jsp
@wcp1231
wcp1231 / change_version.py
Last active December 24, 2015 04:19
修改静态文件地址版本号的python脚本,给HTML里的css、js、图片等加上版本,使得静态资源既能缓存也能实时更新
# -*- coding: utf-8 -*-
import sys
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
import os
import re
def build_replace_func():
version_string = "?ver=%s" % datetime.now().strftime("%Y%m%d%H")
def func(match_obj):
@wcp1231
wcp1231 / GetFilecharset.java
Created July 9, 2013 13:59
判断文件的编码类型
public static String getFilecharset(File sourceFile) {
String charset = "GBK";
byte[] first3Bytes = new byte[3];
try {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourceFile));
bis.mark(0);
int read = bis.read(first3Bytes, 0, 3);
System.out.println("字节大小:"+read);
if (read == -1) {
return charset; //文件编码为 ANSI
@wcp1231
wcp1231 / BISTU_Auto_Evaluate.js
Created June 19, 2013 07:28
自动填写BISTU教务系统的教学质量评估,只要打开教学质量评估页面即可。不过得自己点击提交按钮。
// ==UserScript==
// @name BISTU_Auto_Evaluate
// @namespace http://wcp1231.github.io
// @include http://jwgl.bistu.edu.cn/*
// @version 1
// ==/UserScript==
for(var i = 2; i < 8; i++) {
var id = "DataGrid1__ctl" + i + "_JS1";
document.getElementById(id).selectedIndex = 1;