Skip to content

Instantly share code, notes, and snippets.

View novoland's full-sized avatar

Liu Jing novoland

View GitHub Profile
@novoland
novoland / fix_mvn_ban.py
Created May 21, 2021 08:01
automatically add <exclusion> to pom.xml for banned dependencies scanned by maven enforcer plugin.
import os
from xml.dom.minidom import parse
import xml.dom.minidom
import sys
def findBanned(log):
banned = []
for line in log:
if "Found Banned Dependency" in line:
a = line.split(":")
@novoland
novoland / PushPipeline.java
Last active December 12, 2017 12:52
netty3 的 pipeline 机制简单实现
/**
* 消息中心内所有push均被PushPipeline处理。PushPipeline是一根由多个{@link PushRule}和一个
* {@link PushPipelineSink}组成的单项链表:
*
* <pre>
* PushRule:
* 判断push是否可以被发送。PushRule对一个push请求可以有以下三种处理方式:
* 1. 通过,并送入后续PushRule继续判断;
* 2. 通过,并立即送入PushPipelineSink发送;
* 3. 拒绝,整个流程结束。
package com.meituan.show.sell.web.advice;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
package com.meituan.show.sell.web.exception;
import java.util.List;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.validation.FieldError;
@novoland
novoland / cache_tx_consistency.py
Last active December 23, 2015 13:06
cache和事务如何保持一致
C1 C2 keysToEvict #C1 keysToEvict --- threadLocal; C2 --- medis
'''
关闭C1, isolation level: Read Committed
开启C1, isolation level: Repeatable Read, 无幻读,但少数场景依然是Read Committed
eg:
A B C
start
@novoland
novoland / best_discount.py
Last active December 15, 2015 08:32
DP找最佳套票规则 & 最大优惠 ---- 这是个完全背包问题
#!/usr/bin/python
# coding=utf-8
n = 10 # 有多少张票
a = [0] * (n+1) # a[i]表示前i张票能获得的优惠最大值
applies = [[]] * (n+1) # applies[i]:前i张票获得最大优惠时采用的所有套票规则
rules = [(2,10), (3,14), (4,22), (5,23)] # 套票规则,买2优惠10 etc.
def test():
<html>
<head>
<meta charset="utf-8"/>
<title>打印测试</title>
<style type="text/css">
*{margin:0;padding:0;font-family: 黑体}
#ticket{
width:202mm;
height:80mm;
page-break-after: always;
@novoland
novoland / escape_json.java
Created June 3, 2015 04:11
用fastjson将json相关特殊字符转义
public static String escape(String text) {
if (StringUtils.isEmpty(text)) {
return text;
}
// fastjson序列化string时会自动转义(但会在前后加上两个双引号)
String json = JSONObject.toJSONString(text);
json = json.substring(1, json.length() - 1);
return json;
}
@novoland
novoland / deadlock.sql
Last active August 29, 2015 14:21
UPDATE ON DUPLICATE KEY 造成 MYSQL 死锁现场
插入不同记录:原生MySQL 5.5.43 InnoDB
------------------------
LATEST DETECTED DEADLOCK
------------------------
150522 16:34:11
*** (1) TRANSACTION:
TRANSACTION 1304, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 6 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
// AutowiredAnnotationBeanPostProcessor.java
private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
Class<?> targetClass = clazz;
do {
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
for (Field field : targetClass.getDeclaredFields()) {
AnnotationAttributes ann = findAutowiredAnnotation(field);