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.

Sunday, October 30, 2011

sudo : Unable to Resolve Host

This happens after the host-name of the system is changed. Host-name can be changed by editing the file "/etc/hostname".
   sudo gedit /etc/hostname
For resolving the host conflict, we need to edit the file "/etc/hosts". For editing this file use the command:
   sudo gedit /etc/hosts


Edit the name in front of 127.0.1.1 to the new host-name. This will do.



Share and Learn !!!

Thursday, September 22, 2011

Download YouTube Videos in Ubuntu 11.04

More often we need to download videos from YouTube and similar other sites. Ubuntu provides a command-line feature for downloading videos from YouTube.

For this you need to install the package "youtube-dl". This can be done by using the terminal or the synaptic package manager. For installing the package using the terminal, use the command:
      sudo apt-get install youtube-dl
You can install it through the synaptic package manager by searching the package youtube-dl in it.


Make sure you have updated the package after you have installed it. For updating the package, use the command
    youtube-dl  --update
If you get permission error, change the permissions of youtube-dl in /usr/bin using the command:
   chmod 777 youtube-dl
For downloading the YouTube video, open the terminal (press Ctrl+Alt+T) and type the command:
   youtube-dl "URL"
Open the relevant video in the browser and copy the URL from there.

After the download is completed you can find the video in your HOME folder.

Share and learn. If you have some problems related to this post, post it here.

Wednesday, August 25, 2010

C Graphics Programming in Ubuntu

-->
The solution for doing graphics programming in ubuntu is:
libgraph - library providing the TurboC graphics API ( graphics.h) in Linux using SDL.

For using this , you need to follow some simple steps as mentioned below:
First of all, you need to install the dependencies so that all the required compiler tools gets installed. For that you need to run the given command on the terminal:
sudo apt-get install build-essential

Next you need to install some packages. They are: libsdl-image1.2, libsdl-image1.2-dev, guile-1.8 and guile-1.8-dev. For that run the given command at the terminal:
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev

Now, download and install libgraph-1.0.2.tar.gz from the link :
Download this file in any folder and extract it in the home folder or on the desktop wherever you want.

Open the terminal and navigate to the folder where you have extracted libgraph-1.0.2 with the help of cd command. Install this using the commands given below:
./configure (Return)
sudo make (Return)
sudo make install (Return)

After this you can start your C graphics programming in linux. Now try writing a simple C graphics program by including the header file "graphics.h". You can do the programs as you in TURBO C.

For writing the programs you can use the "gedit" tool in ubuntu. For compiling the programs, navigate to the source program folder and use the following command:
gcc filename.c -lgraph
For executing the program, use the command ./a.out


The error “./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory” can be solved by
sudo cp /usr/local/lib/libgraph.* /usr/lib

If you still have some furthur issues related to this post, post it here.

Friday, February 26, 2010

Installing JDK & JRE in Ubuntu Linux

You need to follow some simple steps for installing Sun Java Development Kit(JDK) & Java Runtime Environment(JRE) in Ubuntu Linux. They are:

Step 1: At the initial stage ,check whether the MULTIVERSE repository is enabled or not.
For this Click on System->Administration->Software Sources->Select Multiverse->Close.

Step 2: Open TERMINAL and type the following to install JDK and JRE :
sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk


Note: (1):
If you want to use command-line 
interface , press Ctrl+Alt+F1 and enter the user name and password. For returning to the graphical user interface , press Ctrl+Alt+F7.
(2):You may need to update the runtime or development kit for the java language. For updation type sudo update-java-alternatives -s java-6-sun at the terminal.

Step 3:
Set up the environment variable.
For this , do the following:
Type the following at the terminal:

vi $HOME/.bash_profile
Type the following in the opened text file:
export JAVA_home=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
Save and close the file. For this , press ESC and type :wq and press enter.

Warning: Linux is case-sensitive.So,take care of the case of the command entered.

Note: If you want to know the version of JRE installed , use the following command :

java -version
For compiling the java program , go to the specified directory and type
javac filename.java
For executing the program , use the command
java filename

ENJOY THE PROGRAMMING.