Skip to content

Instantly share code, notes, and snippets.

Avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / traceroute.py
Created Mar 13, 2021
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 Mar 13, 2021
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 Sep 21, 2020
Add links to prophet
View prophet-links.js
@lotabout
lotabout / MyBenchmark.java
Last active Apr 1, 2020
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 Aug 26, 2019
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
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 Aug 20, 2018
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
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 Mar 29, 2018
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