Skip to content

Instantly share code, notes, and snippets.

@honwhy
honwhy / TrieTreeNode.java
Last active January 16, 2023 14:28
TrieTreeNode v2
package org.example;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
public class TrieTreeNode {
private char ch;
private Set<Long> ids = new HashSet<>();
LinkedHashMap<Character, TrieTreeNode> children = new LinkedHashMap<>();
@honwhy
honwhy / App.java
Created December 31, 2022 16:12
Java 8 CompletableFuture Suggestions
package org.example;
import java.util.*;
import java.util.concurrent.*;
/**
* Hello world!
*/
public class App {
static BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(200);
@honwhy
honwhy / AnnotatedMap.java
Created June 12, 2022 09:23
copy Annotation to Map
package com.example.br;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
@MyTable("t_table")
public class AnnotatedMap<K, V> extends HashMap<K,V> {
public AnnotatedMap() {
@honwhy
honwhy / MyFTP.java
Created January 12, 2020 08:13
用nio写ftpclient(未完)
package org.example;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
@honwhy
honwhy / vue-crypto-js.html
Created January 1, 2020 14:29
vue-crypto-js.html
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
</body>
<div id="app">
<textarea v-model="input">
</textarea>
@honwhy
honwhy / TcpTimeClient.java
Created December 17, 2019 15:54
selector in client side(sorry forget the link from stackoverflow)
package com.honey;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
@honwhy
honwhy / ConsumerQueueDemo.java
Created October 20, 2019 10:45
ConcurrentLinkedQueue vs BlockingQueue
package com.honey;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
public class ConsumerQueueDemo {
public static void main(String[] args) {
//making hot spot code
@honwhy
honwhy / AesDemo.java
Created October 18, 2019 17:08
aes cbc demo
package com.honey;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Random;
public class AesDemo {
@honwhy
honwhy / MultiThreadHashMap.java
Created March 17, 2019 08:48
MultiThreadHashMap
public class MultiThreadHashMap {
private static final Object PRESENT = new Object();
public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
final Map<String,Object> map = new HashMap<>(); //let map do resize multiple times
int N = 1000;
final CyclicBarrier cyclicBarrier = new CyclicBarrier(N+1);
for (int i = 0; i < N; i++) {
new Thread(new Runnable() {
@Override
public void run() {
@honwhy
honwhy / gist:23e6be984e0117196e59eb458e6ac6ba
Created November 18, 2018 11:02
dump_java_process.sh
# dump script from http://dubbo.apache.org/zh-cn/docs/dev/principals/dummy.html
JAVA_HOME=/usr/java
OUTPUT_HOME=~/output
DEPLOY_HOME=`dirname $0`
HOST_NAME=`hostname`
DUMP_PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_HOME" |awk '{print $2}'`
if [ -z "$DUMP_PIDS" ]; then
echo "The server $HOST_NAME is not started!"