To be or not to be

May 30, 2008

How to convert lower-case to upper-case in C++ ?

Filed under: How To — Tags: , , , , — tdas @ 1:06 pm

Standard C library does not provide any built-in function to convert lower case to upper case and vice versa.
C++ STL has an elegant and simple solution for this : transform function.

Note : include the algorithm header file in your C++ file.

To convert Upper Case -> Lower Case:
transform( upperLine.begin(),upperLine.end(), upperLine.begin(),(int(*)(int)) tolower );

To convert Lower Case -> UpperCase:
transform( lowerLine.begin(),lowerLine.end(), lowerLine.begin(),(int(*)(int)) toupper );

Cheers

May 26, 2008

How to use the OR operator in Grep?

Filed under: How To, Shell Script — Tags: , , — tdas @ 12:44 pm

Ever wondered how to search for multiple patterns in one grep statement? One problem I often come across is, while using grep, if I want to search for something like “find all matches that start with a $ or with #“, I am stuck.

Well apparently using the OR operator in grep is trivial.

grep “^$\|^#” foo.dat ( this will return all matches that start with a $ or with # )

Note: Do NOT forget the backslash \ before the |.

Hope that will help someone :)

May 21, 2008

How to tar and untar files in UNIX?

Filed under: How To, Shell Script — Tags: , , , , , — tdas @ 3:14 am

Few years ago, during my undergraduate degree, I was asked to compress my assignment using tar and submit it. I was so scared with all the tar+compress+unix jig, that I ended up NOT submitting the assignment :O. Now when I look back, I feel so stupid. Anyways, now that I know a lil bit more about tar and untar, I’d like to share my knowledge with everyone and hopefully help someone from NOT submitting an assignment :P

Basically tar can be used to group multiple files/directories into one single file, and separate(extract) an archive created by tar into separate files.

* To group multiple files : tar -cvf foo.tar a.dat b.dat c.dat ( this will group files [a-c]*.dat to one file foo.tar )
c = create a tar file
v = verbose( nothing important :P )
f = create the tar file with filename provided as the argument

Thats all you need to know to tar(group) a bunch of files/directories.

* To tar files and gzip them : tar -czf foo.tar.gz *.dat ( this will create a gzip-compressed Tar file of the name foo.tar.gz of all files with a .dat suffix in that directory )

* To untar(separate) files from a tar archive : tar -xvf foo.tar ( this will produce three separate files a.dat, b.dat and c.dat )

* To untar(extract) a gzipped tar archive file : tar -xzf foo.tar.gz

* To untar a bzipped (.bz2) tar archive file : tar -xjf foo.tar.bz2

May 13, 2008

How To Flush/Clear Squid Cache

Filed under: How To, Shell Script — Tags: , , , — tdas @ 7:29 pm

Squid is a high-performance proxy caching server for web clients, supporting FTP, gopher, and HTTP data objects. Unlike traditional caching software, squid handles all requests in a single, non-blocking, I/O-driven process.

Sometimes we need to clear the contents in the cache and restart the program. Clearing the squid cache is brain simple:

goto the directory where the squid program resides( e.g. /etc/init.d/ )
./squid flush

You would need root(su) priviledges to perform the operation

Reference :
Squid Cache

May 6, 2008

Going Back To School …

Filed under: Personal — Tags: , , — tdas @ 3:45 am

I am going back to school tomorrow after a break of 14 months. I am feeling like a bundle of nerves (happy+nervous+skeptical+sad+…) right now. I have not been allowed to do a thesis for my Masters, and the only way I can switch is, if i get straight A’s in the first four courses. Obviously that is no easy task, in fact it will be insanely tough. But as Randy Pausch so aptly said: “Brick Walls are there for a reason…it shows us,how badly we want something”. So here I am, fighting against brick wall odds, to prove to the world I am good enough.

I feel like an old, aged warrior, preparing for one last battle, one last shot at glory…

Blog at WordPress.com.