Skip to content

Instantly share code, notes, and snippets.

View zhou13's full-sized avatar

Yichao Zhou zhou13

View GitHub Profile
#!/bin/bash
date +'%Y-%m-%d %H:%M:%S'
~/bin/perf stat -I 1000 -e cycles,instructions,context-switches -p $1 # 4069
@zhou13
zhou13 / apacase.vim
Last active December 13, 2020 01:39
Format the title entry of a bib into apacase (title case) in vim
" Format all the word into title cases
:%s/\(^\s*title.*\)\@<=\v<(.)(\w*)/\u\2\3/g
" Change short words back
:%s/\(^\s*title.*\)\@<=\(:\s*\|{\)\@<!\v<(And|As|But|For|If|Nor|Or|So|Yet|A|An|The|As|At|By|For|In|Of|Off|On|Per|To|Up|Via)>/\L\0/g
@zhou13
zhou13 / imshow-nomargin.py
Last active May 10, 2023 08:34
matplotlib.pyplot.imshow without margin
plt.gca().set_axis_off()
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.savefig(f"filename.png", transparent=True, bbox_inches="tight", pad_inches=0)
plt.cla()
@zhou13
zhou13 / tunnel.sh
Last active September 20, 2018 04:02
IPv6 tunnel broker
nmcli connection add \
type ip-tunnel ifname he-sit \
mode sit remote 66.220.18.42 -- \
ipv4.method disabled ipv6.method manual \
ipv6.address 2001:470:c:2c3::2/64 \
ipv6.gateway 2001:470:c:2c3::1
wget -O /dev/null https://$USER:[email protected]/nic/update?hostname=$TUNNEL_ID
import multiprocessing
def __parallel_handle(f, q_in, q_out):
while True:
i, x = q_in.get()
if i is None:
break
q_out.put((i, f(x)))