Skip to content

Instantly share code, notes, and snippets.

Avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / traceroute.py
Created March 13, 2021 07:13
Simple traceroute implementation in Python3
View traceroute.py
#!/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 March 13, 2021 02:36
Simple ping implementation in python3 for practicing TCP/IP
View ping.py
#!/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
View prophet-links.js
@lotabout
lotabout / MyBenchmark.java
Last active January 11, 2023 06:01
CompletableFuture.supplyAsync profile
View MyBenchmark.java
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?
View SpringApplication.java
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
View MyBenchmark.java
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;
View SyncTest.java
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.
View ConcurrencyTest.java
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
View timed-log.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
import fileinput
for line in fileinput.input():
print(f'[{datetime.now()}] {line}', end='')
@lotabout
lotabout / DCWGAN.py
Created March 29, 2018 08:53
WGAN implementation
View DCWGAN.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch.nn as nn
import torch
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from torch.autograd import Variable, grad
import torch.optim as optim
import torchvision.utils as vutils