Friday, November 27, 2009

vim: create a custom ex command to quit on ":Q"

I put this in my ~/.vimrc so that it is available in every vim session:
:command -nargs=0 Quit :qa!

Finally! I wanted this little vim tweak since quite a while. I don't want the nagging "E492: Not an editor command: Q" error message every time I type ":Q" instead of ":q".

This command simply tells vim to do a ":qa!" when the user enters ":Quit" or an abbreviation of ":Quit" such as ":Q".

Thursday, November 26, 2009

linux basics: the mysterious three load average numbers

The traffic analogy

A single-core CPU is like a single lane of traffic. Imagine you are a bridge operator ... sometimes your bridge is so busy there are cars lined up to cross. You want to let folks know how traffic is moving on your bridge. A decent metric would be how many cars are waiting at a particular time. If no cars are waiting, incoming drivers know they can drive across right away. If cars are backed up, drivers know they're in for delays.

So, Bridge Operator, what numbering system are you going to use? How about:

  • 0.00 means there's no traffic on the bridge at all. In fact, between 0.00 and 1.00 means there's no backup, and an arriving car will just go right on.
  • 1.00 means the bridge is exactly at capacity. All is still good, but if traffic gets a little heavier, things are going to slow down.
  • over 1.00 means there's backup. How much? Well, 2.00 means that there are two lanes worth of cars total -- one lane's worth on the bridge, and one lane's worth waiting. 3.00 means there are three lane's worth total -- one lane's worth on the bridge, and two lanes' worth waiting. Etc.

 = load of 1.00

 = load of 0.50

 = load of 1.70




source:
http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

Wednesday, November 25, 2009

python: calling a shell command

>>> import subprocess
>>> subprocess.call('ls -l $HOME', shell=True)
total 5608
-rw------- 1 root root     816 2009-10-23 18:51 anaconda-ks.cfg
drwxr-xr-x 3 root root    4096 2009-11-11 21:15 AuthPerformance
drwxr-xr-x 2 root root    4096 2009-11-04 11:34 deleteme
-rw-r--r-- 1 root root     162 2009-10-23 21:08 eth0
-rw-r--r-- 1 root root    4118 2009-10-29 18:03 gdb.txt
-rw-r--r-- 1 root root      99 2009-10-23 21:08 ifcfg-eth0
-rw-r--r-- 1 root root   21859 2009-10-23 18:51 install.log
-rw-r--r-- 1 root root    3155 2009-10-23 18:51 install.log.syslog
-rw-r--r-- 1 root root 1444369 2009-10-26 16:16 libmod_piauth.so
-rw-r--r-- 1 root root 1442766 2009-10-21 18:04 libmod_piauth.so.bkp
drwxr-xr-x 2 root root    4096 2009-11-25 17:49 mozynow
-rw-r--r-- 1 root root  218691 2009-11-19 20:52 pi-auth-2.8-122769-122769-20091119.2030.02-linux-Release.i386.rpm
-rw-r--r-- 1 root root  376900 2009-11-10 11:52 reinstall.log
drwxr-xr-x 5 root root 2146304 2009-11-04 14:28 scripts
-rw-r--r-- 1 root root     382 2009-11-18 18:07 status
-rw-r--r-- 1 root root       0 2009-11-25 17:46 status.1
drwx------ 3 root root    4096 2009-11-19 21:29 usr
0
>>>


source

debian: how to install from .deb files, while taking care of dependencies


dpkg -i <file.deb>
apt-get -f install


This will pull in all undsatisfied dependancies or removes the offending package(s)

Note: Works like a charm! Just tried it on "justniffer_0.5.6_i386.deb" from "http://justniffer.sourceforge.net/index.html".

source

Thursday, November 19, 2009

Tuesday, November 17, 2009

awk: parse a conf file having "a=b" entries

Given a config file (i.e. a text input file to a test) containing "A=B" key/value pairs like the one below:

[root@mttf ~]# head authPerf.conf
domain = mttf.appfwk.net
testidentity = appfwk1
identityNameTemplate = test
password = abcabc
adminpassword = abcdef123

PROBLEM: How can I get the RHS of each "="? In other words, how can I get the values of 'domain', 'testidentity', 'password' etc?

SOLUTION: use AWK!
[root@mttf ~]# grep "domain" authPerf.conf | awk  -F= '{gsub(/^[ \t]+/ , "", $2); print $2}'
mttf.appfwk.net

Monday, November 16, 2009

excel: how to find the first blank row/column

First blank column in the A row:
=MATCH(TRUE,ISBLANK(A2:AA2),0)


First blank row in the A column:
=MATCH(TRUE,ISBLANK(A2:A1000000),0)

yet another "To Do" list

- i have really wanted to learn CSS and webdesign, ala dreamweaver/django/rails. it affords so much scope for creativity and self-expression. always wanted to build a nice website. gotta start setting aside an hour a day towards this goal.

- gotta complete pythonchallenge.com

- write simple script to parse XML in python (required for smoke test setup)
this is what the backup script does from the /pi/hosting/status page

- maybe even finish notpron?