Pages

Saturday, March 24, 2012

getch(), getche() & clrscr() in gcc

Sometimes, we need to use "conio.h" in Linux (gcc). Functions like getch(), getche() and clrscr() are present in the header file "conio.h". getch() prompts the user to press a character and that character is not printed on screen. getche() prompts the user to press a character and that character is printed on screen. clrscr() clears the console screen.
Given below is the code you need to save under the name conio.h to make the functions work.
       
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

/* reads from keypress, doesn't echo */
int getch(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

/* reads from keypress, echoes */
int getche(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

/* Clears screen */
void clrscr(void)
{
 system("clear");
}       
 

Just include the above header files and you can use the these functions.

#Source: Internet

Friday, March 9, 2012

Install Dropbox in Ubuntu

Dropbox is a Web-based file hosting service operated by Dropbox, Inc. that uses cloud storage to enable users to store and share files and folders with others across the Internet using file synchronization. Dropbox provides 2 GB of free online storage. Users who refer Dropbox to others can gain up to 8 GB of additional free storage.

For installing Dropbox, download it from here:
     Ubuntu (.deb)       32-bit            64-bit 
For installing the .deb file, simply double-click on it and then select Install Package.

Alternatively, you can also install a .deb file by opening terminal and typing:
$ sudo dpkg -i package_file.deb
Install Dropbox Via Command-Line
To install, run the following command in your Linux terminal.
32-bit
$ cd ~ && wget -O - http://www.dropbox.com/download?plat=lnx.x86 | tar xzf -
64-bit
$  cd ~ && wget -O - http://www.dropbox.com/download?plat=lnx.x86_64 | tar xzf -
 Next, run the Dropbox daemon from the newly created .dropbox-dist folder.
$  ~/.dropbox-dist/dropboxd
If you're running Dropbox on your server for the first time, you'll be asked to copy and paste a link in a working browser to create a new account or add your server to an existing account. Once you do, your Dropbox folder will be created in your home directory.
Source:  Dropbox

Tuesday, January 17, 2012

Download Flash (.flv) Videos on Ubuntu

Whenever we watch a flash video (such as over You Tube or any other sites), the flash video file gets stored in the temp folder or browser's cache temporarily. We can store those files into our file system for watching it later. First make sure that the video has been completely streamed on your browser and the tab in which the video was playing hasn't been closed. The temporary flash file gets deleted once you close the tab in which the video had been opened. So its necessary not to close the video before completing the steps below.
  First we need to locate the flash video file on our system. For locating the temporary flash video file, use the command:
    lsof | grep -i flash
For detailed documentation on "lsof" command, check the man pages. 
It will give an output like:
"chromium- 1674 shekhar mem REG 8,1 17047244 13128 /usr/lib/adobe- flashplugin/libflashplayer.so"
"chromium- 1761 shekhar mem REG 8,1 17047244 13128 /usr/lib/adobe- flashplugin/libflashplayer.so"
"chromium- 1761 shekhar 22u REG 8,1 8046003 9222 /tmp/FlashXXopqyZk (deleted)"
 The third output line (the one with darkest background color in my case) indicates that the file is somewhere in the /proc directory. Using the process id 1761 (the second field in the output of lsof command), we can find the file FlashXXopqyZk in the /proc directory.
For finding the file use the command:
$  cd /proc/1761/fd ; ls -l | grep FlashXXopqyZk
The output of the above command would be something like:
 lrwx------ 1 shekhar shekhar 64 2012-01-17 09:36 22 -> /tmp/FlashXXopqyZk (deleted)
The above output indicates that the flash video file is named 22 (the field indicated in bold and large font in the above output) and is linked to /temp/FlashXXopqyZk (deleted). Now we just need to copy the file from the /proc directory to our home directory. For copying the file to the Videos folder in your home directory, use the command:
$  cp 22 ~/Videos/filename.flv
And we are done. Navigate back to your Videos folder and watch the video.