Sunday, July 05, 2009

GDB handy commands

Multi-threaded

info threads

Signals

info signals
// To pass the signal from GDB to the process.
handle SIGINT pass

To Debug a running process using GDB

gdb

Tuesday, May 19, 2009

VIM : Comments lines with a pattern in a file

The lines in a file containing a specific pattern can be commented in VIM using the :g command.
:g command is used in following form
:g/[patern]/[cmd]

Example:
:g/JR/normal I //

explanation
Pattern : JR
Cmd : normal I //

"I" is used in VIM to start insert mode at the start of line and "//" is the comment character used in PHP.

Enjoy VIM. Check out the help :g if you have more questions.

Monday, March 30, 2009

Toggle Comment in VIM in one line using perl

There are lot of scripts in VIM which can toggle comments for you. But interestingly there is not a one liner which I can execute on systems where I do not have my vimrc file.

try this mapping

:map F2 V:!perl -nle 'if (/^\s*\/\//) { s/\s*\/\/\s*(.*)/$1/g; print } else {print "//".$_}'^Mj

You can map Alt+C or Ctrl+T something which is faster than F2

This mapping will comment and uncomment the C-style comment. I have tried this on Ubuntu and VIM 7.1 and works fine for me

Note: The map command may not work on copying as the VIM may not recognize the Ctrl - M character. You have to Ctrl- V and then Enter to make it work

Friday, March 13, 2009

Singleton versus Static

These are rules which I use to decide where or not my class will be a Singleton or Static:
  1. Control over construction. Timing issues.
  2. Polymorphism.
  3. One versus multiple instances.

Tuesday, March 10, 2009

Formatting XML in VIM - xmllint --format -

XML text can be formatted in VIM by running the xmllint command over the selected text.

!xmllint --format -

Note the hyphen at the last.

Tried searching for sorter options for --format but did not found any.

Monday, March 09, 2009

VNC not working on locked PC

Problem:
---------
I found that the VNC was not working on my PC(Windows XP) when it was locked using Ctrl+Alt+Del. Interestingly it did worked when the PC was not locked.

Solution:
---------
While installing VNC make sure that you select the option to install it as a service so it can be seen in services.msc

On installing VNC, it provides an option to install as a service. If it is not installed as an service, the VNC cannot be done on a locked PC.

Reason:
--------
This is what as told by one of my colleagues. Seems to be logical.

Windows uses API from gina.dll which provides the capabilities for locking/unlocking the workstation. API from gina.dll are accessible only by the windows services and not by other programs.

Saturday, October 11, 2008

timeout

Debian has an interesting command timeout:

timeout 5 tail -f /var/log/messages

If you do not have timeout package installed, perl can be used to perform the same:

perl -e "alarm shift @ARGV; exec @ARGV;" 5 tail -f /var/log/messages

Reference links:
http://michael.thegrebs.com/2008/05/27/most-awesome-command-ever/
http://www.cyberciti.biz/faq/shell-scripting-run-command-under-alarmclock/

Wednesday, September 17, 2008

Ethtool - Finding the NIC to which the LAN cable is connected

How to find if it is eth01, eth02, eth03 etc to which the LAN is connected.
Sometimes the PCI slots are not properly numbered and we cannot rely on the normal naming convention. Linux ethtool comes handy at that time to find the NIC card.

Use

ethtool -p

This will glow the light on the NIC card. You can just see the glowing the NIC and guess the name.

Tuesday, September 16, 2008

Creating firefox extension

Try out the extension wizard to create ur own extension. More about my first extension to view the PR records is coming later :-)

http://ted.mielczarek.org/code/mozilla/extensionwiz/

Tuesday, August 19, 2008

Get the last column from the ls command

awk '{ printf $NF;$NF = "" ;printf " "$0"\n" }' | sort

http://www.linuxfocus.org/English/September1999/article103.html

Here is one more trick I have learned from my colleague

ls -ltr | while read a b c d e f g h file; do echo $file; done

The second technique looks much easy to me

Friday, June 27, 2008

xargs command replace string

Using xargs command with replace string

to scp files with spec pattern

ls file* | xargs -n1 -i{} scp {} root@:/dest

Friday, May 23, 2008

Petroff Defense Trap

1. e4 e5
2. Nf3 Nf6
3. Nxe5 Nxe4
4. Qe2 Nf6
5. Nc6

Now the black Queen is DEAD. Black king is in check by White Queen and his queen is in attack by knight.To save check and his queen he can 5. .. Qe7 but then white can take the queen with knight at d6

PHP Hacking 1 = 1

'1 =1 ' is classic example of SQL injection attack. For the authentication some PHP GUI saves the user id and password in database. Generally a query something like this is used to validate the user given information:

SELECT * FROM users
WHERE user=''
AND passwd=''

A simple hacker like me ;-) can use SQL injection attack by specifying
User: Any
Password: OR 1 =1

This will allow me to give access to the site. Depending on the query you may need to try other variations like

Password: ') OR ('1=1')

The idea is to inject 1 =1 (which is true) in SQL statement such that the WHERE clause returns TRUE.

Happy Hacking...

Thursday, May 08, 2008

Putty passwordless ssh

putty accepts login and password as command line. So it can be easily used in batch to access machines without giving login and password.

putty host1 -l root -pw

I use it to the server which are build frequently. The problem with the server built frequently is that you cannot exchange keys as the keys will be deleted when the server is built again.

If you are using a linux box then sshpass can also be used for auto SSH.

Here is the batch script for windows lover

@echo off
if %1 == myserver goto myserver
goto default

:myserver
start C:\putty -ssh mercury -l -pw
exit

:default
start C:\putty -ssh %1 -l root -pw
exit

Vim Ctrl-r Ctrl-w

Vim Ctrl-r Ctrl-w can be used to read the word under the cursor. It is useful if you want to edit files under the cursor.

:e \C-v \C-r \C-v\C-w \C-v

I know you can use gf to go the file. But just wanted to do it using one key.:-)

Bind command

bind command can be used to bind your key strokes with the commands. I use it frequently to access my cleartool commands.

after editing a file using vi. You can check the difference with the predecessor or the version tree for the file using key-strokes Alt-d or Alt-t

bind -x '"\M-d"':'cleartool diff -pred -g -options "-b" $_ &'
bind -x '"\M-t"':'cleartool lsvtree -g $_ &'

Thursday, February 07, 2008

Handy RPM commands

# Unpackage an ISO file.
rpm2cpio <> | cpio -idmv

# Extracting the scripts from the rpm
rpm -qp --scripts <> >> /tmp/scripts

# Command to find if any of the files delivered by an RPM has changed.
rpm --verify











wdl

GNU working directory list is an open source utlity to easily move between the working directories. You can even set CDPATH to move effectively between the directores. But take care setting CDPATH can also cause make command to fail, if you have a top-level make file which cd into sub-dirs and does a make.

Friday, December 28, 2007

Screen Command

Unix Screen command is an indespensable command. Once you know it you cannot live without it. It is window manager. Just try it and you will find it mind blowing.

A new screen can be created using
screen.

Ctrl-A c - Create new window
Ctrl-A A - Name a window
Ctrl-A " - Show all windows.

Ctrl-A S split window.
Ctrl-A tab to move to the next window.

Putty Title

Putty Title can be easily modified using the function wt.

wt ()
{
echo -n "^[]2;${@}^G"
# In all of these, ^[ is really the "escape" character.
# You put it into a file using vi, by typing control-V and then hitting the Escape key.
# Likewise, ^G is the control-G# character. Again, hit control-V
# then hit control-G
}

The link 'http://www.unix.com/unix-dummies-questions-answers/35518-name-path.html'