This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import struct | |
import socket | |
import time | |
def checksum(bytestr): | |
# ref | |
# - https://en.wikipedia.org/wiki/IPv4_header_checksum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
fn do_something<'a>(mut callback: Box<FnMut() + 'a>) { | |
// check http://stackoverflow.com/questions/35651279/error-closure-may-outlive-the-current-function-but-it-will-not-outlive-it | |
// about why adding 'a will work | |
callback(); | |
} | |
fn main() { | |
let mut ret = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Sieve of Eratosthenes | |
; Checkout https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf | |
(def primes | |
(concat | |
[2] | |
(lazy-seq | |
(let [prime-inner | |
(fn prime-inner [x table] | |
(if (table x) | |
(prime-inner (inc x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import subprocess | |
import re | |
import json | |
import sys | |
from math import ceil | |
TMUX_BUFFER_NAME = 'dwm' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
NewerOlder