Skip to content

Instantly share code, notes, and snippets.

View asmoker's full-sized avatar
🎯
Focusing

asmoker asmoker

🎯
Focusing
View GitHub Profile
@asmoker
asmoker / SpringBoot2TomcatConfig.java
Created March 25, 2019 13:22
Spring Boot 2.0 Embedded Tomcat Config, Set Unlimited Upload File Size.
@Bean
public TomcatServletWebServerFactory tomcatEmbedded() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 means unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
@asmoker
asmoker / postman_pre_requests.js
Created February 22, 2019 08:21
postman Pre-requests Scripts,用于拦截 postman 请求,计算请求签名,添加自定义请求头等个性化操作,postman 接口使用示例
// 获取请求参数字典
function get_params_dict() {
result = {}
if (pm.request.method === "GET") {
for (var i = 0; i < pm.request.url.query.members.length; i++) {
obj = pm.request.url.query.members[i]
result[obj.key] = obj.value
}
} else {
if (pm.request.body.formdata && pm.request.body.formdata.members) {
@asmoker
asmoker / ConfigReader.java
Created September 2, 2016 09:15
read properties files without spring
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class ConfigReader {
private static final String PROPERTIES_DIR = "properties"; // 配置文件名称
private static Properties properties = new Properties();
@asmoker
asmoker / Pagination.java
Last active February 22, 2019 08:22
Pagination object
package com.demo.utils;
import java.util.List;
/**
* @author zhangminpeng on 2016-07-22 14:30
*/
public class Pagination<T> {
private long pageCurrent; // 当前页码, 起始页码 0
private long rowCount; // 总记录条数
@asmoker
asmoker / BaseDao.java
Created July 22, 2016 12:44
Pagination with Criteria
@SuppressWarnings("unchecked")
public Pagination<T> list(long pageIndex, long pageSize, Criteria criteria) {
long rowCount = (long) criteria.setProjection(Projections.rowCount()).uniqueResult();
long pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
Pagination<T> pagination = new Pagination<>();
pagination.setRowCount(rowCount);
pagination.setPageCount(pageCount);
if (pageIndex <= 0) {
pagination.setPageCurrent(0);
pagination.setHasPrevious(false);
@asmoker
asmoker / HttpsUtil.java
Created June 13, 2016 11:41
Java 发送 HTTPS 请求
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
@asmoker
asmoker / Sort.java
Created June 21, 2015 16:54
bubble sort
// bubble sort(冒泡排序)
public static int[] bubbleSort(int[] array) {
for (int i = 0; i < array.length - 1; i++) {
for (int j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
@asmoker
asmoker / Search.java
Created June 18, 2015 17:32
二分法在数组中查找数据,数组是升序的。
// 二分法查询数组中元素所在的位置,数组是有序的,非递归
public static int dichotomySearch(int[] array, int value) {
int low = 0;
int high = array.length - 1;
while (low <= high) {
int middle = (low + high) / 2;
if (value == array[middle]) {
return middle;
}
if (value > array[middle]) {
@asmoker
asmoker / Application.java
Last active August 29, 2015 14:23
spring framework demo
@Configuration
@ComponentScan
public class Application {
@Bean
MessageService mockMessageService() {
return new MessageService() {
public String getMessage() {
return "Hello Spring";
}
};