C/JAVA:
int sum = 0;
for(int i=0;i<3;i++)
sum+=sum++;
Now print the value of sum
Answer...
C:
7
Java:
0
Why?...
Thursday, June 5, 2008
Wednesday, June 4, 2008
download youtube videos
i know there are hell-a-lot of ways to do it.. for those who like to do it the dirty way like me..
- Install the browser
- Install flashgot
- Install Python
- Download and save the python script say youtube-dl.py from http://www.arrakis.es/~rggi3/youtube-dl/
- Now restart the browser and Tools->Flashgot->More Options
- Click Add, give a name, say My Youtube Downloader
- Click browser and select python.exe
- and in command line arguments give [the full path of youtube-dl.py] -t [URL] example: C:\youtube-dl.py -t [URL]
- now create a shortcut in desktop or startmenu for "C:\program files\mozilla firefox\firefox.exe" -console, if you have installed it in different directory then choose your correct executable
- Launch the browser using the link/shortcut that you created in above step
- in flashgot menu select your download manager and right click on any youtube link and select "Flashgot link", switch to the console that opened while launching forefox and see the progress..
- the files will get stored in your home directory, say c:\documents and settings\
when downloading multiple files, the console output is really ugly in firefox 3, there is no output in console but the download proceeds without any problem
Thursday, March 13, 2008
AWK 1 liners
how to find the websites visited by particular IP from squid access logs?
grep -E '192\.168\.12\.35' /var/log/squid/logs/access.log | awk '{print $7;}' | sort | sed 's/http:\/\///' | cut -d ':' -f 1 | cut -d '/' -f 1 | uniq
grep -E '192\.168\.12\.35' /var/log/squid/logs/access.log | awk '{print $7;}' | sort | sed 's/http:\/\///' | cut -d ':' -f 1 | cut -d '/' -f 1 | uniq
- grep -> get only entries related to 192.168.12.35
- awk -> take 7th column, the URL
- sort -> sort them
- sed-> remove http:// from URL
- cut -> remove port number
- cut -> remove directory and file information
- uniq -> remove duplicate entries
Thursday, February 7, 2008
Some more 'C'
in shared memory IPC in C, if you share a pointer does that mean that you share the memory location pointed by the pointer, no, after many hours of debugging a code, where a program shared an array of pointers with its child process, the child process calculated Fibonacci series and updates the array pointed by the pointer which is in shared memory location, after the child process ends, when we tried to access the array, the famous GCC report "segmentation fault".
A multithread program to calculate Fibonacci series, if every thread waits for the output of previous thread (assuming, that each thread calculates fixed number of elements in the series), then why the hell you need a multi-threaded program, so we all know that there is a formula to calculate nth number in Fibonacci series, and iterative calculation is better than formula, so what do we do.
Split the range so each thread can calculate some amount of numbers, in every thread use the formula to find the first and second number and iterate to find others.
A multithread program to calculate Fibonacci series, if every thread waits for the output of previous thread (assuming, that each thread calculates fixed number of elements in the series), then why the hell you need a multi-threaded program, so we all know that there is a formula to calculate nth number in Fibonacci series, and iterative calculation is better than formula, so what do we do.
Split the range so each thread can calculate some amount of numbers, in every thread use the formula to find the first and second number and iterate to find others.
Subscribe to:
Posts (Atom)