I killed some time figuring this out myself though the solution was there on the first link given out by google..
thanx to the guy who posted this one..
list is a listview here...
while (list.SelectedItems.Count > 0)
{
list.Items.Remove(list.SelectedItems[0]);
}
vaibhav
Saturday, December 13, 2008
Remove selected items from listview in C#
Posted by
vaibhav
at
4:20 PM
0
comments
Monday, December 8, 2008
How to find file system disk space in linux
My linux VM started showing me that it ran outof space... So I tried to figure out what is the space left over... so I found this on the man page of df command...
df - report file system disk space usage
Show information about the file system on which each FILE resides, or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si
likewise, but use powers of 1000 not 1024
-i, --inodes
list inode information instead of block usage
-k like --block-size=1K
-l, --local
limit listing to local file systems
--no-sync
do not invoke sync before getting usage info (default)
-P, --portability
use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE
limit listing to file systems of type TYPE
-T, --print-type
print file system type
-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version
output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following: kB 1000, K 1024, MB
1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
n thats what my VM gave me :)
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 3945128 3945112 0 100% /
none 385124 0 385124 0% /dev/shm
//14.4.2.55/CodePart
117218300 58824100 58394200 51% /mnt/myshare
vaibhav
Posted by
vaibhav
at
12:17 PM
0
comments
Friday, October 3, 2008
export not working in shell script - solution
Another small problem and another nice thing learnt :o)
I was trying to make a shell script that exports all my environment variables as I was tired exporting them manually each time I connected to my lab machine from my computer. I wrote the script and tried running. to my surprise it was printing the echo statements but not exporting the variable. After searching for 5 minutes on the web I found that when we try exporting some variables it runs in a private shell. This make the changes not visible in the current shell.
I found this on a linux forum and found it interesting:
The program that you use to access the shell is called a terminal emulator. Examples are Konsole, Gnome Terminal, xterm, Eterm, aterm, etc. When you open one of these, the program also creates a subshell. The shell that you enter commands into is different from the one running your X server, though it has inherited all the attributes of the main shell.
When you run a script in a shell, that script runs in a subshell that works very similarly. A script runs in its own environment, and does not affect the parent at all. When the "source" command is used, changes to the subshell are duplicated in the parent shell
http://www.linuxforums.org/forum/linux-newbie/55168-export-doesnt-work-shell-script.html
so the solution:
simple ... run your shell script with the following command
test_script.sh=>
#!/bin/sh
export MY_TRACE_FILE=/root/mytrace.trc;
and then do a
. ./test_script.sh
or
source ./test_script.sh
I tried the second one and it worked just fine :)
Posted by
vaibhav
at
10:53 AM
2
comments
Wednesday, October 1, 2008
Code for Random Number Generator
This is something I always thought of doing but it was always a priority 2 task for me. Today when I was in a fix of keying in make and make install each time I had to run my test I finally replaced the libuuid patch with a simple 3 line code of this random number generator function.
int temp_id=0;
void myRandomNumber()
{
unsigned int myseed;
myseed = (unsigned)time(NULL);
srand(myseed); // Initialize the random number generator
temp_id = rand(); // Random number
}
Reference:
http://www.randombots.com/random_control.htm
Vaibhav
Posted by
vaibhav
at
3:29 PM
0
comments
Tuesday, August 26, 2008
How to unzip a RPM file and a bz2 file on unix/linux
You may use
1. Unzip RPM file
$ rpm2cpio myrpmfile.rpm | cpio -idmv
for detailed explaination look at
http://www.cyberciti.biz/tips/how-to-extract-an-rpm-package-without-installing-it.html
2. for a bz2 file
$ bunzip2 filename.txt.bz2
To compress a file using bzip2, execute the following command:
$ bzip2 filename.txt
for more details you may visit
http://www.debianadmin.com/create-and-extract-bz2-and-gz-files.html
cheers
Vaibhav
Posted by
vaibhav
at
3:50 PM
0
comments
Zipping and Unzipping Files in UNIX
taken from http://www.hostingmanual.net/other/zip.shtml
There are several methods of archiving files and retrieving archives. We recommend using the "zip" function to compress your files for its ease of use and portability. (Files zipped in Unix can be extracted using WinZip or PKunzip in Windows). We have provided various "unzip" methods. The "right" unzip method depends upon the method used to zip the file. You can tell the zip method by the file extension (e.g., .zip, .tar, .gz, etc.)
Zipping Files Using ZIP
This Unix program is compatible with the zip program for DOS and Windows. To zip files, first have the files uploaded to your server, then log into your account with Telnet. Navigate to the directory where the files are that you want to zip (for instance by typing cd www then cd sounds to move to your /www/sounds directory). Then type:
zip myzip file1 file2 file3
This puts the files named file1, file2, and file3 into a new zip archive called myzip.zip.
Unzipping Files
Please note that the unzip method you use is defined by the filename you are trying to unzip. For example, if you are trying to unzip a file called file.tar - you would use the method described in "tar". Files ending in .gzip or .gz need to be extracted with the method described in "gunzip".
Zip
If you have an archive named myzip.zip and want to get back the files, you would type:
unzip myzip.zip
Typing zip
or unzip
by itself will give you a usage summary, showing nearly all the options available.
Tar
To extract a file compressed with tar (e.g., filename.tar), type the following command from your telnet prompt:
tar xvf filename.tar
Basically, this command means that you will see the file "explode", so don't worry when you see your screen scrolling wildly. It also means that you will see any errors in the archive.
Gunzip
To extract a file compressed with gunzip, type the following:
gunzip filename_tar.gz
then if you receive no errors, type:
tar xvf filename_tar
Posted by
vaibhav
at
10:21 AM
0
comments
Monday, August 18, 2008
adding a persistent route to windows server 2003
You may use the following command on your cmd prompt to add a persistent route to windows server 2003.
C:\Route add -p network [network address] mask [subnet mask] [gateway] metric [value]
for help on this command type
C:\ route ADD
to print all added routes type in
C:\route print
hope it helps.
vaibhav chugh
Posted by
vaibhav
at
10:55 AM
0
comments