プログラムが複雑になる一番の理由は条件分岐 (if 文など) です。
条件分岐がなければ、一本道で読み下していけばいいのでバグが入り込む余地は大変少なくなります。
ということで、
- 条件分岐を書かなくていいように書く
- 条件分岐を書くなら、わかりやすく局所化して書く
#!/bin/sh | |
SEC=$1 | |
tcpdump -s 65535 -nn -q -tttt -x port 3306 -l > /tmp/tcpdump.3306 2> /dev/null & | |
PID_3306=$! | |
tcpdump -s 65535 -nn -q -tttt -x port 11211 -l > /tmp/tcpdump.11211 2> /dev/null & | |
PID_11211=$! |
#!/bin/sh | |
# Just copy and paste the lines below (all at once, it won't work line by line!) | |
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY! | |
function abort { | |
echo "$1" | |
exit 1 | |
} | |
set -e |
# Max line width is 78 cols | |
-l=78 | |
# Indent level is 4 cols | |
-i=4 | |
# Continuation indent is 4 cols | |
-ci=4 | |
# Output to STDOUT |
#!/usr/bin/env perl | |
=head1 Examples | |
$ tail -f access_log | perl colorize.pl | |
$ plackup app.psgi 2>&1 | perl colorize.pl | |
=cut | |
use strict; |
After upgrading to Mountain Lion : 10.8 I noticed that I was getting Python errors which prevented me from starting vim: | |
Traceback (most recent call last): | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 565, in <module> | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 547, in main | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 278, in addusersitepackages | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 253, in getusersitepackages | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 243, in getuserbase | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 523, in get_config_var | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 419, in get_config_vars |
diff -Narup tmux-1.6.orig/tty-acs.c tmux-1.6/tty-acs.c | |
--- tmux-1.6.orig/tty-acs.c 2012-10-15 00:13:51.729160450 +0900 | |
+++ tmux-1.6/tty-acs.c 2012-10-15 00:35:51.770801087 +0900 | |
@@ -41,21 +41,21 @@ const struct tty_acs_entry tty_acs_table | |
{ 'g', "\302\261" }, | |
{ 'h', "\342\226\222" }, | |
{ 'i', "\342\230\203" }, | |
- { 'j', "\342\224\230" }, | |
- { 'k', "\342\224\220" }, | |
- { 'l', "\342\224\214" }, |
How it looks like | |
================================== | |
mysql> select queue_stats('t'); | |
+------------------------------------------------------------------------------------------------------------------------------+ | |
| queue_stats('t') | | |
+------------------------------------------------------------------------------------------------------------------------------+ | |
| rows_written: 0 | |
rows_removed: 0 | |
wait_immediate: 0 |
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Socket; | |
use IO::Socket; | |
use IO::Socket::INET; | |
use IO::Select; | |
use IO::Handle; |