.comment-link {margin-left:.6em;}

Vivek Kutal's Blog

Tuesday, October 24, 2006

Bash Tips

Here are some tips for customizing bash

1. Directory shortcuts

You can assign shortcuts to the directories u frequently use.

just add the following in your .bashrc

function l
{
command cd /opt/development/linux-2.6.18
}
export l

now l is a new shortcut to the linux-2.6.18 directory , just type l and enter to go there.

add more functions like this to create shortcuts to dirs u frequently use.

2. New Command names

most of the time we use commands like
ps ax | grep xyz or cat abc | grep xyz
now instead for typing this every time u can give them new names

function pgrep
{
command ps ax | grep "$@"
}
export pgrep

and

function catg
{
command cat "$1" | grep "$2"
}
export catg

"$@" inserts the arguments passed .
"$1" , "$2" are ur 1st and 2nd arguments

now u can use "pgrep xyz" instead of typing "grep ax | grep xyz"

here are some of the commands that I use

sudo apt-get install --> ainstall
sudo apt-get remove --> aremove
.
.
all apt-get commands

make menucnfig --> mmc
make distclean --> mdc
.
.
all frequently used make commands

grep -rin "$@" * --> cgrep
find . -name "$@" --> nfind

and all frequently edited files and frequently used ssh and scp commands.

(here is a link on howto use ssh and scp without passwords)


3. Usefull shortcuts

ctrl + l --> Clear Screen
ctrl + w --> Delete last word
ctrl + c --> Cancel the command you are typing
alt + u --> Make the word uppercase
ctrl + r --> Search History
ctrl + d --> Exit the Shell

Monday, March 27, 2006

Likely / Unlikely Macros in the Linux kernel

In 2.6 we many times see something like this

if (unlikely(pmd_bad(*pmd))) {
pmd_ERROR(*pmd);
pmd_clear(pmd);
return;
}

and these macros are defined in compiler.h as

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

I just found a nice article explaining this in detail , this is the link .

Monday, March 13, 2006

do {......} while(0)

A few days ago a came across a macro in the linux kernel code
#define MACRONAME do {Some code} while (0)
now I was wondering what is the use of having while(0)
here's the explaination for it, by Ben Collins , on kernelnewbies

  • It allows you to use more complex macros in conditional code. Imagine a macro of several lines of code like:
    #define FOO(x)  printf("arg is %s\n", x); do_something_useful(x);
  • Now imagine using it like:
            if (blah == 2)
    FOO(blah);

    This interprets to:
            if (blah == 2)
    printf("arg is %s\n", blah);
    do_something_useful(blah);;
    As you can see, the if then only encompasses the printf(), and the do_something_useful() call is unconditional (not within the scope of the if), like you wanted it. So, by using a block like do{...}while(0), you would get this:
            if (blah == 2)
    do {
    printf("arg is %s\n", blah);
    do_something_useful(blah);
    } while (0);
    Which is exactly what you want.
  • (from Per Persson) As Collins point out, you want a block statement so you can have several lines of code and declare local variables. But then the natural thing would be to just use for example:
      #define exch(x,y) { int tmp; tmp=x; x=y; y=tmp; }
    However that wouldn't work in some cases. The following code is meant to be an if-statement with two branches:
      if(x>y)
    exch(x,y); // Branch 1
    else
    do_something(); // Branch 2
    But it would be interpreted as an if-statement with only one branch:
      if(x>y) {          // Single-branch if-statement!!!
    int tmp; // The one and only branch consists
    tmp = x; // of the block.
    x = y;
    y = tmp;
    }
    ; // empty statement
    else // ERROR!!! "parse error before else"
    do_something();
    The problem is the semi-colon (;) coming directly after the block.

    The solution for this is to sandwich the block between do and while(0). Then we have a single statement with the capabilities of a block, but not considered as being a block statement by the compiler.

    Our if-statement now becomes:
      if(x>y)
    do {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
    } while(0);
    else
    do_something();

Sunday, March 05, 2006

List of commands to run from the run prompt in XP

Accessibility Controls
access.cpl

Add Hardware Wizard
hdwwiz.cpl

Add/Remove Programs
appwiz.cpl

Administrative Tools
control admintools

Automatic Updates
wuaucpl.cpl

Bluetooth Transfer Wizard
fsquirt

Calculator
calc


Check Disk Utility
chkdsk

Command Prompt
cmd


Computer Management
compmgmt.msc

Date and Time Properties
timedate.cpl


Device Manager
devmgmt.msc

Direct X Control Panel (If Installed)*
directx.cpl

Direct X Troubleshooter
dxdiag

Disk Cleanup Utility
cleanmgr

Disk Defragment
dfrg.msc

Disk Management
diskmgmt.msc

Disk Partition Manager
diskpart

Display Properties
control desktop

Display Properties
desk.cpl

Display Properties (w/Appearance Tab Preselected)
control color


Fonts
control fonts

Fonts Folder
fonts


Hearts Card Game
mshearts

Iexpress Wizard
iexpress


Internet Properties
inetcpl.cpl


IP Configuration (Display Connection Configuration)
ipconfig /all



java Control Panel (If Installed)
jpicpl32.cpl

Java Control Panel (If Installed)
javaws

Keyboard Properties
control keyboard

Local Security Settings
secpol.msc

Local Users and Groups
lusrmgr.msc

Logs You Out Of Windows
logoff

Microsoft Chat
winchat

Minesweeper Game
winmine

Mouse Properties
control mouse

Mouse Properties
main.cpl


Network Connections
ncpa.cpl

Network Setup Wizard
netsetup.cpl

Notepad
notepad

On Screen Keyboard
osk


Password Properties
password.cpl

Performance Monitor
perfmon.msc


Phone and Modem Options
telephon.cpl

Power Configuration
powercfg.cpl

Printers and Faxes
control printers

Printers Folder
printers


Quicktime (If Installed)
QuickTime.cpl

Regional Settings
intl.cpl

Registry Editor
regedit

Registry Editor
regedit32

Remote Desktop
mstsc

Removable Storage
ntmsmgr.msc

Removable Storage Operator Requests
ntmsoprq.msc


Scanners and Cameras
sticpl.cpl

Scheduled Tasks
control schedtasks

Security Center
wscui.cpl

Services
services.msc

Shared Folders
fsmgmt.msc

Shuts Down Windows
shutdown

Sounds and Audio
mmsys.cpl

Spider Solitare Card Game
spider

System Configuration Editor
sysedit

System Configuration Utility
msconfig

System File Checker Utility (Scan Immediately)
sfc /scannow

Task Manager
taskmgr

Telnet Client
telnet

User Account Management
nusrmgr.cpl

Utility Manager
utilman

Windows Firewall
firewall.cpl

Windows Magnifier
magnify


Windows Update Launches
wupdmgr

Wordpad
write


Taken from here

Thursday, February 02, 2006

Downloading Google Videos

We cannot view google videos in India but now we can downlaod them and that too in a avi fromat.
You can download it from here , just need to paste the link of the video.

Actually we can view the videos in India but there a long procedure for it and if you can download it why would anyone want to see it online :-).

Friday, December 30, 2005

Pune On Google Earth

Pune can now be seen on google earth.
Here are some pics that I have uploaded on Flickr

Bundgarden Bridge
http://www.flickr.com/photos/techvivek/75280867

Shanivarwada
http://www.flickr.com/photos/techvivek/75294186

Sanchati Bridge
http://www.flickr.com/photos/techvivek/75293669

Nehru Stadium
http://www.flickr.com/photos/techvivek/75294042

Central Jail
http://www.flickr.com/photos/techvivek/75302458
http://www.flickr.com/photos/techvivek/75300936

Golf Course
http://www.flickr.com/photos/techvivek/75293207

Esquare
http://www.flickr.com/photos/techvivek/75289068

Vishrantwadi
http://www.flickr.com/photos/techvivek/75300544

J.N.Petet High school (My School)
http://www.flickr.com/photos/techvivek/75301246

Sunday, December 25, 2005

A search engine that identifies songs for you

Tutanic is a new search engine which identifies songs for you (Name and the Artist) .
You just need to play the song in your Microphone and it identifies it in seconds , offcourse if it is present in its database but worked for most of the songs that I tested.



Click here to Download It (530 KB)