Category: LEARNING

  • 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)

  • Virtualbox

    Virtualbox is a tool that provides to run multiple OS’s without rebooting your system. You can install any OS using virtualbox. Its a great tool to run another OS within another OS. For example, If you have installed Ubuntu 12.04 and you want to install Ubuntu 11.10. Then you have option that you can install that alongside Ubuntu 12.04. But with this step you have to reboot each time to switch between different OS’s.

    But you can install Ubuntu 11.04 within Ubuntu 12.04 using Virtualbox.

    Installation steps for Virtualbox:

    • Step 1
      wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add –
    • Step 2
      sudo sh -c ‘echo “deb http://download.virtualbox.org/virtualbox/debian precise contrib” >> /etc/apt/sources.list’
    • Step 3
      sudo apt-get update && sudo apt-get install virtualbox-4.1

    Now open dashboard and type virtualbox,

    then open that. It looks like below:

  • Ruby on Rails – Blog Application (Rails 2 App)

    Creating the Blog Application

    For creating this application you must install Ruby on Rails on your system and also install the database to add the backend for your applicaton.

    Click here for installing Ruby on Rails and MySQL Database.

    Follow the steps for creating your blog application in Ruby on Rails :

      1. Open a terminal, navigate to a folder where you have rights to create files, and type :

        $ rails blog -d mysql

        -d mysql option create database with MySQL connectivity.

      2. Now move to blog folder using :

        $ cd blog

      3. Database Configuration

        Open the database.yml file to edit the database settings.
        For this enter following commands in terminal:

        $ cd config/
        $ gedit database.yml

        Replace username and password with your MySQL Username and password.
        Update these changes in all three sections : development, test and production.

        After saving these changes, run this command in terminal:
        $ cd ..

      4. Database Creation

        Run the following command in terminal to create database :

        $ rake db:create

      5. Starting up Web Server

        Run this command in terminal to run default webpage in browser:

        $ script/server

      6. Creating Controller

        Run this command in terminal:

        ruby script/generate controller home index

      7. Edit Home Page

        Open app/views/home/index.html.erb file. Run these commands in terminal:

        $ cd app/views/home/
        $ gedit index.html.erb

        Add following line and Save the file.(You can also delete the previous text)


        <h1>Hello Rails !</h1>

      8. Remove index.html from public folder

        $ cd
        $ cd Desktop/blog
        $ rm pulic/index.html

      9. Setting the Application Home Page

        Open routes.rb file.
        $ gedit config/routes.rb

        Find the line beginning with root :root and uncomment it.
        Replace that line with this :

        map:root :controller => ‘home’, :action => ‘index’

        Now save that file and if you navigate to http://localhost:3000 in your browser, you’ll see the home/index view.

      10. Creating a Resource

        In the case of the blog application, you can start by generating a scaffolded Post resource. To do this, enter this command in your terminal:

        $ script/generate scaffold Post name:string title:string content:text

      11. Running a Migration

        Use following command to create tables:

        $ rake db:migrate

      12. Add a Link

        Open index.html.erb file to add link to My Blog page.

        $ cd app/views/home/index.html.erb

        Add this line at last,

        <%= link_to “My Blog”, posts_path %>

        and save the file.

        The link_to method is one of Rails’ built-in view helpers. It creates a hyperlink based on text to display and where to go – in this case, to the path for posts.

      13. Test Your Blog Application

        $ script/server

        Now open http://localhost:3000/ in browser.

      By these steps your blog is created and if you find any error then feel free to ask and share it through comments.

  • Configuring the Database in Ruby on Rails

    Configuring a Database

    Just about every Rails application will interact with a database. The database to use is specified in a configuration file, config/database.yml. If you open this file in a new Rails application, you’ll see a default database configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default:

    • The development environment is used on your development/local computer as you interact manually with the application.
    • The test environment is used when running automated tests.
    • The production environment is used when you deploy your application for the world to use.

    1) Configuring an SQLite3 Database

    Rails comes with built-in support for SQLite3, which is a lightweight serverless database application. While a busy production environment may overload SQLite, it works well for development and testing. Rails defaults to using an SQLite database when creating a new project, but you can always change it later.

    Here’s the section of the default configuration file (config/database.yml) with connection information for the development environment:

      development:
      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000

    In this guide we are using an SQLite3 database for data storage, because it is a zero configuration database that just works. Rails also supports MySQL and PostgreSQL “out of the box”, and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it.

    2) Configuring a MySQL Database

    If you choose to use MySQL instead of the shipped SQLite3 database, yourconfig/database.yml will look a little different. Here’s the development section:

      development:
      adapter: mysql
      encoding: utf8
      database: new_development
      pool: 5
      username: root
      password:
      socket: /tmp/mysql.sock

    If your development computer’s MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the development section as appropriate and you can also do these changes in test and production sections too.

    3) Configuring a PostgreSQL Database

    If you choose to use PostgreSQL, your config/database.yml will be customized to use PostgreSQL databases:

      development:
      adapter: postgresql
      encoding: unicode
      database: new_development
      pool: 5
      username: blog
      password:

    You can also do these changes in test and production sections.

    Change the username and password in the development section as appropriate.

    Creating the Database

    Now that you have your database configured, it’s time to have Rails create an empty database for you. You can do this by running a rake command:

    $ rake db:create

    This will create your development and test  databases inside the db/ folder

  • Installation Steps for Ruby on Rails

    Steps to install Ruby on Rails

    1) Setting up the Rails development environment

    Ruby, rubygems, rails and other required packages can be installed by :

    1. sudo apt-get install build-essential
    2. $ sudo apt-get install ruby-full
    3. $ cd Downloads
    4. $ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
    5. $ tar xzvf rubygems-1.8.24.tgz
    6. $ sudo mv rubygems-1.8.24 /usr/local/src
    7. $ cd 
    8. $ cd /usr/local/src
    9. $ cd rubygems-1.8.24
    10. $ sudo ruby setup.rb
    11. $ sudo update-alternatives –install /usr/bin/gem gem /usr/bin/gem1.8 1 
      If you got error in this step (ERROR: update-alterntives:error: unknown argument ‘–install’),   then retype ‘–‘ (Two Hyphens) before install
    12. $ sudo gem install rails

    2) Setting up MySQL Database

    If you have already installed Mysql then ignore this step.

    $ sudo apt-get install mysql-server

    Well you have now install Ruby on Rails ,Now its time to test it. So Create a Rails’s application .Here name of Rails application is new ,you can give your own name.

    Go to place where you want to create Ruby on Rails application and run these commands in terminal :

    rails new
    cd new
    rails server

    The rails server command launches a small web server named WEBrick which comes bundled with Ruby. You’ll use this any time you want to view your work through a web browser.
    This command will give you the following output in terminal

    => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-04-18 03:20:33] INFO WEBrick 1.3.1 [2010-04-18 03:20:33] INFO ruby 1.8.7 (2010-01-10) [x86_64-linux] [2010-04-18 03:20:33] INFO WEBrick::HTTPServer#start: pid=26086 port=3000

    With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open http://localhost:3000, you will see a basic rails app running.
    Congratulations ,You are now running Ruby on Rails.
    If you want to stop server then Press Ctrl+C in terminal

    Continue to Configuring the Database in Ruby on Rails.

  • Ruby on Rails

    What is Rails?Ruby on Rails

    Rails is a web development framework written in the Ruby language. It is designed to make programming web applications easier by making several assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Longtime Rails developers also report that it makes web application development more fun. Rails is opinionated software. That is, it assumes that there is a best way to do things, and it’s designed to encourage that best way – and in some cases discourage alternatives. If you learn “The Rails Way” you’ll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience. The Rails philosophy includes several guiding principles:

    • DRY – “Don’t Repeat Yourself” – suggests that writing the same code over and over again is a bad thing.
    • Convention Over Configuration – means that Rails makes assumptions about what you want to do and how you’re going to do it, rather than letting you tweak every little thing through endless configuration files.
    • REST is the best pattern for web applications – organizing your application around resources and standard HTTP verbs is the fastest way to go.

    The MVC Architecture

    Rails is organized around the Model, View, Controller architecture, usually just called MVC. MVC benefits include:

    • Isolation of business logic from the user interface
    • Ease of keeping code DRY
    • Making it clear where different types of code belong for easier maintenance

    Models

    A model represents the information (data) of the application and the rules to manipulate that data. In the case of Rails, models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, one table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models.

    Views

    Views represent the user interface of your application. In Rails, views are often HTML files with embedded Ruby code that performs tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.

    Controllers

    Controllers provide the “glue” between models and views. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.

    The Components of Rails

    Rails provides a full stack of components for creating web applications, including:

    • Action Controller
    • Action View
    • Active Record
    • Action Mailer
    • Active Resource
    • Railties
    • Active Support

    Action Controller

    Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action. Services provided by Action Controller include session management, template rendering, and redirect management.

    Action View

    Action View manages the views of your Rails application. It can create both HTML and XML output by default. Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.

    Active Record

    Active Record is the base for the models in a Rails application. It provides database independence, basic CRUDfunctionality, advanced finding capabilities, and the ability to relate models to one another, among other services.

    Action Mailer

    Action Mailer is a framework for building e-mail services. You can use Action Mailer to send emails based on flexible templates, or to receive and process incoming email.

    Active Resource

    Active Resource provides a framework for managing the connection between business objects an RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.

    Railties

    Railties is the core Rails code that builds new Rails applications and glues the various frameworks together in any Rails application.

    Active Support

    Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in the Rails, both by the core code and by your applications.

  • Fedena, An Opensource (And Free) School Management System

    School management software systems in India are archaic (just the way our education system is) and most of these software are developed by fly-by-night operators who really do a crappy job of building such a software (and charge a bomb to schools).

    At the core, schools need to really adapt latest software which can help them improve productivity (many big schools in Bangalore still store student data in Microsoft excel).

    Fedena is set to change the scene with its open source school management software, developed on RoR framework. Developed by Bangalore based Foradian Technologies, Fedena can be used as:

    • Student Information System (SIS)
    • School Management software
    • School ERP
    • Campus Management software
    • Student records system
    • Student management system
    • School software
    • E-learning system

    Fedena Admin Screen

    Fig : Dashboard of Fedena Admin

    Benefits to schools:

    • Available in chosen language.[Ex: Kannada, Tamil, Spansh]
    • Easy tracking of students and Employees
    • Easy way for TC generation and Transfer of Batch
    • Time table generation and Examination creation
    • Analyzing student’s performance and attendance
    • Various student and staff reports [based on different category, religion, blood group, caste, DOB and many other filters]
    • Easy Attendance Marking and Attendance reports
    • All the historical records of a student available easily
    • Helps in sending data to UID project
    • As the entire data is online and secure, any analysis can be done at any desired point of time.
  • Video Chat with OpenTok

    OpenTok

    The OpenTok video chat platform delivers the simplicity and customization that developers need for building modern web applications. This new API lets you call the shots. You have full control over layout, who sees whom, and who just watches.

    The OpenTok API is a free and flexible cloud-based API, making it easy to add video chat to your applications without having to worry about infrastructure and scale—build your app using our simple JavaScript or ActionScript libraries.

    Technical Requirements for OpenTok

    End users will need the following:

    • Flash Player 10.3 or later
    • Firefox 3.0+, Safari 4.0+, Internet Explorer 7+, Chrome
    • Windows XP+, OSX 10.4+
    • A webcam and a microphone!
    • A standard DSL line with a minimum upload and download speed of 160kb per call participant

    OpenTok in Linux

    OpenTok does not support in Linux but it provides facility to support Linux by adding {wmode : “window”}  in session.publisher function. If video chat is not working after adding this then do the following changes :

    • Download webcamstudio for video chatting using OpenTok

    Link to install webcamstudio :
    http://mandeepsimak.wordpress.com/2012/05/18/webcamstudio-a-free-virtual-webcam-software-with-cool-effects-ubuntu-11-1012-04/

    OR

    • Do the global settings of Adobe Flash Player
    Open 
    and choose Always Allow for static.opentok.com and staging.opentok.com it will allow it to work properly.

    Options available with OpenTok

    • Video Recording
    • Video chatting
    • Video Conferencing
    • Video Archiving

    Limitations of OpenTok

    • High speed internet connection is required. 
    • Global settings for Adobe Flash should be done for using OpenTok in Linux.
    • Sometimes after changes Flash settings, it doesn’t work.
    • Linux and Flash Player do not combine very well. So, we have to install Webcam Studio in Linux to fix camera acquisition problem.


  • Graphics.h in Linux for c/c++

    graphics.h is a header file that is used to add graphics in c/c++ program in TURBOC. But in Ubuntu graphics.h file is not supported by g ++ compiler.

    For executing graphics program in g++ compiler, we have to install library files.

    Steps for installing the graphics library files are as follows:

    First run $ sudo apt-get install build-essential in terminal to install necessary compiler tools.

    Then, install the following packages:
    libsdl-image1.2
    libsdl-image1.2-dev
    guile-1.8
    guile-1.8-dev
    libsdl1.2debian-art
    libartsc0-dev
    libaudiofile-dev
    libesd0-dev
    libdirectfb-dev
    libdirectfb-extra
    libfreetype6-dev
    libxext-dev
    x11proto-xext-dev
    libfreetype6(upgrade)
    libaa1
    libaa1-dev
    libslang2-dev
    libasound2
    libasound2-dev

    You can install them by typing the following command in the terminal :
    $ sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian-arts libartsc0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6(upgrade) libaa1 libaa1-dev libslang2-dev libasound2 libasound-dev

    After this download libgraph-1.0.1 (This is the link) to your Home Folder.
    Right click on it and press “Extract here”

    open terminal and navigate into the folder u just extracted the file contents into by running $ cd libgraph-1.0.1

    Now run the following commands one after the another. Proceed to the next command only if the preceding command executes without any errors.
    $ ./configure
      $ sudo make
      $ sudo make install

    If you get any errors during the “sudo make” step, paste it in the comments section of this post.

    Now technically install is over. :)

    Try writing a simple program including graphics.h. Declare the values of gd and gm and call initgraph as follows

    int gd,gm=VGAMAX; gd=DETECT;
    initgraph(&gd,&gm,NULL);

    and when compiling using g++ add an extra paramter -lgraph

    i.e if you are compiling a program example.cpp in the terminal u type in

    $ g++ example.cpp -o example.o -lgraph

    And execute the program by runnung ./example.o

    If on compile it gives u an error that says “could not load shared libraries” or something like that just run the following command and it should fix it

    $ sudo cp /usr/local/lib/libgraph.* /usr/lib

    An example program(to print a line) :

    #include<iostream>
    #include<graphics.h>

    int main()
    {
    int gd,gm=VGAMAX; gd=DETECT;
    initgraph(&gd,&gm,NULL);
    line(50,50,80,80);
    delay(5000);

    return 0;
    }

  • Installation of g++ compiler in LINUX

    GNU C++ compiler is a fairly portable optimizing compiler for C++/C. g++ compiler is used to execute both c and c++ programs.

    Command for installing G++ Cmpiler

    Execute this command in terminal :

    $ sudo apt-get install g++
    
    Steps for compiling and executing c++ program
    
    1. Write and save the program in gedit
        
        //Sample c++ program
        #include<iostream>
        using namespace std;
        main()
        {
             cout<<"Sample c++ Program";
             return 0;
        }
    
        Save the program as sample.cpp (.cpp is the extension for c++ program).
    
    2. Compile the program
    
       Write the following command in terminal after installing g++ compiler.
       $ g++ sample.cpp -o sample.o
    
       In this command,
    • g++ indicates the compiler name,
    •  sample.cpp is a file name of the source program,
    •  -o option specifies the file name of the output program.
    •   sample.o is an output file.
       If there is no syntax/semantic error in you program then the compiler 
       will successfully generate an executable file,otherwise fix the problem 
       in your code.
    
    3. Executing the program
       Write the following command in terminal after compiling c++ program.
       $ ./sample.o
     
       After executing this command it gives the output as:
       Sample c++ Program
    
    If you have any problems then share it through comments.