Mat , Hychen
Mat 問有沒有辦法把python args/kwargs 對應到 command line tools的args/options
Mat 覺得ucltip不太物件導向
Hychen說: 這玩意本來就是以我用得順手來開發的 XD
import ucltip
ls = ucltip.Cmd('ls')
ls.opts(a=True)
ls.execute('/tmp')
ls2 = ucltip.Cmd('ls')
ls2.opts(l=True)
ls2.execute('/tmp')
Hychen , Thinker
如果要同時輸出到 pipe 與 stdout,可以把訊息寫到 /dev/tty (等於目前的 control terminal)
# Use TTY for print information or debuging message
# Use STDOUT for printing MissionMessage
self.tty_fd = os.open('/dev/tty', os.O_WRONLY)
self.bk_stdout = os.dup(sys.stdout.fileno())
os.close(sys.stdout.fileno())
os.dup(self.tty_fd)
self.bk_stdout = os.fdopen(self.bk_stdout, 'w')
缺點
缺點: stdout 沒辦法被rederiect, 不能用cron, 因為cron沒有tty
$4
新版的字串反轉,字串內容包含 UTF-8
http://paste.ubuntu.com/835223/
#include <stdio.h>#include <string.h>
int main(int argc, char* argv[]){
char msg[] = "哈囉世界";
int size = strlen(msg);
int i = 0, pos = 0;
for (i = 0; i < size / 2; i++) {
msg[i] ^= msg[size - 1 - i];
msg[size - 1 - i] ^= msg[i];
msg[i] ^= msg[size - 1 - i];
}
while (pos < size) {
int start = pos;
int end = pos;
for (i = pos; i < size; i++) {
if ((msg[i] & 0x80) == 0x80) {
start = i;
break;
}
}
for (i = start + 1; i < size; i++) {
if ((msg[i] & 0xC0) == 0xC0) {
end = i;
break;
}
}
for (i = start; i*2 < (start + end); i++) {
msg[i] ^= msg[end + start - i];
msg[end + start - i] ^= msg[i];
msg[i] ^= msg[end + start - i];
}
pos = end + 1;
}
printf("%s\n", msg);
return 0;
}
Wayling
#qemu bridge mode ? 可以讓兩個guest mode linux互ping成功
/sbin/ifconfig eth0 down
/sbin/ifconfig eth0 0.0.0.0 promisc up
openvpn —mktun —dev tap0
ifconfig tap0 0.0.0.0 up
openvpn —mktun —dev tap1
ifconfig tap1 0.0.0.0 up
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 tap0
brctl addif br0 tap1
brctl stp br0 off
ifconfig br0 10.10.10.2 netmask 255.255.255.0
linux image用qemu官網提供的
guest 1:
qemu -m 512 -hda linux-0.2.img -net nic -net tap,ifname=tap0,script=no
guest 2:
qemu -m 512 -hda linux-0.2.img -net nic,macaddr=00:01:02:03:04:05 -net tap,ifname=tap1,script=no
PS:
1. ip 記得要設
2. 原本ping不通,發現原來 MAC address會一樣所以一個guest 隨便設一個MAC address