Do you program in vim? Have you heard of exuberant ctags? No, then download it to your machine immediately, if ctags is not already in your system http://ctags.sourceforge.net/
Trust me - this simple program can save hours of frustration.
If you have a directory called source and the directory and its subdirectories contain source code - type "ctags -R" . This creates a listing of which functions are in which files. Thus if you are editing a file, and find a function which is defined in another, all what you have to do is "Ctrl - ]" to jump to its definition. "Ctrl -T" will take you back. Now, if the definition is in the same file, then you might as well just type "gD"within vim to go to it. (This is a vim capability).
Some more useful stuff with vim and Ctags:
vim -t tag Start vim and position the cursor at the file and line where "tag" is defined.
:ta tag - Find a tag.
Ctrl-] - Find the tag under the cursor.
Ctrl-T - Return to previous location before jump to tag (not widely implemented).
Monday, July 24, 2006
Thursday, July 20, 2006
Finding indices of multidimensional arrays in python
Python is great for a lot of things. Unfortunately, there is no easy direct way to find indices of multidimensional arrays.
Example - You have a list(or array) A[5][5]. It is represented as [ [1,1,1,1,1], [2,34,23,1,4]....[1,34,54,44.1]] in python.
If you want to find the minimum in the list and find indices of the list, you have to proceed as follows:
mintest = 100000 # Some large number
# Instead of '4' in the below for loop, you can use the length attribute of the array.
for iter in range(0,4):
min1 = min(A[iter])
if (mintest > min1):
row_index = citer
col_index = A[iter][:].index(min(A[iter]))
mintest = min1
print "Row, column indices of the minimum value %d in the array are %d,%d" % (mintest, row_index, col_index)
Example - You have a list(or array) A[5][5]. It is represented as [ [1,1,1,1,1], [2,34,23,1,4]....[1,34,54,44.1]] in python.
If you want to find the minimum in the list and find indices of the list, you have to proceed as follows:
mintest = 100000 # Some large number
# Instead of '4' in the below for loop, you can use the length attribute of the array.
for iter in range(0,4):
min1 = min(A[iter])
if (mintest > min1):
row_index = citer
col_index = A[iter][:].index(min(A[iter]))
mintest = min1
print "Row, column indices of the minimum value %d in the array are %d,%d" % (mintest, row_index, col_index)
Tuesday, July 18, 2006
Execute the "touch" command recursively
If you want to update the access time of a set of files, you can use
touch *
However, if you want to touch files and directories recursively, the touch command does not have a built in option. Instead use this command to achieve the same result:
If XXX is the dir within which you want to touch recursively, execute the foll. (Give the full path to XXX as needed)
find XXX | xargs touch
touch *
However, if you want to touch files and directories recursively, the touch command does not have a built in option. Instead use this command to achieve the same result:
If XXX is the dir within which you want to touch recursively, execute the foll. (Give the full path to XXX as needed)
find XXX | xargs touch
Sunday, July 16, 2006
Search as you go in vim
If you want to search for television, and you want the words to be highlighted as you type in "television" , the following command will help you
:set incsearch
Add the following line to your .vimrc or .gvimrc file and you are all set every time you vim!
set incsearch
:set incsearch
Add the following line to your .vimrc or .gvimrc file and you are all set every time you vim!
set incsearch
Friday, July 14, 2006
Grammar checker for latex
Love latex but miss word's grammar checking facility?
There is one (albeit simple) option - Queequeg, A Tiny English Grammar Checker (http://queequeg.sourceforge.net/index-e.html)
Follow the installation instructions given in their website.
In their steps they say "make dict WORDNET=/src/wordnet/dict".
For whatever reason this does not work if you want another directory. Just open the Makefile and set the directory you want WORDNET to point.
There is one (albeit simple) option - Queequeg, A Tiny English Grammar Checker (http://queequeg.sourceforge.net/index-e.html)
Follow the installation instructions given in their website.
In their steps they say "make dict WORDNET=/src/wordnet/dict".
For whatever reason this does not work if you want another directory. Just open the Makefile and set the directory you want WORDNET to point.
How to get a syntax usb-400 wireless card to work with any linux distro
You bought the cheapo wireless card. It works well enought with windows, but in *nix, there is a problem. You have scourged various websites with specifics for varioux linux distros, saw something about hotplug, yada, yada yada...nothing works.
The foll. will get you through in MOST linux distros (have tried it on simplymepis, ubuntu, redhat 9.0)
Obtain the linux-wlan driver for your card (http://www.linux-wlan.org/) and install it. However, you need to install the kernel headers (no, this is not recompiling the kernel) before installing linux-wlan.
In debian distros, it is as simple as knowing your kernel (uname -a should give you that), followed by an apt-get install kernel-header.... (choose the right header corresponding to uname -a)
Now, tar unzip, your linux-wlan drivers file, do a configure (and pray to God you have everything required in your system) , a make (while selling Satan your soul for being able to build) , and finally a make install. Do all this as root to make your life easier.
Good, it builds! What next?
First, in your router, turn off encryption (Disable WEP and make auth type to be "open system" - believe me this is needed as a first step. Will save you hassle.)
Create a small script called wlan_script_basic.sh in your home directory consisting of the following lines:
sudo rmmod prism2_usb
sudo modprobe prism2_usb prism2_doreset
sudo wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
sudo wlanctl-ng wlan0 lnxreq_autojoin ssid="XXX" authtype=opensystem
sudo dhclient wlan0
XXX = name of your access point/router
(Pray that you will donate all your hair while your wlan0 acquires a lease)
Great! internet works.
Now, to set up WEP.
Enable WEP in your router, set a key (I am assuming it is 12345678, a 64-bit hex key), and select shared key as your system.
Now, write a new script containing the following:
sudo rmmod prism2_usb
sudo modprobe prism2_usb prism2_doreset
sudo wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
sudo wlanctl-ng wlan0 lnxreq_hostwep decrypt=true encrypt=true
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11PrivacyInvoked=true
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey0=""
sudo wlanctl-ng wlan0 lnxreq_autojoin ssid="XXX" authtype=sharedkey
sudo dhclient wlan0
Did it work?
Yes? Great, you are all set!
No? Spend 15 bux and get a wireless card that works with your distro. It will save you countless hours of hacking.
The foll. will get you through in MOST linux distros (have tried it on simplymepis, ubuntu, redhat 9.0)
Obtain the linux-wlan driver for your card (http://www.linux-wlan.org/) and install it. However, you need to install the kernel headers (no, this is not recompiling the kernel) before installing linux-wlan.
In debian distros, it is as simple as knowing your kernel (uname -a should give you that), followed by an apt-get install kernel-header.... (choose the right header corresponding to uname -a)
Now, tar unzip, your linux-wlan drivers file, do a configure (and pray to God you have everything required in your system) , a make (while selling Satan your soul for being able to build) , and finally a make install. Do all this as root to make your life easier.
Good, it builds! What next?
First, in your router, turn off encryption (Disable WEP and make auth type to be "open system" - believe me this is needed as a first step. Will save you hassle.)
Create a small script called wlan_script_basic.sh in your home directory consisting of the following lines:
sudo rmmod prism2_usb
sudo modprobe prism2_usb prism2_doreset
sudo wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
sudo wlanctl-ng wlan0 lnxreq_autojoin ssid="XXX" authtype=opensystem
sudo dhclient wlan0
XXX = name of your access point/router
(Pray that you will donate all your hair while your wlan0 acquires a lease)
Great! internet works.
Now, to set up WEP.
Enable WEP in your router, set a key (I am assuming it is 12345678, a 64-bit hex key), and select shared key as your system.
Now, write a new script containing the following:
sudo rmmod prism2_usb
sudo modprobe prism2_usb prism2_doreset
sudo wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
sudo wlanctl-ng wlan0 lnxreq_hostwep decrypt=true encrypt=true
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11PrivacyInvoked=true
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
sudo wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey0="
sudo wlanctl-ng wlan0 lnxreq_autojoin ssid="XXX" authtype=sharedkey
sudo dhclient wlan0
Did it work?
Yes? Great, you are all set!
No? Spend 15 bux and get a wireless card that works with your distro. It will save you countless hours of hacking.
Thursday, July 13, 2006
Delete lines matching a pattern in vim
I have only recently started using the powerful :g
Syntax :[range]:g//[cmd]
Some examples of its usage:
Delete all lines matching a pattern
:g//d
Delete all blank lines
:g/^\s*$/d
I also found this tip in the vim website, which contains a lot more examples:
http://www.vim.org/tips/tip.php?tip_id=227
Syntax :[range]:g/
Some examples of its usage:
Delete all lines matching a pattern
:g/
Delete all blank lines
:g/^\s*$/d
I also found this tip in the vim website, which contains a lot more examples:
http://www.vim.org/tips/tip.php?tip_id=227
Search and replace part of an expression in gvim
Assume that you want to add a double asterisk (**) to every line in a document.
e.g. you want to replace
hello, this is a line
this is another line
this is a third line
with
hello, this is a line**
this is another line**
this is a third line**
There are many ways to doing this, but one of the more general ways of doing this with regular expressions (which can be easily extended for other tasks) is
:%s/\(^.*\)/\1**
An extension: What if you want to introduce a line break before the word line?
Use \r
:%s/\(^.*\) \(line\*\*\)/\1\r\2/g should do it for you
As you notice \1 contains the match within the first parentheses. If there were multiple parentheses, the contents can be accessed using \1, \2 etc.
e.g. you want to replace
hello, this is a line
this is another line
this is a third line
with
hello, this is a line**
this is another line**
this is a third line**
There are many ways to doing this, but one of the more general ways of doing this with regular expressions (which can be easily extended for other tasks) is
:%s/\(^.*\)/\1**
An extension: What if you want to introduce a line break before the word line?
Use \r
:%s/\(^.*\) \(line\*\*\)/\1\r\2/g should do it for you
As you notice \1 contains the match within the first parentheses. If there were multiple parentheses, the contents can be accessed using \1, \2 etc.
Wednesday, July 12, 2006
Floating point division in python
Add the following line to your python 2.4 code, if you want to do FP division. Otherwise, python will only do integer division!
from __future__ import division # Otherwise python will not do FP division
from __future__ import division # Otherwise python will not do FP division
Tuesday, July 11, 2006
Latex tip - to make pages look nicer
Don't you hate it when you get a doc with 5.5 pages?
When you want to force material over to the next page, e.g., when you want to balance the last page by moving references, you can use \vfill\eject between references to move more over to column two and produce a more balanced last page. (This command is great for forcing material over to the next page.)
When you want to force material over to the next page, e.g., when you want to balance the last page by moving references, you can use \vfill\eject between references to move more over to column two and produce a more balanced last page. (This command is great for forcing material over to the next page.)
Cool gvim trick for marking
You know how you edit some code at line 10, then move to line 30, and forget where you were originally (line 10)? There is a gvim command for taking care of this. You can use markers. In line 10, you can (in command mode) type ma to mark the position with identifier 'a', and now after editing line 30, you can type 'a to move back to line 10 (marker a). Markers are also useful for deleting lines between two markers and so on.
But, it so happens if you create too many markers, you will forget that marker 'a' is actually line 10. More problems!
The solution - Ctrl-i and Ctrl-o can be used in gvim to move around the last places you edited. Thus, saving you from marking everyplace you edited.
Of course markers are still needed, when you want to delete lines between two markers, or search and replace between them.
e.g.
d'a - delete from current position to mark a
:'a,'b d -delete all lines between markers a and b
:'a,'b s/ef/cd -you know what this means
But, it so happens if you create too many markers, you will forget that marker 'a' is actually line 10. More problems!
The solution - Ctrl-i and Ctrl-o can be used in gvim to move around the last places you edited. Thus, saving you from marking everyplace you edited.
Of course markers are still needed, when you want to delete lines between two markers, or search and replace between them.
e.g.
d'a - delete from current position to mark a
:'a,'b d -delete all lines between markers a and b
:'a,'b s/ef/cd -you know what this means
The ~ symbol in latex
The ~ symbol. I thought, it was the trick for adding spaces within math expressions
i.e. for anything enclosed in $.
e.g.
$a = a + b$ --> a=a+b
$a~=~a~+~b$ --> a = a + b
But, actually what it does it ties the symbols together. So, for example if you give Figure~\ref{fig:world}, what it ensures is the terms Figure and the reference number remain always on the same line. Thus it will always be printed as
"Figure X"
"and not as Figure
X"
But, if you just used a hard space between Figure and \ref, the latter might just happen!
i.e. for anything enclosed in $.
e.g.
$a = a + b$ --> a=a+b
$a~=~a~+~b$ --> a = a + b
But, actually what it does it ties the symbols together. So, for example if you give Figure~\ref{fig:world}, what it ensures is the terms Figure and the reference number remain always on the same line. Thus it will always be printed as
"Figure X"
"and not as Figure
X"
But, if you just used a hard space between Figure and \ref, the latter might just happen!
Subscribe to:
Posts (Atom)