Skip to content

Instantly share code, notes, and snippets.

@gjp0609
gjp0609 / SudokuTest.java
Created January 7, 2019 07:41
sudoku solve
import java.util.Arrays;
public class SudokuTest {
private static int[][] sudoku = new int[9][9];
private static int step = 0;
private static void init() {
String src = "" +
"009002400" +
@gjp0609
gjp0609 / App.java
Created January 7, 2019 08:05
Jsoup parse html in sinngle line
// https://www.metacritic.com/browse/games/release-date/available/ps4/metascore
Jsoup.parse(new BufferedReader(new FileReader(new File("C:/Files/ps4.html")))
.lines()
.reduce(Jsoup.parse(new BufferedReader(new FileReader(new File("C:/Files/ByUser.html")))
.lines()
.reduce("", (acc, item) -> acc + item)).toString(), (acc, item) -> acc + item))
.select(".product_wrap")
.stream()
.sorted(Comparator.comparing(e -> ((Element) e).select(".textscore").text()).reversed())
.map(item -> "\033[106m "
@gjp0609
gjp0609 / App.java
Created January 7, 2019 08:09
One line test
Jsoup.parse(new BufferedReader(new FileReader(new File("C:/Files/ps4.html"))).lines().reduce(Jsoup.parse(new BufferedReader(new FileReader(new File("C:/Files/ByUser.html"))).lines().reduce("", (acc, item) -> acc + item)).toString(), (acc, item) -> acc + item)).select(".product_wrap").stream().sorted(Comparator.comparing(e -> ((Element) e).select(".textscore").text()).reversed()).map(item -> "\033[106m ".concat(item.select(".textscore").text()).concat(" \033[102m ").concat(String.format("%3s", item.select(".metascore_w").text())).concat(" \033[91m ").concat(item.select("a").text())).distinct().forEach(System.out::println);
@gjp0609
gjp0609 / FileDownload.java
Created January 15, 2019 10:11
download file from network to local use thread pool
package message;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@gjp0609
gjp0609 / CreateWXAQRCode.java
Created January 17, 2019 02:26
generic WXAQRCode
/**
* 生成小程序二维码并存入本地
*
* @param pathAndParams 路径及自定义参数: /page/index?id=123
* @param filePathAndName 文件路径及名称: C:/Files/qrcode/123.jpg
*/
private static void generic(String pathAndParams, String filePathAndName) {
RestTemplate rest = new RestTemplate();
InputStream inputStream = null;
OutputStream outputStream = null;
@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>
@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 / 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 / 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 / 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 请自行更改