Category: LINUX

  • Doxygen – Documentation Builder

    Doxygen

    Generate documentation from source code

    Doxygen is the standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, Tcl, and to some extent D.

    Installation

    Run following command in terminal:

    $ sudo apt-get install doxygen

    Usage

    It’s very simple to use. Just type $ doxygen in terminal and you got its manual.

    For using comments format is very important. So before start check its comment instructions.

    To create documentation, move to folder where your source file exits through terminal and then type

    $ cd /path/to/your/project/source/
    $ doxygen -g [filename]

    You can fill any filename as your choice. Its configuration file and you can edit that according your project details like change project name in filename.(config file for doxygen)

    Then run

    $ doxygen [filename]

    By this your documentation will be generated. This will create 2 folders in your current directory.
    Folders:

    • html for html documentation open /path/to/project/source/html/index.html to check documentation.
    • latex for documentation using latex as pdf output. For that file run

      $ cd /path/to/your/project/source/latex
      $ make

    This will create refman.pdf file(check pdf file as file name may be changed in your case).

    That’s all. This is basic guide, you can do more by exploring filename.conf file.
    You can also add Special Commands in comments to make your documentation more descriptive.

    Hope this will help you.

  • C++ with CGI

    Before doing example, You have to configure cgi-bin with apache server.
    If its done then try your first example.

    Open an empty file and write following c++ code.


    #include <iostream>
    using namespace std;

    int main ()
    {

    cout << "Content-type:text/html\n\n";
    cout << "Hello World - First CGI Program";

    return 0;
    }

    Now save this file with .cpp extension(example.cpp) in public_html/cgi-bin folder.
    Then compile that program.
    $ g++ -o example example.cpp

    This will create example file which is executable.
    Then open browser and open following link”

    localhost/~username/cgi-bin/example

    This will show you following o/p on browser.

    Hello World – First CGI Program

    If you find any problem then share it as comments.
    Thankyou.

  • CGI Configuration on Apache

    There are 3 ways to use CGI.

    • First Way
      When we install Apache server, then /usr/lib/cgi-bin folder is automatically created. You can place c++ files in that folder and execute them on browser(localhost/cgi-bin/example).
    • Second Way
      You can also configure /var/www/cgi-bin for CGI programming.
    • Third Way
      You can also configure cgi-bin in home directory as /public_html/cgi-bin.

    According to me 3rd way is best as its in home directory and we don’t have to use sudo while compiling or creating any file.

    Steps to configure cgi-bin in public_html and public_html. Run following commands in terminal

    1. $ sudo a2enmod cgi
    2. $ sudo a2enmod cgid
    3. $ sudo a2enmod userdir
    4. $ sudo service apache2 restart
    5. $ mkdir ~/public_html
    6. $ cd ~/public_html
    7. $ mkdir cgi-bin
    8. $ cd /etc/apache2
    9. $ sudo vim sites-available/default
    10. Add following text in file:
       ScriptAlias /cgi-bin/ /home/*/public_html/cgi-bin/
       <Directory "/home/*/public_html/cgi-bin">
               AllowOverride None
               Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
               SetHandler cgi-script
               Order allow,deny
               Allow from all
       </Directory>
      
    11. $ sudo service apache2 restart
  • MySQL with C++

    Here’s an example for connecting C++ program with MySQL.

    You can simply download code from Github [Link]

    or

    Do as following

    Write following code in text editor and save file as mysql.cpp

    
    // Include Header Files
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    
    // For MySQL Connection
    #include <mysql.h>
    
    using namespace std;
    
    // Defining Constant Variables
    #define SERVER "localhost"
    #define USER "root"
    #define PASSWORD "password"
    #define DATABASE "test"
    
    int main()
    {
        MYSQL *connect;
        connect = mysql_init(NULL);
    
        if (!connect)
        {
            cout << "Mysql Initialization Failed";
            return 1;
        }
    
        connect = mysql_real_connect(connect, SERVER, USER, PASSWORD, DATABASE, 0,NULL,0);
    
        if (connect)
        {
            cout << "Connection Succeeded\n";
        }
        else
        {
            cout << "Connection Failed\n";
        }
    
        MYSQL_RES *res_set;
        MYSQL_ROW row;
    
        // Replace MySQL query with your query
    
        mysql_query (connect,"show tables");
    
        unsigned int i=0;
    
        res_set=mysql_store_result(connect);
    
        unsigned int numrows = mysql_num_rows(res_set);
        
        cout << " Tables in " << DATABASE << " database " << endl;
    
        while (((row=mysql_fetch_row(res_set)) !=NULL))
        {
            cout << row[i] << endl;
        }
    
        mysql_close (connect);
    
        return 0;
    }
    
    

    Now compile and run this program in terminal using following statements.

    $ g++ -o mysql mysql.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql

    $ ./mysql

  • MySQL Connector for C++

    MySQL Connector/C++ is a MySQL database connector for C++.

    Installation

    If you are using Linux then you need to install two additional packages i.e. libmysql++ and libmysql++-dev for connecting C++ program with MySQL

    Run following commands in terminal.

    $ sudo apt-get install libmysql++

    $ sudo apt-get install libmysql++-dev

  • Capistrano

    Capistrano is an open source tool for running scripts on multiple servers; its main use is deploying web applications. It automates the process of making a new version of an application available on one or more web servers, including supporting tasks such as changing databases.

    Capistrano is written in the Ruby language and is distributed using the RubyGems distribution channel. It is an outgrowth of the Ruby on Rails web application framework, but has also been used to deploy web applications written using other frameworks, including ones written in PHP.

    Capistrano is implemented primarily for use on the Bash command line. Users of the Ruby on Rails framework may choose from many Capistrano recipes, e.g. to deploy current changes to the web application or roll back to the previous deployment state.

    Installation

    Run following command in terminal.

    $ gem install capistrano

  • Phusion Passenger

    Phusion Passenger (informally also known as mod_rails and mod_rack) is a free module for the Apache HTTP Server and nginx for deployment of Ruby applications, including those built using the Ruby on Rails framework. It is available as a Gem package and is supported on Unix-like operating systems. Phusion Passenger also supports arbitrary Ruby web applications that follow the Rack interface.

    Phusion Passenger is the “preferred deployment setup” for Ruby on Rails applications, and has been recommended by the Ruby on Rails authors. In combination with Ruby Enterprise Edition, Phusion Passenger claims that it is capable of reducing Rails’s memory consumption by 33% as well as increasing its performance.

    Installation

    Run following commands in terminal.

    1. Install Passenger
      $ gem install passenger
      1
    2. Install Passenger Module for Apache
      $ passenger-install-apache2-module
      2

      After this step press enter.

      3

      Again press enter and install requirements mentioned by software.

      4

    3. After installing these requirements, again run following command
      $ passenger-install-apache2-module

      The passenger-install-apache2-module script will guide you through what you need to do to get Passenger working.

      5

      It should tell you to copy these lines into your /etc/apache2/apache2.conf:

      LoadModule passenger_module /home/mandy/.rvm/gems/ruby-1.9.3-p327/gems/passenger3.0.18/ext/apache2/mod_passenger.so
      PassengerRoot /home/mandy/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18
      PassengerRuby /home/mandy/.rvm/wrappers/ruby-1.9.3-p327/ruby

      Note: Above lines may be different in your case. Check them according to your script instructions.

      After copying, Restart Apache Server buy executing following commands in terminal.

      $ sudo a2enmod rewrite
      $ sudo service apache2 restart

      At last press ENTER and your phusion passenger is installed on your system.

  • Refinery CMS

    Refinery CMS, often shortened to Refinery, is an open source content management system written in Ruby as a Ruby on Rails web application with jQuery used as the JavaScript library. RefineryCMS supports Rails 3.2.

    Refinery differs from similar products by targeting a non-technical end user and allowing the developer to create a flexible website rapidly by staying as close as possible to the conventions of the Ruby on Rails framework.

    Official Website Link: www.refinerycms.com

    Features

    • Engine architecture
    • WYSIWYG content editing
    • Localisation (currently supports 26 languages
    • Page management
    • Image and File management
    • Contact form and inquiry management
    • Search engine optimization (SEO)

    Installation

    Run following command in terminal.

    $ gem install refinerycms

    It takes time to install.

    Thanks.

  • Ruby on Rails – Installation using RVM

    Ruby Version Manager (RVM) is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

    Steps for Installation
    Open terminal and run following commands.

    • Step 1
      $ sudo apt-get install build-essential git-core curl
    • Step 2
      RVM Installation
      $ curl -L get.rvm.io | bash -s stable
    • Step 3
      $ echo ‘[[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”‘ >> ~/.bashrc
    • Step 4
      $ ~/.bashrc
    • Step 5
      $ . ~/.bashrc
    • Step 6
      Check requirements for Ruby
      $ rvm requirements
    • Step 7
      Install requirements of Ruby by RVM
      $ sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
    • Step 8
      Install Ruby with 1.9.3 version
      $ rvm install 1.9.3
    • Step 9
      Check Rubygems version. Its installed with Ruby.
      $ gem -v
      1.8.24
    • Step 9
      Install Rails latest version
      $ rvm gem install rails
    • Step 10
      Check version of Ruby, Rails and Rubygems
      $ ruby -v
      ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
      $ gem -v
      1.8.24
      $ rails -v
      Rails 3.2.8

    Installation is complete. Now try RoR Apps.
    If you find any error between steps then share it as comments.
    Thanks for using this post.

  • OpenstreetView (OSV) – RoR Application

    OpenStreetView (OSV)  is a Ruby on Rails application.
    Requirements for OSV
    1. MySQL (Database)
    2. Ruby 1.8-dev
    3. Rails 2.3.8
    4. Rubygems
    Installation steps for requirements :
    1. MySQL

      Open the terminal and run the following command :
      $ sudo apt-get install mysql-server mysql-client

    2. Ruby 1.8-dev

      Open terminal and then write the following command :
      $ sudo apt-get install ruby1.8-dev

    3. Rubygems

      Download Rubygems : rubygems-1.3.7.zip
      Now unzip that using following command in terminal :
      $ cd Downloads (Move to location where you downloaded rubygems)
      $ unzip rubygems-1.3.7.zip

      Now move rubygems-1.3.7 to /usr/local/src
      Open terminal and write
      $ cd Downloads
      $ mv rubygems-1.3.7 /usr/local/src

      After that install rubygems. Open terminal and run
      $ cd /usr/local/src/rubygems-1.3.7
      $ ruby setup.rb

      OR

      You can install rubygems by running following command in terminal:
      $ sudo apt-get install rubygems

    4. Rails 2.3.8

      Run following command in terminal:
      $ sudo gem install rails -v 2.3.8

    Now check whether you have installed each and everything correctly or not.
    Run following in treminal:

          $ ruby -v
          $ gem -v
          $ rails -v

    After fulfilling the requirements, its time to download OSV code.

    Download the code from:

    https://github.com/johnmckerrell/OpenStreetView/downloads

    And then extract that somewhere you want.

    Or you can do as below:

    mkdir OSV
    cd OSV
    sudo apt-get install git-core;
    git clone git://github.com/johnmckerrell/OpenStreetView.git
    // or
    git clone https://github.com/johnmckerrell/OpenStreetView.git
    cd OpenStreetView
    cd config
    sudo gedit config/database.yml

    It will Open the database.yml in Geditor. This file contain the Information regarding the Database connection for OSV So Carefully do as:

    a)Change user and password of MySQL and socket as follow
    b)socket: /var/run/mysqld/mysqld.sock

    Now edit the other file as:
    sudo gedit config/environment.rb

    // Change server name from www.openstreetview.org to localhost in line
    // number 7, in line number 4, make version for RAILS_GEM_VERSION as ‘2.3.8’
    Now Change the Directory as Follow as:

    cd vendor/plugins/
    a)git clone http://github.com/technoweenie/restful-authentication.git restful_authentication
    b)sudo rake gems:install
    You are Just two Steps away to Run OSV. Now change the Directory as Following and do as:

    a)cd OSV/OpenStreetView
    b)rake
    c)rake db:migrate
    d)script/server

    The script/server will Start the server , Now you Can run the OSV at localhost as:
     Browse in browser(localhost:3000)