将字符串分割成数组
str='Tom,Jarry'
users=(${(@s/,/)str})将数组合并成字符串
# 用回车符Join
${(j:\n:)users}| 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") |
| package main | |
| import "fmt" | |
| func main() { | |
| for prime := range primes(100) { | |
| fmt.Println(prime) | |
| } | |
| } |
| // 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"}); |
| gpg --s2k-cipher-algo AES256 --s2k-digest-algo SHA512 --s2k-mode 3 \ | |
| --s2k-count 65000000 --edit-key <key id> |
| // 保证总和为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 } |
| $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); |
将字符串分割成数组
str='Tom,Jarry'
users=(${(@s/,/)str})将数组合并成字符串
# 用回车符Join
${(j:\n:)users}| # 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. |
| 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. |