Skip to content

Instantly share code, notes, and snippets.


Jiacai Liu jiacai2050

Block or report user

Report or block jiacai2050

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

I write a buggy server to leak socket fd, which listen on 5000, and as expected there were CLOSE-WAIT left when client is closed

$ ss -ntpa | grep 5000
LISTEN     0      50                       :::5000                    :::*      users:(("java",14586,92))
CLOSE-WAIT 79     0          ::ffff:      ::ffff:  users:(("java",14586,96))
CLOSE-WAIT 79     0          ::ffff:      ::ffff:  users:(("java",14586,93))
CLOSE-WAIT 5      0          ::ffff:      ::ffff:  users:(("java",14586,95))
CLOSE-WAIT 150    0          ::ffff:      ::ffff:  users:(("java",14586,94))
package benchmark;
public class CacheLineEffect {
//考虑一般缓存行大小是64字节,一个 long 类型占8字节
static long[][] arr;
public static void main(String[] args) {
arr = new long[1024 * 1024][];
for (int i = 0; i < 1024 * 1024; i++) {
arr[i] = new long[8];
package hystrix;
import rx.Observable;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
View specter-benchmark.clj
(ns demo.specter-benchmark
(:use [com.rpl.specter]
;; one big app state, look like
;; {app-id1 {peer-id1 #{ch-di1}}}
(def clients (atom {}))
(def num-app 10)
(def num-peer 20)


All preferences for the DNS-over-HTTPS functionality in Firefox are located under the "network.trr" prefix (TRR == Trusted Recursive Resolver).


set which resolver mode you want.

0 - Off (default). use standard native resolving only (don't use TRR at all)

1 - Race native against TRR. Do them both in parallel and go with the one that returns a result first.

View transducer_bench.clj
(def dataset (interleave (range 10000000) (range)))
(defn workflow [ds]
(->> ds
(map #(* % %))
(filter #(= 0 (rem % 111)))
(take 10)))
View map_defrecord_bench.clj
(ns demo.record
(:require [criterium.core :refer [bench with-progress-reporting]]))
(def a-z-ks (map (comp keyword str) (seq "abcdefghijklmnopqrstuwvxyz")))
(def dummy-map (zipmap a-z-ks (range)))
(defmacro alphabet-macro []
(defrecord ~'Alphabet [~@(map (comp symbol str) a-z-ks)])
(def ~'dummy-record (~'Alphabet. ~@(range 26)))))
jiacai2050 /
Created Sep 6, 2017
guava caffeine 性能测试
import com.github.benmanes.caffeine.cache.Caffeine;
import junit.framework.TestCase;
import java.text.NumberFormat;
jiacai2050 / gist:13b1b45af7349a3ff6d2a79bdd37f7f5
Created May 16, 2017 — forked from daviesian/gist:4517859
Code to redirect output nrepl output to a particular client repl.
View gist:13b1b45af7349a3ff6d2a79bdd37f7f5
;; After connecting an nrepl client repl to an nrepl server, some
;; output will still appear on stdout from the server.
;; Try these snippets - they will both produce output on the nrepl server
;; Java libraries commonly do both these things.
(.println System/out "Hello stdout.")
(.start (Thread. #(println "Hello from a new thread.")))
jiacai2050 / 0.
Created Nov 21, 2016 — forked from Integralist/0.
Clojure deftype, defrecord, defprotocol
View 0.
  • defprotocol: defines an interface
  • deftype: create a bare-bones object which implements a protocol
  • defrecord: creates an immutable persistent map which implements a protocol

Typically you'll use defrecord (or even a basic map);
unless you need some specific Java inter-op,
where by you'll want to use deftype instead.

Note: defprotocol allows you to add new abstractions in a clean way Rather than (like OOP) having polymorphism on the class itself,

You can’t perform that action at this time.