Skip to content

Instantly share code, notes, and snippets.

View wangshuai1992's full-sized avatar
🎯
Focusing

Zack Patti wangshuai1992

🎯
Focusing
  • Hang Zhou
View GitHub Profile
@hygull
hygull / LICENSE KEY FOR SUBLIME TEXT 3 BUILD 3143.md
Last active December 16, 2023 19:30
LICENSE KEY FOR SUBLIME TEXT 3 BUILD 3143

STEPS

  • Click on Help menu

  • Select Enter License

  • Then paste given KEY given at bottom

  • Finally click on Use License

@pfmiles
pfmiles / ValueHidingUtil.java
Created August 28, 2017 12:56
简易的字段隐藏工具,用于选择性地对原值做全部、部分加密/解密; 用于一些页面展示/表单提交的信息展示场景
package test;
import java.nio.charset.Charset;
import org.apache.commons.codec.binary.Base64;
import org.springframework.security.crypto.encrypt.BytesEncryptor;
import org.springframework.security.crypto.encrypt.Encryptors;
/**
* 简易的字段隐藏工具,用于选择性地对原值做全部、部分加密/解密; 用于一些页面展示/表单提交的信息展示场景
@pfmiles
pfmiles / TypeReference.java
Created July 11, 2014 08:41
用于精确地向调用方法传递带泛型的类型的trick
public class TypeReference<T> {
private final Type type;
protected TypeReference(){
Type superClass = getClass().getGenericSuperclass();
type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
}
@pfmiles
pfmiles / machines
Created March 26, 2014 03:19
Master script: 在集群多个服务器上执行同样命令的方式,支持sudo
192.168.0.1
xxx.xxx.xxx.xxx
.....
@pfmiles
pfmiles / Ipv4WhiteList.java
Last active April 15, 2018 06:39
简易快速的内存ipv4黑白名单实现
package xxx;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
@pfmiles
pfmiles / GatewayUrgentDnsSwitchServiceImpl.java
Created November 14, 2013 09:04
Java应用本地内存dns cache更改、恢复示例程序; 用于参考实现java进程内部范围内的dns绑定功能(无需更改部署机器的dns绑定或dns服务器的配置)
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.Map;
public class GatewayUrgentDnsSwitchServiceImpl implements GatewayUrgentDnsSwitchService {
@pfmiles
pfmiles / SetStack.java
Created June 20, 2012 05:47
A data structure which have both stack & set features, especially useful to detect 'circles' in trees or graphs.
/**
* A data structure which have both stack & set features, especially useful to
* detect 'circles' in trees or graphs.
*
* @author pf-miles
*
*/
public class SetStack<E> extends LinkedHashSet<E> {
private static final long serialVersionUID = -3159906489148656808L;
private Deque<E> innerStack = new ArrayDeque<E>();
@pfmiles
pfmiles / MongDBAtomicUpdate.java
Created May 22, 2012 09:46
超级麻烦的、基于“乐观锁”的mongoDB原子更新操作(在老值上加上一个新值)
// 1.查找相同主键对象
DBObject old = col.findOne(qo);
if (old == null) {
// 2.若不存在,尝试插入, 若出错"duplicate 主键",则转到3.更新操作
try {
col.insert(newObj, WriteConcern.SAFE);
} catch (DuplicateKey e) {
// 2.1 瞬间又被插了一条记录,尝试更新操作
BasicDBObject upObj = new BasicDBObject();
WriteResult rst = null;
@pfmiles
pfmiles / ComputeUtil.java
Created May 9, 2012 01:53
实时、持续计算大规模流数据平均值的函数
public class ComputeUtil {
/**
* 根据已有平均值、总量、新增值递推新平均值的公共函数, 计算公式: newAvg = (oldAvg * oldCount)/(oldCount+1) + newVal/(oldCount+1);
* 另外由于目前的需求是保留2位小数,所以当oldCount大到一定程度时,oldCount/(oldCount+1) 趋近于 1 且 1/(oldCount+1) 趋近于 0,就不必执行某些实际计算以减少不必要操作
*
* @param oldAvg 老平均值
* @param oldCount 老的总量
* @param newVal 新值
* @return 新平均值