Skip to content

Instantly share code, notes, and snippets.

View wfxr's full-sized avatar
☃️
I may be slow to respond.

Wenxuan wfxr

☃️
I may be slow to respond.
  • ::1
  • Nauvis
View GitHub Profile
package main
import "fmt"
func foo1() {
fmt.Println("Hello, world")
fmt.Println("Hello, world")
fmt.Println("Hello, world")
fmt.Println("Hello, world")
fmt.Println("Hello, world")
@wfxr
wfxr / main.go
Last active April 18, 2021 10:34
Primes
package main
import "fmt"
func main() {
for prime := range primes(100) {
fmt.Println(prime)
}
}
@wfxr
wfxr / surfingkeys.js
Last active December 29, 2021 05:37
surfingkeys config
// vim: set ft=javascript:
settings.tabsMRUOrder = false;
mapkey('T', 'Choose a tab with omnibar', function() {
Front.openOmnibar({type: "Tabs"});
});
mapkey('gt', '#8Open a URL', function() {
Front.openOmnibar({type: "URLs", extra: "getAllSites"});
@wfxr
wfxr / gist:126c6d0ca716a60f1db53ff8d3f922d3
Created January 28, 2019 03:25
gpg safe private key
gpg --s2k-cipher-algo AES256 --s2k-digest-algo SHA512 --s2k-mode 3 \
--s2k-count 65000000 --edit-key <key id>
@wfxr
wfxr / PercentageRound.kt
Created September 6, 2018 11:51
Algorithms
// 保证总和为100%的前提下损失精度最小的百分比Rounding算法
import com.google.common.math.IntMath
fun percentageRound(a: List<Double>, precision: Int): List<Double> {
val factor = IntMath.pow(10, precision)
val scaled = a.map { it * factor }
val rounded = scaled.mapIndexed { i, num -> i to Math.round(num) }
val sum = rounded.fold(0L) { acc, pair -> acc + pair.second }
@wfxr
wfxr / swap_ctrl_caps.ps1
Last active October 10, 2022 05:48
Swap ctrl and capslock in Win10
$hexified = "00,00,00,00,00,00,00,00,03,00,00,00,3A,00,1D,00,1D,00,3A,00,00,00,00,00".Split(',') | % { "0x$_"};
$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout';
New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified);
@wfxr
wfxr / snippet.md
Created November 16, 2017 08:24
Zsh代码片段

将字符串分割成数组

str='Tom,Jarry'
users=(${(@s/,/)str})

将数组合并成字符串

# 用回车符Join
${(j:\n:)users}
@wfxr
wfxr / ssh.md
Last active November 15, 2017 10:28
Linux commands

基本参数

正向代理

ssh -fCNL

反向代理

ssh -fCNR
@wfxr
wfxr / bash-snippets.sh
Last active August 2, 2017 02:32
Bash代码片段
# bash 遍历文件
if [[ -d "/etc/zsh.d" ]]; then
for f in /etc/zsh.d/*.zsh(N); do
source $f
done
fi
# The (N) tells zsh to set the NULL_GLOB option for that pattern. When no
# matches are found, the glob expands to an empty string instead of throwing an
# error. In zsh a for loop over an empty expansion does nothing, which is the
# behavior we want here.
@wfxr
wfxr / test-command-exist.txt
Last active July 26, 2017 02:47
zsh和bash测试命令是否存在
Bash
The testing results for bash is shown in the following table, with each testing command running for 100,000 times:
TESTING COMMAND RUNNING TIME (REAL, USER, SYS)
type ls &>/dev/null 0m1.476s, 0m0.632s, 0m0.836s
hash ls &>/dev/null 0m1.598s, 0m0.740s, 0m0.856s
command -v ls &>/dev/null 0m1.441s, 0m0.660s, 0m0.776s
which ls &>/dev/null 2m0.418s, 0m3.852s, 0m13.212s
According to the results, type and command -v are the two fastest ways to test the existence of a command in bash. I have also run the tests with either set +h or set -h, but the results do not have obvious difference.