Tuesday, December 14, 2010

Perl 1 liners

For a number of reasons I think Perl is an unsightly language, but at my current employer its the language of choice. One place Perl definitely shines is its 1 liners:

http://blog.ksplice.com/2010/05/top-10-perl-one-liner-tricks/

Tuesday, November 16, 2010

screen

I'm just starting to see the power in screen. What is screen?

From the man page:
Screen is a full-screen window manager that multiplexes a physical
terminal between several processes (typically interactive shells).
Each virtual terminal provides the functions of a DEC VT100 termi-
nal and, in addition, several control functions from the ISO 6429
(ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete
line and support for multiple character sets). There is a scroll-
back history buffer for each virtual terminal and a copy-and-paste
mechanism that allows moving text regions between windows.


Screen is good for continuous virtual sessions that are not interrupted by network connectivity. IE stays around when you don't want to worry about getting disconnected from the server.

heres me screenrc:
defscrollback 10000
vbell off
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%{y}%H%{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%m/%d %{W}%c%{g}]'

My screenrc (that I lifted from a friend...) shows which virtual terminal you are in and what host you are on.

Be forewarned -- scroll back works a little diffrent you have to use the screen specific mechanism.

Also CTRL-A has special meaning, it does not go to the begging of the line like it does in normal BASH or Emacs.

use CTRL-A CTRL-D to detach from a screen session
use `screen -r ` to reconnect to an old detached session
use `screen -ls` to see open screen sessions

Thursday, November 4, 2010

svn: overwrite local files with repository files

From time to time I want get ride of locally modified files (mostly I end up modifying code for testing purposes). svn revert makes this super easy.

(from svn checked out directory)
svn revert -R .

Friday, October 29, 2010

greping multiple lines

I just found a neat way to grep multiple lines when you only know the contents of one of those lines --

Use -B n to see n lines before the match and -A m to see m lines after the match.

ie. grep -B2 -A2

Example --


root@localhost:~# echo ' Cell 52 - Address: 00:24:6C:AB:26:D3
Protocol:802.11b/g/n
ESSID:"StevesAP"
Mode:Managed
Frequency:2.462 GHz (Channel 11)
Quality:100/100 Signal level:-25 dBm Noise level:-92 dBm
Encryption key:on
Bit Rates:54 Mb/s
IE: IEEE 802.11i/WPA2 Version 1
' | grep -B2 -A2 -i steve

Cell 52 - Address: 00:24:6C:AB:26:D3
Protocol:802.11b/g/n
ESSID:"StevesAP"
Mode:Managed
Frequency:2.462 GHz (Channel 11)

Tuesday, March 30, 2010

run script every 5 minutes via cron

Crontab hint.
*/5 * * * * /path/to/script

reminder: cron runs in its own shell; make sure you import nonstandard shell variables / shell functions you may need.