Wednesday, July 25, 2012

Vim - open a list of files from previous command


Problem : You want to execute a find command and open all the files into vim

find . -name * | xargs vim

Something not working right ?

Try
$> find . -name *
$> vim $(!!)

What just happened ?

The first command executes a "find"

The second command is opening vim and providing an argument list from a previous command. You
could also have executed

$> vim $(find . -name *)

Keywords
output command previous xargs vim to pipe

Tuesday, February 7, 2012

Using key mapping in vi

vi or vim provide a very useful technique whereby user can assign arbitrary functions to control key strokes. For eg, here is one such mapping:

map ^k I/*A*/

When a hits ctrl+k, the line on which the cursor currently is, is commented. To explain the command:
map ^k - assigns the functionality to ctrl+k character
I/*A*/ - concatenation of smaller operations which are
- Move to Esc mode,
I - Insert in the beginning of the line
/* - characters to be inserted
- Move to Esc mode
A - Append at the end of the line
*/ - characters to be appended
- move to Escape mode

The Esc key can be typed by first typing Ctrl+V followed by Esc key.

By adding this mapping to .vimrc file, this mapping can be saved across vim invocations.

Monday, February 6, 2012

Using vi as Line Editor in bash

For folks who are comfortable with vi, use the following command and override the default line editor (emacs) in bash:

$ set -o vi

Now start using vi commands to edit bash commands. It supports both insert and escape modes, just like the vi text editor.

Thursday, February 2, 2012

Sorting in a recursive query

Here is a neat utility from Oracle to query a table recursively, and sort results among siblings:

SELECT e.id, e.name, e.manager_id
FROM employee e
START WITH ID = 1
CONNECT BY manager_ID = PRIOR ID
order siblings by e.name;

Note the 'order siblings by' clause. This can be used only with recursive queries and sorts the siblings by the name.

Sunday, January 15, 2012

Oracle Cascade Delete

http://www.sandeepsinghal.com/2012/01/14/oracle-cascase-delete/

Sunday, October 9, 2011

Oracle SID vs Service Name in JDBC URL

With SID
jdbc:oracle:thin@myhost:port:sid

With Service Name
jdbc:oracle:thin@myhost:port/service

Tuesday, October 4, 2011

Vim - Join Lines with a Comma (or any other character)

Step 1 : Put the desired character at the end of each line. I will use a "," as an example

:%s/$/,/g

Step 2 : Join the lines together

%j!

Monday, October 3, 2011

Post on Logging.

My post on logging in production

http://sandeepsinghal.wordpress.com/2011/09/18/better-you-log-in-development-less-you-will-bleed-in-production/

Google Code Page for Unix Utils

 Adding some of my utility shell scripts to a common google page.

http://code.google.com/p/nixtils/ 

Monday, July 25, 2011

Linux - See which process is using which port

netstat -anop

Then use ps and grep to find the process using this port

Windows - See what processes are using which ports

netstat -ano

You can then use the task manager to see the process id of the owning process.

Tuesday, February 23, 2010

Installing xmllint on cygwin

Select the following pacakges
  • libxml
  • libxslt

Sunday, December 27, 2009

symbolic links in windows

junction - sysinternal tool for winxp and above

mlink - with vista and above

Saturday, November 7, 2009

Find lines of code in your repository


for ext in "*.java" "*.xml" "*.css" "*.jsp" "*.js" "*.sql"
do
echo -n "$ext,$location,"
find ./$location -iname "$ext" -exec wc -l '{}' \;|gawk '{total+=$1} END{print total}'
done

Thursday, July 2, 2009

Getting tablespace Size


SELECT tablespace_name,
  SUM (bytes) / 1024 / 1024 current_size,
  autoextensible,
  SUM (maxbytes) / 1024 / 1024 max_size
FROM dba_data_files
WHERE tablespace_name like '%'
GROUP BY tablespace_name, autoextensible
ORDER BY 1

Sunday, May 10, 2009

bash : search and replace from previous command

tar -cvf sandeep.tar sandeep/

!!:gs/sandeep/singhal will mean

tar -cvf singhal.tar singhal/

:gs is for global search and replace

bash - last argument of the previous command (nth argument)

  • Get the last argument of the previous command : !!$
  • Get the first argumnet of the previous command : !!^
  • Get the 1st argument of the previous command : !!1
  • Get the nth argument of the previous command : !!n

Examples : 

$> ls :!!$  (or !$) 

$> ls :!!^

$> ls :!!2

$> ls :!!n

Saturday, May 2, 2009

Trigger GC in eclipse.

This is a handy for eclipse which lets you to trigger gc in the eclipse instead of waiting for the jvm to schedule the GC .

Go to Window->Preferences->General, mark Show Heap status check box.
The current Heap usage with icon for "Run Garbage Collector" will appear at the bottom right.

It helps a lot in eclipse performance.

I find it pretty handy especially because I do not shutdown eclipse often.

Friday, May 1, 2009

Two things I love about opera

1. You can type windows specific path on the browser bar and it will covert it to "forward slashes" when you are browsing directory like strucure on a browser

2. The quick search box : The cursor remains at the same place if you go to a different window by "ALT-TAB". This in firefox changes to select the entire text already typed in the search box. Hence you cannot start typing straight away, since that will erase the already entered text.