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 / tmux-tiled.py
Created Jun 23, 2017
DWM like pane management for tmux
View tmux-tiled.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import re
import json
import sys
from math import ceil
TMUX_BUFFER_NAME = 'dwm'
@lotabout
lotabout / expanding_nebula.py
Created Oct 5, 2017
Solution for google foobar: Expanding Nebula
View expanding_nebula.py
def generate(c1,c2,bitlen):
a = c1 & ~(1<<bitlen)
b = c2 & ~(1<<bitlen)
c = c1 >> 1
d = c2 >> 1
return (a&~b&~c&~d) | (~a&b&~c&~d) | (~a&~b&c&~d) | (~a&~b&~c&d)
from collections import defaultdict
def build_map(n, nums):
mapping = defaultdict(set)
View google-translate.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# translate utility that utilize google translator, support python2 & python3
# Note that the order or arguments in the URL matters.
try:
from urllib import urlencode
except:
from urllib.parse import urlencode
@lotabout
lotabout / send-to-download.js
Last active Oct 30, 2020
Greasemonkey script for send content to backend localhost.
View send-to-download.js
// ==UserScript==
// @name Post test
// @namespace jinzhou
// @description Post Test
// @include *
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==
@lotabout
lotabout / crawler_dribbble.py
Created Jan 17, 2016
A crawler for dribbble.com
View crawler_dribbble.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import re
import os
import json
import logging
import traceback
@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 {