Skip to content

Instantly share code, notes, and snippets.

@gjp0609
gjp0609 / log4j2.xml
Created September 8, 2021 06:35
log4j2 config
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="APP_NAME" value="webtools"/>
<Property name="LOG_PATH" value="/mnt/c/Files/Logs/Mine/webtools"/>
<Property name="LAYOUT" value="%style{%d{yyyy-MM-dd HH:mm:ss.SSS}}{Cyan} [%-26.26t] %5level %style{[%40.-40c{1.}:%-3.5L]}{Magenta} %m%n"/>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
@gjp0609
gjp0609 / 0-100regex
Created January 10, 2020 03:10
0-100 保留两位小数
^(100|(([1-9])[0-9]?|0{1})((\.)([0-9]){1,2})?)$
@gjp0609
gjp0609 / IndexController.kt
Created January 9, 2020 08:41
微信域名授权跳转 解决微信授权域名限制
private val authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECTURI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect"
private val appId = "xxxxxxx"
private val redirectUrl = "http://www.xxx.com/xxx/redirectBack"
@GetMapping("/getCode")
fun redirect(url: String, scope: String, response: HttpServletResponse) {
println(url)
val encodeUrl = encode(url, StandardCharsets.UTF_8)
val redirectUrl: String = authUrl
.replace("APPID", appId)
@gjp0609
gjp0609 / readFile.html
Created January 2, 2020 06:59
read text from file
<input id="file" type="file"/>
<script>
let input = document.getElementById("file");
input.addEventListener("change", function () {
if (this.files && this.files[0]) {
let myFile = this.files[0];
let reader = new FileReader();
reader.addEventListener('load', function (e) {
console.log(e.target.result);
});
@gjp0609
gjp0609 / WechatRedirectController.kt
Created December 27, 2019 07:25
wechat redirect
val OAUTH2_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECTURI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect"
val appId = "xxxx"
/**
* 认证
* @param url 回跳链接
* @param scope 授权方式
*/
@GetMapping("/getCode")
fun redirect(url: String, scope: String, response: HttpServletResponse) {
@gjp0609
gjp0609 / GlobalCorsConfig.java
Created December 5, 2019 06:21
Springboot1.x 管理CORS
@Configuration
public class GlobalCorsConfig {
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 设置你要允许的网站域名,如果全允许则设为 *
config.addAllowedOrigin("*");
// 如果要限制 HEADER 或 METHOD 请自行更改
@gjp0609
gjp0609 / HttpFormUtil.java
Created November 28, 2019 09:31
发送form请求
/**
* http form 请求工具类
*/
public class HttpFormUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpFormUtil.class);
/**
* multipart/form-data 格式发送数据时各个部分分隔符的前缀,必须为 --
*/
private static final String BOUNDARY_PREFIX = "--";
@gjp0609
gjp0609 / proxy.java
Created October 12, 2019 08:31
java use local proxy
static {
String proxyHost = "127.0.0.1";
String proxyPort = "1080";
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", proxyPort);
}
@gjp0609
gjp0609 / Translate.js
Last active January 18, 2024 17:35
Tampermonkey script Translate.js
// ==UserScript==
// @name * 搜狗/百度/谷歌翻译
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author OnySakura
// @include *
// @grant GM_xmlhttpRequest
// ==/UserScript==
@gjp0609
gjp0609 / pom.xml
Created January 21, 2019 09:08
打包时排除lib
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<!--此处修改为你的应用入口类全路径-->
<mainClass>com.xxx.xxxxx.Application</mainClass>