× [PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。 |
![]() |
引越し検討がてら、MovableType To Yaml のsedスクリプト作ってみた。
MovableTypeフォーマット このフォーマットsedで置換できますか? ソース いい感じにyamlになって使い勝手が良いかも? Qiitaはエクスポート標準で対応してないし、インポートもできないのか。。。 引越し辞めるかw PR |
![]() |
mkfifoを使うと標準出力と標準入力を用いてインタプリタのプログラムを組むことが容易になる。
pythonプログラム(subprocessを用いていない) import re def send(s): RET = "@@RETURN VALUE@@" print(s+";echo {} $?".format(RET)) outputs = [] while True: output = input() if re.search("^{} ".format(RET), output): m = re.match("^{} (.*)".format(RET), output) return (int(m.groups()[0]), outputs) outputs.append(output) import sys print(send("ping www.google.co.jp -c 4"), file=sys.stderr) print(send("ls ----"), file=sys.stderr)subprocessなしでシェルをキック $ mkfifo net $ bash < net 2>&1 | tee /dev/stderr | python ls.py | tee net ping www.google.co.jp -c 4;echo @@RETURN VALUE@@ $? PING www.google.co.jp (142.250.206.195) 56(84) bytes of data. 64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=1 ttl=56 time=14.8 ms 64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=2 ttl=56 time=16.6 ms 64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=3 ttl=56 time=15.8 ms 64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=4 ttl=56 time=15.4 ms --- www.google.co.jp ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 14.760/15.666/16.645/0.681 ms @@RETURN VALUE@@ 0 (0, ['PING www.google.co.jp (142.250.206.195) 56(84) bytes of data.', '64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=1 ttl=56 time=14.8 ms', '64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=2 ttl=56 time=16.6 ms', '64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=3 ttl=56 time=15.8 ms', '64 bytes from kix07s07-in-f3.1e100.net (142.250.206.195): icmp_seq=4 ttl=56 time=15.4 ms', '', '--- www.google.co.jp ping statistics ---', '4 packets transmitted, 4 received, 0% packet loss, time 3005ms', 'rtt min/avg/max/mdev = 14.760/15.666/16.645/0.681 ms']) ls ----;echo @@RETURN VALUE@@ $? ls: unrecognized option '----' Try 'ls --help' for more information. @@RETURN VALUE@@ 2 (2, ["ls: unrecognized option '----'", "Try 'ls --help' for more information."]) ほかにも、通信系のインタプリタをライブラリなしで実行することができる。 便利なり。 その代わり、標準出力は使えないが(笑)簡易RPA的なコンソールプログラムはすぐに作れる。 |
![]() |
・Ubuntuが起動できなくなったので、インストールCDでリカバリした。
マウント chroot デバイスドライバまわりのメモ ・r8168ネットワークドライバが認識しない。 RTL8111/8168/8411 のインストールに苦悩した話 ・i915ビデオドライバがflickerする。 「PCIe Bus Error: severity=Corrected, type=Data Link Layer」を回避する方法 |
![]() |
AGC039に参加して問題Bが解けなかったのだけども、解き方が分かったので解説
問題としては、同じVnに辺があってはいけないというもの。 幅優先探索法で、既に探索済みのノードに出会った場合、次のレベルか前のレベルかしかないということに気づけば後はもっとも長いパスを見つければOK うーん、時間中には思いつかん。。。 |
![]() |
作ったのはこちら
https://github.com/doshiraki/rbtree_bygo/blob/master/rbtree.go 赤黒木 やっぱり削除は難しい。。。 ポイントは、delete case 3,4がまったく同じ結果というようにまとめられること。 Node := delNode for { parent := Node.parent if parent == nil { //case 1 break } dir := Node.dir() dirOther := dir ^ 1 sibling := parent.children[dirOther] if sibling.isRed { //case 2 parent.flip(dirOther) sibling.isRed = false parent.isRed = true sibling = parent.children[dirOther] } //sibling is Black nephew := sibling.children[dirOther] if nephew == nil || !nephew.isRed { //far nephew is Black nephew = sibling.children[dir] if nephew == nil || !nephew.isRed { //near nephew is Black sibling.isRed = true if parent.isRed { //case 4 parent.isRed = false break } else { //case 3 Node = parent continue } } //case 5 //near nephew is Red and far nephew is Black sibling.flip(dir) sibling, nephew = nephew, sibling sibling.isRed = false nephew.isRed = true } //case 6 //sibling is Black && far nephew is Red saveColor := parent.isRed parent.flip(dirOther) sibling.isRed = saveColor parent.isRed = false nephew.isRed = false break } |
![]() |
忍者ブログ [PR] |