Skip to content

Instantly share code, notes, and snippets.

View asdf913's full-sized avatar

asdf913

  • Hong Kong
  • Hong Kong
View GitHub Profile
@asdf913
asdf913 / JptExamMarkSheetExcel.java
Last active March 20, 2025 12:29
JPT Exam Mark Sheet (xlsx)
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
@asdf913
asdf913 / ChopImage.java
Created February 13, 2025 12:03
Chop Image by Java
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Collection;
import java.util.function.ObjIntConsumer;
@asdf913
asdf913 / Main.java
Last active February 11, 2025 06:33
Check if string is plain text or not
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.function.FailableFunction;
@asdf913
asdf913 / JlptAdverbList.java
Created February 2, 2025 09:56
Extract all Japanese adverb from https://jlptsensei.com/complete-japanese-adverbs-list/ and write the list to a XLSX spreadsheet. Each sheet represent the JLPT examination level
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Predicate;
@asdf913
asdf913 / Main.java
Created January 20, 2025 14:23
Print the "java.awt.datatransfer.DataFlavor" constants which are "java.awt.datatransfer.DataFlavor". Also list the result of "java.awt.datatransfer.Transferable.isDataFlavorSupported(java.awt.datatransfer.DataFlavor)" against all "java.awt.datatransfer.DataFlavor" constants which are "java.awt.datatransfer.DataFlavor"
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.util.Arrays;
@asdf913
asdf913 / PDImageXObjectTest
Last active January 18, 2025 15:07
List of allowed "org.apache.pdfbox.util.filetypedetector.FileType" and test if a given file is accepted by "org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.createFromByteArray(org.apache.pdfbox.pdmodel.PDDocument,byte[],java.lang.String)" method
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.file.Files;
import java.util.ArrayList;
@asdf913
asdf913 / gist:65aa2113e4e596ed6f96f5bcbfbd1240
Created June 22, 2024 05:46
Convert all java file under all sub folder encoding from UTF-8 to CP932
find . -name "*.java" -type f -exec readlink -f {} \;|xargs -I {} iconv -f UTF-8 -t CP932 {}>{}
org.apache.groovy.util.Maps.of(K, V)
org.apache.groovy.util.Maps.of(K, V, K, V)
org.apache.groovy.util.Maps.of(K, V, K, V, K, V)
...
up to 100 key value pairs
https://docs.groovy-lang.org/latest/html/gapi/org/apache/groovy/util/Maps.html
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.time.chrono.JapaneseEra;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;