Tuesday, August 31, 2010

Use the variable closer to its use

Its good programming practice to define the variable closer to its use. Eg. In cpp, this is better code: for(int i = 0; in;i++) {...} rather than int i; ... ... for(i=0;in;i++) createSummaryAndThumb("summary6428596033694449081");/n;i++)/n;i...

How to bound check arrays in cpp / c

Bound checking in cpp /c is headache.... char *strcpy(char *dest, const char *src) { char *save = dest; while(*dest++ = *src++); return save; } //main func char *src = "hello to c programming language"; char dest[12]; strcpy(dest,src); //calling function Here we have no bound check on dest size or src size. When we pass it to function it is perfectly alright but problem is dest is array which is just 12 bytes long...but src is larger string... So if programmer is lucky , he gets Error - "Segmentation fault" else in worse case, he gets...

File IO in c++ 1

Introduction This tutorial will start with the very basis of File I/O (Input/Output) in C++. After that, I will look into aspects that are more advanced, showing you some tricks, and describing useful functions. You need to have good understanding of C++, otherwise this tutorial will be unfamiliar and not useful to you! Your Very First Program I will first write the code, and after that, I will explain it line by line. The first program, will create a file, and put some text into it. #include < fstream > using namespace std; int main() { ofstream...

Monday, August 30, 2010

Using == operator in better way in cpp

In cpp, it is possible that instead of i==5 we can do i=5 So we assign i = 5 and if it is like if(cond) cond gets true. So better is 5==i beause == is symmetric. If someone writes by mistake is 5=i As we get error = 'can't assign value to litera...

Friday, August 27, 2010

Regular expression

1. IntroductionAlthough there are plenty of perl hackers and other regular expression users, the amount of decent tutorials and guides on regular expressions on the 'net remains exceptionally low. Because I still find relatively many questions about regular expressions, and see how others struggle with them, I decided to write this tutorial. Bear in mind that this is still a work in-progress. 1.1. PurposeThe purpose of this tutorial is...

Thursday, August 26, 2010

Linux/Unix : Working with files

Unix files We have discussed unix files here. File names Displaying file contents -Overview There are multiple ways to display file content. So, what is equivalent of notepad here? cat - used to display the content more - used to display the content, but paginate the content  Moreover we can display part of files using head and tail. We can search the files using grep. Sort the files using sort Compare the files using diff cut the file part using cut remove the duplicate lines using uniq. Count the words, lines and characters using...

date and time and days

cal for printing present month calendar cal n prints calendar for year n, example n = 2007 cal m n prints calendar for month m and year...

cat in linux

cat Read/scan the man page for cat with the command: man cat Use this command to display the contents of a file. What happens? cat filename Now try this command notice the difference. How many lines are in the file? cat -n filename The cat command is more often used for purposes other than just displaying a file. Try these commands to "concatenate" two files into a new, third file: cat file1 - first, show file1 cat file2 ...

ls in unix / linux

Use ls without any arguments to display your current directory contents. How many files do you see? Now use ls with the -a option. How many files do you see this time? Notice that the "new" files all begin with a "dot", which indicates they are "hidden" files. ls -a This command is useful for distinguishing between directories, ordinary files, and executable files. Notice how its output differs from ls without arguments. ls -F Use the command ls -l to obtain a "long" listing...

ps in linux

ps r: Shows only running processes. ps f: Shows children descended from their parents in an ASCII art tree. I find this very useful when looking at problem processes. Use with the S option to see CPU information from children summed up with parents. ps e: Shows the command environment for each process. This is useful in a situation where a program works for one user but not for another, or on one machine but not on another. ps -t pts/3: Shows processes associated with the specified tty. I've found this useful when trying to work out who's doing...

Wednesday, August 25, 2010

Grep examples

want to display lines starting with the string "root" grep ^root /etc/passwd root:x:0:0:root:/root:/bin/bash PatternWhat does it match? bagThe string bag. ^bagbag at beginning of line. bag$bag at end of line. ^bag$bag as the only word on line. [Bb]agBag or bag. b[aeiou]gSecond letter is a vowel. b[^aeiou]gSecond letter is a consonant (or uppercase or symbol). b.gSecond letter is any character. ^...$Any line containing exactly three characters. ^\.Any line that begins with a dot. ^\.[a-z][a-z]Same, followed by two lowercase letters (e.g., troff...

Friday, August 13, 2010

Orthogonality

Literally orthogonality means at right angles, hence independent or irrelevant to. In programming languages, orthogonality means design so that changes in one thing don’t effect another. The example they give a user interface and database — you should be able to swap the database without changing the interface or make changes to the interface without affecting the database. When this term is used in describing computer instruction sets, orgothogonal instruction set can use any register for any purpose while in non-orthogonal set (such as...

Longest common substring revisited

For calculating longest substring we can use following algorithms: 1. Dynamic Algorithm 2. Hirschberg's algori...

Troubleshooting DNS servers

There may be broadly 2 problems we face when dealing with DNS server: The DNS server is not responding to clients. The DNS server does not resolve names correctly. Dealing with them 1 by 1. The DNS server is not responding to clients Cause 1: Network failure Solution: Check if the hardware is fully ok, i.e. adapters are properly plugged or not. Then check network connectivity by pinging other computers or routers (such as its default gateway) that are used and available on the same network as the affected DNS servers. Cause2: Network is o.k....

Cloud Computing and Virtualization

Cloud Computing is defined as a pool of virtualized computer resources. Based on this Virtualization the Cloud Computing paradigm allows workloads to be deployed and scaled-out quickly through the rapid provisioning of virtual machines or physical machines. A Cloud Computing platform supports redundant, self-recovering, highly scalable programming models that allow workloads to recover from many inevitable hardware/software failures. A Cloud Computing platform is more than a collection of computer resources because it provides a mechanism to manage...

Thursday, August 12, 2010

Virtualization

Virtualization is the term which may be used in various cases like hardware, memory management, storage, desktop, data and network. In these cases it has different functions and meanings. Here are some cases of virtualization: Hardware virtualization - Execution of software in an environment separated from the underlying hardware resources Memory virtualization -  Aggregating RAM resources from networked systems into a single memory pool There are other cases as well - network virtualization, storage virtualization and many more. Definition Virtualization...