This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trim() { | |
local var="$*" | |
# remove leading whitespace characters | |
var="${var#"${var%%[![:space:]]*}"}" | |
# remove trailing whitespace characters | |
var="${var%"${var##*[![:space:]]}"}" | |
printf '%s' "$var" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"strings" | |
"text/template" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
set timeout 5 | |
set user [lindex $argv 0] | |
set host [lindex $argv 1] | |
set password [lindex $argv 2] | |
spawn ssh-copy-id $user@$host | |
expect { | |
"*yes/no" { send "yes\r";exp_continue } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toplevel=$(git rev-parse --show-toplevel) | |
log_file=$HOME/.commit_log/$(date +%Y)_week_$(date +%U).log | |
message=$(git log -1 --pretty=format:'%H%n%cd%n%s%n%b') | |
mkdir -p "$HOME/.commit_log" | |
touch "$log_file" | |
printf "%s\n$message\n--------------------------------------------------------------------------------\n" "$toplevel" >> "$log_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package time33 | |
func Time33(s []byte) uint64 { | |
hash := uint64(0) | |
for _, b := range s { | |
hash += hash<<5 + uint64(b) | |
} | |
return hash | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def frange(start, stop, increment): | |
x = start | |
while x < stop: | |
yield x | |
x += increment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dedupe(items, key=None): | |
seen = set() | |
for item in items: | |
val = item if key is None else key(item) | |
if val not in seen: | |
yield item | |
seen.add(val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import socket | |
import time | |
HOST = 'localhost' | |
PORT = 1680 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((HOST, PORT)) | |
s.setsockopt(socket.SOL_TCP, socket.TCP_QUICKACK, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package trylock | |
import "sync/atomic" | |
// Mutex trylock的mutex | |
type Mutex struct { | |
v int32 | |
} | |
// TryLock 尝试获取锁,取不到则返回false |
NewerOlder