Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Billy.Zheng zw963

🏠
Working from home
View GitHub Profile
View 1.rb
res = []
File.foreach('mastering-roda.org').each do |line_content|
line_content.scan(/(\b\w{2,}\b) (\b\k<1>\b)/).each do |e|
next if e == ['btn', 'btn']
res << [line_content, e]
end
end
View 1.txt
# System Info:
1. `uname -a`:
Linux zbook 5.12.12-arch1-1 #1 SMP PREEMPT Fri, 18 Jun 2021 21:59:22 +0000 x86_64 GNU/Linux
2. `lsb_release`:
`lsb_release` not found.
3. `/etc/lsb-release`:
View test.rb
#!/usr/bin/env ruby
puts 'test github token'
View sequel_migration.sh
#!/bin/bash
sec=$(date '+%Y%m%d%H%M%S')
mkdir -p db/migrations
set -u
new_migration=db/migrations/${sec}_$1.rb
if [[ "$1" =~ ^create_join_table_for_(.+)_and_(.+) ]]; then
content="create_join_table"
@zw963
zw963 / Ruby 3.0.0 benchmark.rb
Last active Apr 10, 2021
Ruby 3 benchmark for thread/process/Ractor
View Ruby 3.0.0 benchmark.rb
def tarai(x, y, z)
x <= y ? y : tarai(
tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y)
)
end
require 'benchmark'
@zw963
zw963 / add_capslock_ctrl.sh
Last active May 17, 2021
A script which change Capslock to Ctrl, and change rightAlt to Capslock for GNOME + Wayland for Arch linux.
View add_capslock_ctrl.sh
#! /bin/bash
if ! fgrep -qs 'ctrl:new_ctrl = +new_ctrl(new_ctrl)' /usr/share/X11/xkb/rules/evdev; then
sudo sed -i.bak '/ctrl:nocaps[[:blank:]]*=[[:blank:]]*+ctrl(nocaps)/a\
ctrl:new_ctrl = +new_ctrl(new_ctrl)
' /usr/share/X11/xkb/rules/evdev
fi
cat <<'HEREDOC' |sudo tee /usr/share/X11/xkb/symbols/new_ctrl
partial modifier_keys
@zw963
zw963 / kv_bench.rb
Created Jan 2, 2019 — forked from epitron/kv_bench.rb
Benchmark Ruby's various key/value databases (GDBM, SDBM, CDB)
View kv_bench.rb
require 'epitools'
%w[gdbm sdbm cdb].each { |lib| require lib }
DBS = [
[GDBM, GDBM],
[SDBM, SDBM],
[CDBMake, CDB ],
]
NUM = 100000
View zip.sh
bak_dir=~/Downloads
name=ik_kefu
full_name=$bak_dir/${name}
keep_count=3
date=$(date '+%Y-%m-%dT%H%M')
[ -e $full_name.zip ] && mv $full_name.zip "$full_name$date.zip"
bak_files=$(find $bak_dir/ -maxdepth 1 -name "${name}????-??-??T????.zip" |sort -V)
View em_fiber.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 有关 Fiber 的解释: (按照数据流的方向分为两部分)
# 在 `主线程' 中使用 resume 方法来启动(或继续执行)一个 `纤程'.
# 1. 第一次调用 fiber.resume, 会启动一个纤程,
# 如果 resume 调用时提供了实参, 会作为代码块形参传入代码块.
# 2. 如果非第一次调用 fiber.resume, 即, `恢复' 一个纤程, 会做两件事:
# - 从上次离开纤程的那个位置(调用 Fiber.yield 离开纤程的那个位置), 恢复纤程的执行.