Skip to content

Instantly share code, notes, and snippets.

View lotabout's full-sized avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / Launcher.java
Created March 12, 2024 11:10
Java Agent example
package me.lotabout;
import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
@lotabout
lotabout / traceroute.py
Created March 13, 2021 07:13
Simple traceroute implementation in Python3
#!/usr/bin/env python3
import struct
import socket
import time
# Need to run with root permission cause RAW socket is used
# ref:
# - https://dnaeon.github.io/traceroute-in-python/
@lotabout
lotabout / ping.py
Last active December 24, 2023 06:08
Simple ping implementation in python3 for practicing TCP/IP
#!/usr/bin/env python3
import os
import struct
import socket
import time
def checksum(bytestr):
# ref
# - https://en.wikipedia.org/wiki/IPv4_header_checksum
@lotabout
lotabout / prophet-links.js
Last active September 21, 2020 09:47
Add links to prophet
@lotabout
lotabout / MyBenchmark.java
Last active December 24, 2023 05:54
CompletableFuture.supplyAsync profile
package me.lotabout;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@lotabout
lotabout / SpringApplication.java
Created August 26, 2019 06:42
How to add an additional connector in spring boot's application?
import org.apache.catalina.connector.Connector;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class SpringApplication {
@lotabout
lotabout / MyBenchmark.java
Created May 26, 2019 10:07
Java UUID Benchmark
package me.lotabout;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.RandomBasedGenerator;
import com.fasterxml.uuid.impl.TimeBasedGenerator;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class SyncTest {
private enum TestType {
SYNCHRONIZED, VOLATILE, ATOMIC, LOCK, FAIR_LOCK
@lotabout
lotabout / ConcurrencyTest.java
Last active August 20, 2018 14:41
Test the performance of different concurrency mechanism.
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;
public class ConcurrencyTest {
private enum TestType {
@lotabout
lotabout / timed-log.py
Created May 2, 2018 05:10
Add timestamp to log
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
import fileinput
for line in fileinput.input():
print(f'[{datetime.now()}] {line}', end='')