Skip to content

Instantly share code, notes, and snippets.

View akiradeveloper's full-sized avatar

Akira Hayakawa akiradeveloper

View GitHub Profile
public editDistance(that: Table): number {
let dist = 0;
// swap distance
let xs = this.asColorSeq();
let ys = that.asColorSeq();
let n = xs.length;
for (let i=0; i<n; i++) {
if (xs[i] != ys[i]) {
dist += 0.5;
fn dfs(&mut self, v: usize, t: usize, f: u32) -> u32 {
if v == t { return f; }
self.used[v] = true;
for e in &mut self.g[v] {
if !self.used[e.to] && e.cap > 0 {
let d = self.dfs(e.to, t, std::cmp::min(f, e.cap)); // cannot borrow `*self` as mutable more than once at a time
if d > 0 {
e.cap -= d;
self.g[e.to][e.rev].cap += d; // cannot borrow `self.g` as mutable more than once at a time
return d;
cl_crosshairalpha 255; cl_crosshaircolor 2; cl_crosshairdot 0; cl_crosshairgap -2; cl_crosshairsize 3; cl_crosshairstyle 4; cl_crosshairusealpha 1; cl_crosshairthickness 1; cl_crosshair_drawoutline 0; cl_crosshair_sniper_width 1;
// misc
cl_autohelp "0"
cl_autowepswitch "0"
cl_dm_buyrandomweapons "0"
cl_forcepreload "1"
cl_showhelp "0"
cl_showpos "1"\
cl_teamid_overhead_always "2" // w/ equipment
cl_teammate_colors_show "1" // show teammates in rader with color
closeonbuy "0"
@akiradeveloper
akiradeveloper / gist:81b7fa34fb887d8e2dcf1ae1e8f5451d
Created October 14, 2017 07:45
writeboost build compatibility
linux-3.10: OK
linux-3.14: OK
linux-3.16: OK
linux-3.18.75: OK
linux-4.12.14: OK
linux-4.13.6: OK
linux-4.1.44: OK
linux-4.4.92: OK
linux-4.6: OK
linux-4.8: OK
dmsetupを実行するプロセスとは別に
udevadm monitor --kernel で待機させてそいつに観測させた
remove
KERNEL[4202.177671] remove /devices/virtual/block/dm-0 (block)
KERNEL[4202.205822] remove /kernel/slab/dmwb_buf_8 (slab)
KERNEL[4202.206786] remove /kernel/slab/bio-3 (slab)
KERNEL[4202.250279] remove /devices/virtual/bdi/251:0 (bdi)
KERNEL[4202.250776] remove /devices/virtual/block/dm-0 (block)
BACKING=/dev/vdb
CACHE=/dev/vdc
sz=`sudo blockdev --getsz ${BACKING}`
echo $sz
sudo dd if=/dev/zero of=$CACHE oflag=direct bs=512 count=1
sudo dmsetup create wbdev --table "0 $sz writeboost $BACKING $CACHE 2 writeback_threshold 70"
sudo dmsetup status wbdev | wbstatus
sudo dd if=/dev/mapper/wbdev of=/tmp/o iflag=direct bs=4k count=1
@akiradeveloper
akiradeveloper / gist:283d0e6d093d7437248de1bfdc110474
Created October 12, 2017 11:18
ライトブーストのregressionがおかしい
JavaからIOを発行するとRMWしたりバッファリングしたりしてカーネルへのIOが思惑どおりにならないため
ddを使っているがこれが仇となっている可能性がある
// デバイスを作る
$ sudo sh script.sh
[sudo] password for akira:
1+0 records in
1+0 records out
512 bytes copied, 0.00111281 s, 460 kB/s
Error detected while processing function vimfiler#mappings#do_switch_action..vimfiler#mappings#do_action..vimfiler#mappings#do_files_action..unite#mappings#do_action..unite#action#do:
line 58:
E716: Key not present in Dictionary: file_quit && &buftype =~# 'nofile'
E15: Invalid expression: unite.context.file_quit && &buftype =~# 'nofile'
@akiradeveloper
akiradeveloper / read-caching.md
Created August 4, 2016 13:46
writeboost read-caching

I am writing this blog as a documentation draft and the aim is to make all users feel easy to use read-caching in their production.

writeboost is a log-structured writeback-caching software so it sounds bit strange that it can supports read-caching. The idea is implement read-caching as lightweight write-caching. The basic idea is:

  1. Only caches 4KB (full-sized) read requests
  2. Captivate read data into the read-cache cells, in the endio callback. (read_cache_cell_copy_data) There are 2048 cells preallocated. reserve_read_cache_cell is called when the read request results in cache miss (then read from the backing device) and the function reserves one of the cells. In endio, the read data payload is copied to the cell reserved.
  3. Once all cells are occupied writeboost "injects" the read data captivated in the cells into the write-caching path. (inject_read_cache) This is something like read-requests turns into writers. But the code path is simpler than the actual write path because the data is assure