Geek Lair

Effective Computer Usage

leave a comment »

These are some of the things which I do to speed up the work I do with computers.

Learn Shortcuts

Shortcuts can be your biggest time saver. Instead of dragging the mouse to a menu, selecting an option which opens another window and then finally choosing an action, if that action has a shortcut associated with it, you can do it much faster with the keyboard. Well designed applications provide shortcuts as a way to “power use” them. The GUI serves a new user, but seasoned users can use shortcuts to speed up the way they use the application.

Spend some time learning the shortcuts of applications you use regularly. It is not easy, but it pays back splendidly. You will look like a rock star riffing on his guitar, if you master keyboard shortcuts.

Screen Real Estate

If you are working on a physical desk, do you keep only what you are using at the moment (say a book)? Or do you keep other items on it so that you can switch between using them without much effort?

Your computer display also works the same way as a physical desk (does the term desktop sound familiar?). If your screen resolution allows multiple windows to be viewed at the same time without sacrificing functionality, use it. Don’t maximize windows and keep switching between them.

A good example is your browser. Most websites today are designed for 1024×768 resolution. If you display has a resolution larger than that, why maximize the browser and eat up valuable screen real estate, when you can keep your browser at 1024×768 and use the remaining space for your IM or email client? That way you can keep an eye on who is online and the emails you get while browsing. No need to waste time with switching between windows.

Also, if you are a heavy mouse user, not maximizing windows offers huge time savings. Other windows can be positioned so that some part is always visible and to switch to another window, you just need to click on the visible portion of that window instead of searching for it in the taskbar.

Always Customize

Most applications can be configured to do things faster, but present a simple but inefficient interface by default so as to not scare new users. Once you get comfortable using an application, see if you can do things faster by customizing it.

For example, in some corporate environments ,Windows XP is configured to use Windows 98 style Start menu instead of the new one which shows the most frequently used applications. You can also add application shortcuts to the new Start menu. Using the old one to select a frequently used application will take at least 3 clicks, whereas in the new Start menu it can require only 2 clicks.

If you are going to frequently launch an application, put it somewhere easily accessible instead of hunting through menus to open it. Define a keyboard shortcut if your OS allows it.

Written by anonir

January 8, 2010 at 23:34

Posted in General Tech

Tagged with ,

Extracting a substring from a starting point using awk

leave a comment »

If you have a string like this (this is how versions look in Clearcase):

/root_path/stream/version_name/78

and want to extract the string 78 (i.e, the version no.), you can do it this way:

echo "/root_path/stream/version_name/78" | awk '{where = match($0,"\/[^\/]*$"); print substr($0,where+1)}'

We get the position of the last occurrence of “/” and use substr to extract the string after that position till end of string.

Written by anonir

December 29, 2009 at 19:07

Posted in Linux

Tagged with

Bash script to compile and run a C program in one step

with 3 comments

Here is a simple script to compile and run a C program:

#!/bin/bash
# Script to compile and execute a c program in one step.

# Get file name without the .c extension
file_name=$(echo $1|sed 's/\(.*\)\.c/\1/')

# Compile the program with -o option to specify the name of the binary
gcc -o $file_name.out $1

# If there were no compilation errors, run the program
if [[ $? -eq 0 ]]; then
        ./$file_name.out
fi

The same could be done for C++ programs as well. Just replace the .c in the sed expression with .cpp and replace gcc with g++

Written by anonir

October 26, 2009 at 18:21

Posted in bash, Linux

Customizing vim

leave a comment »

You can set additional options in vim to make your programming life easier. You can add these options to .vimrc in your home folder so that they are loaded every time you start vim.

vim ~/.vimrc

set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
syntax on
colo murphy

To know what each option does,  just type:

:help <option>

For example to know about autoindent, type:

:help autoindent

gvim

By default, gvim uses courier font. To set your own font, create a file .gvimrc in your home and add set guifont option:

vim ~/.gvimrc

set guifont=Bitstream\ Vera\ Sans\ Mono\ 9

Another useful option is to set the window size:

set lines=100 columns=130

Note that gvim reads options from .vimrc as well. But vim will not read options from .gvimrc

Other resources of interest

Written by anonir

October 26, 2009 at 18:04

Posted in Linux

Tagged with ,

bash and cron

leave a comment »

Setting up cron in Ubuntu is simple enough as described in the Ubuntu wiki. But what they don’t mention is that by default cron uses /bin/sh for its SHELL env variable. That may cause a problem if you try to set up a bash script in cron. To prevent that from happening, you need to define the SHELL variable for your user crontab to point to /bin/bash.

In the console type:

crontab -e

Add the following line at the top:

SHELL=/bin/bash

Your crontab should look something like this:

SHELL=/bin/bash
# m h  dom mon dow   command
*/5 * * * * /usr/local/bin/my_bash_script

Written by anonir

October 13, 2009 at 15:45

Posted in bash, Linux, Ubuntu

Tagged with ,

Productive Firefox

leave a comment »

Firefox has redefined the web experience. It dragged the web out from the clutches of the mundane and boring IE6. Apart from the features which are immediately obvious, Firefox has hidden treasures which can further improve the browsing experience

Ctrl + K

I’ve seen people who wanted to do a Google search open a new tab, type in google.com in the address bar and then enter their search term or drag their mouse pointer all the way the search box next to the address bar. There is a much faster way to accomplish the same. Just open a new tab (Ctrl + T), then press Ctrl + K and you are in the search bar!

Bonus tip: Press Ctrl + Down/Up arrow to switch between different search engines.

I’m Feeling Lucky

Google search has this feature where it will show the most popular website for a given search expression. Using Firefox you can do it right from your address bar. Say you remember a popular website for lolcats but cannot remember its address. You can type in lol cat in the address bar and voila! Firefox shows you the page that started the silly phenomenon:

Screenshot-Shiretoko

lol cat

Of course you could as well load google.com and do a search there. But that is too way too slow compared to:  go to the address bar (Ctrl + L), and just type in the search term. Time is precious. We can’t waste it can we? But a caveat here. This works fast only for search terms which involve at least two words. If you type in a single word, Firefox will attempt to do a DNS lookup for it and when there is no match for that word, only then will Firefox route the word to Google’s I’m Feeling Lucky search.

My preciouss mouse!

Here’s something for you mouse lovers. To open a link in a new background tab, you can hover over it and press the middle click of your mouse (now a days that is mostly the scroll wheel ). This way is faster than doing a right click on the link and selecting “Open Link in New Tab” option. Another way to accomplish the same is to hold the Ctrl key and do a left click with the mouse.

Skating through tabs

To cycle through tabs from left to right use Ctrl+Tab. To do it in the opposite direction, use Ctrl+Shift+Tab. To switch to the tab right of the current tab use Ctrl+Page Down and for the tab to the left, use Ctrl+Page Up.

A cleaner web

Ever since the web came out of a “fancy geek fad” status to a “essential communication medium”, website owners smelled money. A lot of it. As result we see web pages are ad soups with a bit of content thrown in and in some cases even the teeny bit of content is spread across multiple pages. Not only do ads add clutter to a web page, they also waste bandwidth. Enter Adblock Plus, an add on which blocks ads. Install it and enjoy a better web.

Written by anonir

September 10, 2009 at 13:21

Posted in Web

Tagged with

Zebra striping tables with JSTL and CSS

with 6 comments

Zebra striping is giving adjacent rows in a table different colors and alternate rows the same color:

Zebra Striped Table

Zebra Striped Table

One way to do it is using JavaScript and CSS. There are a lot of articles describing how to do so. This method has one disadvantage – if the user disables JavaScript in the browser, the table will not be striped. The only way is to hard code the style for each row. This is easily done using JSTL.

If we have a list of objects of type Person, then we can iterate over them using the JSTL <c:forEach> action and render a row for each item. Even and odd rows can be determined from the loop counter:

<table>
    <thead>
	<tr>
	    <td>Sno</td>
	    <td>First Name</td>
	    <td>Last Name</td>
	    <td>Age</td>
	    <td>Gender</td>
	</tr>
    </thead>

    <tbody>
	<c:forEach var="person" items="${persons}" varStatus="i">
	    <c:choose>
		<c:when test="${(i.count) % 2 == 0}">
		    <tr class="even">
		</c:when>
		<c:otherwise>
		    <tr class="odd">
		    </c:otherwise>
		</c:choose>
		<td>${i.count}</td>
		<td>${person.firstName}</td>
		<td>${person.lastName}</td>
		<td>${person.age}</td>
		<td>${person.gender}</td>
	    </tr>
	</c:forEach>
    </tbody>
</table>

 
Even rows will have the style “even” and odd rows “odd”. Here are the CSS styles I used:

<style type="text/css">
    table {
	border-collapse: collapse;
	text-align: center;
    }
    td {
	border: 1px solid #000;
    }
    thead {
	background-color: #000;
	color: #fff;
	font-weight: bold;
    }
    thead td {
	padding: 0 .5em;
    }
    .odd {
	background-color: #E6E6E6;
    }
    .even {
	background-color: #fff;
    }
</style>

Written by anonir

December 16, 2008 at 20:07

Posted in JEE, Web

Tagged with ,