VIM: Visual block select with edit!

Within Vim, do following sequence to edit to be applied in highlighted virtual block:

Ctrl+v -> select block with cursor -> Shift+ -> enter edit val -> ESC -> done

For example, I would like to insert '//' comment line in front of all highlighted syntax:

Ctrl+v -> select block with cursor -> Shift+i -> type in '//' -> ESC -> done

Tada! Magic!


Great reference sites to beef up your interview skills

Great listing put together by Mashables in 9 Sites for Successful Job Interviews
Quotes below:

InterviewUp - Is a mixture of a job board along with a community of people who share their interview experiences from different fields so that you can get a feel for what types of questions you may get when you go in, and what sort of answers work best.

About.com - With About.com’s ever growing catalog of articles on just about every subject, it’s not surprising they have a section dedicated to job interviews. They have suggested answers for numerous questions, tips on sending thank you letters, tips for your resume and more.

AceTheInterview - AceTheInterview is totally dedicated to about every aspect of the job hunt you can think of. Their interview section has important notes on things such as do’s & don’ts, the touchy area of salary negotiations, an interview checklist and more.

CareerBuilder - The popular mainstream job hunting site offers numerous tips on all aspects of the application and interview process, tips on marketing yourself, how to promote your hidden job skills and more.

CareerLab - Offers advice on what to do if you don’t get a job offer after multiple interviews, a cheat sheet to keep notes on your interview as well as what you wore so you don’t repeat an outfit, sample cover letters and more.

HotJobs - Yahoo’s job search site offers numerous tips on how to prepare, how to present yourself, follow up on the interview, even how to handle an interview over a meal, and more.

InterviewBest - Helps you come up with concise interview presentations that present your strong points and how you would benefit a company.

Monster - The well known job search site also offers quizzes you can use to see how ready you are for various aspects of your job hunt as well as a random job interview question generator.

QuintCareers - Is a site dedicated to preparing you for your job hunt with over 3,500 pages of free career advice. They have a large section dedicated to what to expect from the interview process and how best to prepare for it.


More UNIX usage tips!

!$ operator returns the file_system_access.c argument, and the !:1 operator returns the kxp12.c argument, which is the first argument of the previous command.

$ mv kxp12.c file_system_access.c
$ ln –s !$ !:1

df command shows you the total number of blocks used on each available volume and the percentage of free space.

Use the find command with the -size parameter. Listing 7 shows how to use the find command to find files larger than 10MB. Note that the -size parameter takes a size in kilobytes.
$ find / -size +10000k –xdev –exec ls –lh {}\;

Make the most of regular expressions

Many UNIX commands use regular expressions as arguments. Technically speaking, a regular expression is a string (that is, a sequence of characters composed of letters, numbers, and symbols) that represents a pattern defining zero or more strings. A regular expression uses meta-characters (for example, the asterisk [*] and question mark [?] symbols) to match parts of or whole other strings. A regular expression doesn't have to contain wildcards, but wildcards can make regular expressions useful for searching for patterns and manipulating files. Table 1 shows some basic regular expression sequences.

Table 1. Regular expression sequences
Caret (^)Matches the expression at the start of a line, as in ^A
Question mark (?)Matches the expression at the end of a line, as in A?
Backslash (\)Turns off the special meaning of the next character, as in \^
Brackets ([])Matches any one of the enclosed characters, as in [aeiou] (Use a hyphen [-] for a range, as in [0-9].)
[^ ] Matches any one character except those enclosed in brackets, as in [^0-9]
Period (.)Matches a single character of any value except end of line
Asterisk (*)Matches zero or more of the preceding characters or expressions
\{x,y\} Matches x to y occurrences of the preceding
\{x\} Matches exactly x occurrences of the preceding
\{x,\} Matches x or more occurrences of the preceding

Listing 12 shows some of the basic regular expressions used with the grep command.

Listing 12. Using regular expressions with grep
$ # Lists your mail
$ grep '^From: ' /usr/mail/$USER
$ # Any line with at least one letter
$ grep '[a-zA-Z]' search-file.txt
$ # Anything not a letter or number
$ grep '[^a-zA-Z0-9] search-file.txt
$ # Find phone numbers in the form 999-9999
$ grep '[0-9]\{3\}-[0-9]\{4\}' search-file.txt
$ # Find lines with exactly one character
$ grep '^.$' search-file.txt
$ # Find any line that starts with a period "."
$ grep '^\.' search-file.txt
$ # Find lines that start with a "." and 2 lowercase letters
$ grep '^\.[a-z][a-z]' search-file.txt

Process data with awk

The awk command always seems to live in the shadows of Perl, but it can be a quick, useful tool for simple command-line-based data manipulation. Listing 15 shows how to get started with the awk command. To get the length of each line in the file text, use the length() function. To see if the string ing is present in the file text, use the index() function, which returns the location of the first occurrence of ing so that you can use it for further string processing. To tokenize (that is, split a line into word-length pieces) a string, use the split() function.

Listing 15. Basic awk processing
$ cat text
testing the awk command
$ awk '{ i = length($0); print i }' text
$ awk '{ i = index($0,”ing”); print i}' text
$ awk 'BEGIN { i = 1 } { n = split($0,a," "); while (i <= n) {print a[i]; i++;} }' text

Printing specified fields of text file is a simple awk task. In Listing 16, the sales file consists of each salesperson's name followed by a monthly sales figure. You can use the awk command to quickly total the sales for each month. By default, awk treats each comma-separated value as a different field. You use the $n operators to access each individual field.

Listing 16. Using awk for data summarization
$cat sales
$ awk -F, '{print $1,$2+$3+$4}' sales
Gene 42
Dawn 50
Renee 46
David 46


Perl Tip: Couple useful stuffs

$` $& $' before match after

\w - type words made up of ordinary letters, digits, and underscores.
\b - anchor matches at the start or end of a group of \w characters

redir all IO's (including STDOUT and STDERR) during command line execution or script execution:
(cmd) >& out

Perl Tip: Bundling options

Use this statement to 'bundle' the given options:

use Getopt::Long;

This enables options of say -d and -e into -de bundling!

Perl Tip: Call variable based subroutines

Take off strict temporarily while you pipe it in the variable based subroutine calls.

{ no strict 'refs';
*{$ProdMod . "::Init"}->(\%Subroutines,$Debug);

$ProdMod is variable where subroutine call is call {$ProdMod."::Init"}. %Subroutines and $Debug are the input variables to the provided subroutine.

Also, can put it into hash or array which points to the subroutine calls as so:
my %Subs = (
"test1" => \&test1,
"test2" => \&test2,
"test3" => \&test3,
"test4" => \&test4,

And calls it:

Considering you have test1-4 subroutine defined:
sub test1($$) {...}


Cygwin Vi syntax enabling

Just create .vimrc file with following content:

   syntax enable
set sw=4 ts=4 et
set wildmenu

Not loading .bashrc in cygwin

Add this line in the end of '/etc/profile' file:

. "${HOME}/.bashrc"

Problem solved! Make sure $HOME is pointing to your home directory and you have .bashrc file generated.

[Update] Cygwin always load off of '.bash_profile' instead of '.bashrc' file. Thus, another solution is to do 'source ~/.bashrc' within '.bash_profile'. Or add the following line in '.bash_profile':

if [ -f ~/.bashrc ]
. ~/