Skip to content

Instantly share code, notes, and snippets.

🚀
Hard working...may not respond.

pf_miles pfmiles

🚀
Hard working...may not respond.
Block or report user

Report or block pfmiles

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pfmiles
pfmiles / RandSeq.java
Created Jun 26, 2018
可配置的随机字符串产生器,可满足任意大窗口区间内生成值绝不重复的要求
View RandSeq.java
package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
/**
@pfmiles
pfmiles / AlphabetEncoder.java
Last active Nov 28, 2017
任意进制、自定义字符表的数字表示方式转换工具
View AlphabetEncoder.java
public final class AlphabetEncoder {
private static final String[] ALPHABET = { "0", "1", "2", "3", "4", "5", "6",
"7", "8", "9", "", "", "", "",
"", "" };
private static final long ENCODE_LENGTH = ALPHABET.length;
private static final Map<String, Integer> idxMap = new HashMap<>();
static {
for (int i = 0; i < ALPHABET.length; i++)
@pfmiles
pfmiles / scanCoverageRecur.java
Last active Sep 27, 2017
增量计算扫描覆盖率的通用算法
View scanCoverageRecur.java
/**
* 计算扫描覆盖率的通用算法
* cover_rate递推公式为:fn = (1 - fn-1) * N/M + fn-1 ; 其中fn是本次迭代cover_rate, fn-1是上次迭代cover_rate, N是本次抽取数量,M是集合总数,f0=0;
*/
public static BigDecimal scanCoverageRecur(BigDecimal fn1, int N, BigInteger M, int scale) {
if (fn1 == null)
fn1 = new BigDecimal(0);
BigDecimal one = new BigDecimal(1);
BigDecimal Nb = new BigDecimal(N);
BigDecimal Mb = new BigDecimal(M);
@pfmiles
pfmiles / ValueHidingUtil.java
Created Aug 28, 2017
简易的字段隐藏工具,用于选择性地对原值做全部、部分加密/解密; 用于一些页面展示/表单提交的信息展示场景
View ValueHidingUtil.java
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 / insertOrUpdate.xml
Last active Aug 23, 2017
mysql行级锁原子插入模板,结合ibatis
View insertOrUpdate.xml
<!-- 注意这里需要用 isNotEmpty 保证更新目标的关键字段不能被更新为null,这里的insert仅仅为了实现selectForUpdate的行级锁而做,其中目标字段在数据库中必须为nullable -->
<insert id="asa.AsaDdMediaDAO.insertOrUpdate" parameterClass="AsaDdMediaDO">
insert into
asa_dd_media(gmt_create,
gmt_modified, url, type, media_id) values (
now(), now(), #url#, #type#, #mediaId#)
ON
DUPLICATE KEY
UPDATE gmt_modified = now(), type = #type#
<isNotEmpty prepend="," property="mediaId">
@pfmiles
pfmiles / AutowiringSpringBeanJobFactory.java
Last active Jul 27, 2017
分布式quartz全局调度配置, 支持spring bean自动注入
View AutowiringSpringBeanJobFactory.java
package test.common.quartz;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
/**
@pfmiles
pfmiles / BeanUtil.java
Created Jan 6, 2017
使用from对象,update指定对象(to, 符合javaBean规范的pojo)
View BeanUtil.java
package test;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@pfmiles
pfmiles / ClassUtil.java
Last active Jan 22, 2017
取得指定类的指定类型的直接父类或父接口身上实际传入的泛型实参列表
View ClassUtil.java
package test;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@pfmiles
pfmiles / HttpInvoker.java
Last active Sep 8, 2017
短频快http api调用工具,鼓励长连接
View HttpInvoker.java
package test;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@pfmiles
pfmiles / IOUtil.java
Last active Sep 23, 2016 — forked from awilmore/IOUtil.java
IO channel间互相“流”数据的方案,尽可能zero-cory
View IOUtil.java
package com.awilmore.ioutils;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;
public class IOUtil {
You can’t perform that action at this time.