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 / ProcessIdPortMultimap.java
Created May 8, 2026 07:30
Get the mulitmap of Process Id and it opened port number.
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.collections4.IterableUtils;
@asdf913
asdf913 / StringArrayToMap.java
Created May 8, 2026 01:12
Convert a String array into a java.util.Map
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
public class StringArrayToMap {
@asdf913
asdf913 / InetSocketAddressCheckPort.class
Created May 7, 2026 12:59
Retrieve the allowed minimum and maximum port number defined in "checkPort()" in "java.net.InetSocketAddress" class
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.util.Arrays;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.classfile.FieldOrMethod;
import org.apache.bcel.classfile.JavaClass;
@asdf913
asdf913 / WhichOrWhere.java
Last active May 7, 2026 10:15
Use "which" or "where" to determine if a command is valid. Also print the path of the corresponding executable of the command. Print the actual path if the path is a link
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.util.Objects;
import java.util.function.Predicate;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@asdf913
asdf913 / DocxToRubyHTML.java
Created May 4, 2026 05:25
Docx Document to generate Ruby HTML
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Proxy;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
@asdf913
asdf913 / GetFontFilePaths.java
Created March 6, 2026 21:46
Get Font File Paths. This program will invoke native function based on the operating system.
package test2;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@asdf913
asdf913 / gist:dce24d35cfb609e1aaac77d0bb1cca0b
Created June 5, 2025 08:29
Swap Value From Two Variables Without Temporary Variable
public class SwapValueFromTwoVariablesWithoutTemporaryVariable {
public static void main(final String[] args) {
//
int a = 10;
//
int b = 2;
//
System.out.println("a=" + a + ",b=" + b);
//
@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;