Just another WordPress.com weblog

Install Ruby on Rails
1. Install Dependencies
$ sudo apt-get install ruby ruby-dev zlib1g-dev libsqlite3-dev sqlite3

2. Install Rails without documentations of gem files

$ sudo gem install rails –no-ri –no-rdoc

Note : Missing dependency of ruby-env or zlib1g-dev will result in following error :

ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/usr/bin/ruby2.1 extconf.rb

If anybody is facing such an issue while installing, please look into the log file of a specific gem where you encountered the problem and install the specific dependency package for that gem

Install rails without documentation for gems by default
1. find out gemrc file in your system
$ strace gem source 2>&1 | grep gemrc
stat(“/etc/gemrc”, 0x7fffe6f7dcd0) = -1 ENOENT (No such file or directory)
stat(“/home/selva/.gemrc”, 0x7fffe6f7ddb0) = -1 ENOENT (No such file or directory)
2. $ vim ~/.gemrc – add below line to this file :
gem: –no-documen

After you have created your rails application and you are facing the issue like “rails server autodetect’ could not find a javascript runtime” while starting your application’s rails server (bin/rails server), You can either install therubyracer gem which is commented in your Gemfile or You can install node.js by using this link :

http://www.ubuntuupdates.org/ppa/nodejs_v012?dist=vivid

Download the the repository key with:

curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -

Then setup the repository:

$ sudo sh -c "echo deb https://deb.nodesource.com/iojs_1.x vivid main \
> /etc/apt/sources.list.d/nodesource.list"
$ sudo apt-get update
$ sudo apt-get install iojs

<?php

echo ‘<pre>’;

class EmailTemplates {
private $inputString;

function __construct() {
$this->inputString = file_get_contents(‘message3.txt’);  //Read File and convert into string
}

public function parseEmailContent() {

//Finding “From:” word and getting the whole line.

$fromPattern = “/From\:(.*)/im”;  //Where  i = case insensitive, m = string matching found multiple times
preg_match_all($fromPattern, $inputStr, $fromAddress);   //Match founded will be stored in first index and result will be returned to second index of resulting array variable. preg_match_all stores all matched values into array.
print_r($fromAddress);
$fromPattern = “/To\:(.*)/im”;
preg_match_all($fromPattern, $inputStr, $fromAddress);
print_r($fromAddress);
$messagePattern = “/\”([^\”]+)\”/”;  //Finding  Email body messages within Double Quotes.
preg_match_all($messagePattern, $inputStr, $bodyMessage);
print_r($bodyMessage);
}
}

$emailTpl = new EmailTemplates();
$emailTpl->parseEmailContent();

?>

Email Contents File : message.txt

From: mine@gmail.com
To: myfriend@gmail.com

“sdjfdsfhsodn asdfsdlfdsfd;
sdfhdsiofdsfdsfihds sdifjdsofjn sd dsifjdsofn sdoifodsjifsdjfjdslfd”

Regards,
Selvamani

From: Mine <mine@gmail.com>
To: My Friend <myfriend@gmail.com>

“sdjfdsfhsodn ouef sncks ahcnkl9isdio90q2
sdfhdsiofdsfdsfihds sdifjdsofjn sd dsifjdsofn sdoifodsjifsdjfjdslfd”

Regards,
Selvamani

<?php

echo “<pre>”;
$numArray = array(11,1,9,4,13,47,5,15,2,7);
echo “Input Value : “;
print_r($numArray);

$n = count($numArray);
$result = sortArray($numArray, $n);
echo “Output Value : “;
print_r($result);

function sortArray($unsortedArr, $n) {
$len = count($unsortedArr);
for($i = 0; $i < $len-1; $i++) {
if($unsortedArr[$i+1] < $unsortedArr[$i]) {
$unsortedArr[$i+1] ^= $unsortedArr[$i] ^= $unsortedArr[$i+1] ^= $unsortedArr[$i];   //Swapping Array index values
}
}
#    print_r($unsortedArr);
$n = $n-1;
if($n > 0) {
return sortArray($unsortedArr, $n);
} else {
return $unsortedArr;
}
}

?>

TCP/IP

Today i started to learn python cgi. In the begining, i had to know the network concepts like how data are transferred over the network. I got clear idea about TCP/IP(Transmission Control Protocol/Internet Protocol), that is, It is a rule to be followed for transferring data over internet. First data are divided into small packets and packed with relevant information and IP assigns destination address to each packets

Now all packets are no need to follow the same path. Router will direct the packets to manage data traffics over internet to reach its destination.

And there are different type of HTTP requests GET, POST, PUT, CONNECT, TRACE, DELETE, HEAD, OPTIONS.

CGI – Common Gateway Interface

It is external program to a web server which process the client requests and return respective results.
CGI Concept and Processing Steps :
1. Client sends requests
2. Server receives requests
3. Contacting external program called CGI script
4. CGI script process client data and returns the result to server
5. Server serves response to Client

It can be written in Ruby, Python, PHP, Perl. CGI mostly uses GET and POST.

I got tired to configure the apache server to make working python file. Finally, i succeeded to work with python cgi.

These are all the steps which i did,

First i created folders /var/www/python/cgi-bin/ and changed folder permission

as $ sudo chmod -R 777 /var/www/python

Then i created this test file to check in the browser and saved it as index.py in cgi-bin folder

#!/usr/bin/python
print “Content-Type: text/plain\n\n”
print ‘python works’

And i added the cgi-bin directory path in /etc/apache2/httpd.conf file as follows:

<Directory “/var/www/python/cgi-bin”>
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

<Directory “/var/www/python/cgi-bin”>
    Options All
</Directory>

          If cgi-bin directory path is not set, apache will throw 403 Forbidden error, that means, either you dont have enough permission or this folder is not having 777 permission. Next is, restarting apache server sudo /etc/init.d/apache2 restart to reflect the changes in server.

               Now i tested the index.py file, It downloaded the python file instead of opening in browser. This is where i got stuck to go ahead. I googled and tried to fix the solution. After struggling more than one hour, i found that browser is not recognized the the cgi script file.

        It means that some configuration is missing for setting up MIME type in apache server.  The actual file to be configured is mime.conf in /etc/apache2/mods-enabled/mime.conf. I just uncomment this line

AddHandler cgi-script .cgi

and add .py at the end of this line to look like

AddHandler cgi-script .cgi .py

Now restart your server $ sudo /etc/init.d/apache2 restart and run the index.py file in browser.

Cheers,

FATAL ERROR: MODx Setup cannot continue.

To use PHP 5.3.0+, you must set the date.timezone setting in your php.ini. Please do set it to a proper timezone before proceeding. A list can be found here

Read the rest of this entry »

As i mentioned before about my project using pygtk and glade, it is now been completed.

Project Description :
This application is applicable to retail business. You can import your Product details in your business into the database. It has different modules User Management, Product Management, create stock details, Billing, Report automation and Production and Sales report etc.,

Features:
It provides stocks details and sold product details and Report Automation on the daily basis. User can be created by admin with some restriction. Product can be added to database by admin.

I hosted my project in code.google.com : http://code.google.com/p/py-retail/

Here is screenshots :

Python 2.7 Vs Python 3.1

Date : 06/02/2011

Place : KanchiLUG Meet

I explained some new features added which was been lacking in Python 2.7 to the Python 3.1 at KanchiLug weekly meet. I gave the demo using both Python 2.7 Interpreter and Python 3.1 Interpreter about those features such as output of divisonal operator, file object creation, dictionary’s ordered list, Indentation exceptional error, format specifier etc., To know more details of the new features in Python 3.1, use this link New Python 3.1 Features

Booming GNU/Linux,

செல்வமணி.  ச

Place : Birla Planetarium, Chennai.

Date   : 30/12/2010.

Mr. Lenin, authority of Birla Planetarium, organized one hour FOSS(Free/Open Source Software) session with Students(7th Standard to 9th Standard) on Dec 30 2010. Mr. T. Srinivasan asked Dhastha to conduct this session. I got this message from Dhastha to accompany him.  This program was arranged only for the Students. I met Dhastha at there. The session started exactly at 10am. There were around 60 people.  At the beginning what I thought is “All were looking small, so they don’t know anything about Operating System. So It will take so hard to make them clear understand about Linux”.To make this session very useful to the students, before we started we got some information from them to know their knowledge of computer. Everyone had experience with Windows. Their knowledge about computer was so helpful and saved our time to reach our points easily.

I and Dhastha started to talk with student with the as usual story of Ritchard M Stalman and Linus Torvalt. Everyone  impressed with Linux. We showed them Ubuntu and its compiz features. Then we played BigBugBunny animation clip. All kids enjoyed this.

Next question session. Followings are some question, which We never expected from them

1. At the session I explained about kernal orally. 8th standard student asked us that ” How can I see the source code of kernal?”. Thats it, a few moment I was kept silent.

2. How can I install linux in my system?

3. Where can I get help regarding linux?

4. Some kids said, can you give your mobile number? I will call you with my dad, and elder brother and explain about linux to them.

5. How to play games?

6. One student asked me a critical question that is “Linux is a free OS and have all kinds of softwares, then Why it is not famous. I mean why we dont know about linux?

7. Will Linux affect by virus?

That was really amazing.

At the end of the session, we met another unexpected incident. Some kids came forward to asked us “Autograph”. What to say? That was my memorable day..

Booming GNU/Linux,

செல்வமணி. ச

You can commit you project using subversion as follows:

svn commit -m “Your comment here for your modification on the project” –username <gmailusername>

Then the following prompt should be opened for commiting your project successfully…

Password for ‘<gmailusername>’:

For this password, you should give your code.google.com password assigned to you while hosting your project.

First time commiting project using svn commit will work properly.

If you are commiting your project next time, you can get the prompt like

Password for ‘(null)’ GNOME keyring:

which means, Multiple keyrings are present on a users system. All users will have a default keyring, and another which is only stored in memory. For each commit, gnome-keyring stores the user details in another keyring. To disable this, open the config file in the subversion from the home folder as follows:

selva@selva-laptop:~$ cd .subversion/

selva@selva-laptop:~$ ls

auth  config  README.txt  servers

open the ‘config’ file with any text editor,

selva@selva-laptop:~/.subversion$ gedit config

inside the text file, look for the line ‘password-stores = no’ under ‘[auth]’ section and uncomment it & remove the value ‘no’ for it to look like ‘password-stores = ‘. Then, save and close config file.

Finally, open another file named ‘servers’ in text editor,

inside the text file, look for the line ‘store-passwords = no’ under ‘[global]’ section and just uncomment it. Then, save and close ‘servers’ file.

That’s it. Now, you can commit your project anytime with the code.google password assigned to you.

 

Booming GNU/Linux,

செல்வமணி. ச

I  discussed about Glade to the new luggies to Kanchi LUG.

Around 10 people attended the class.

Introduction : Glade is a GUI interface to design front end application and its specialty is that it can be bound with any languages ( C, C++, Ruby , Python , Java) .

I showed a live demo for the widgets available in glade like toplevels, containers, controls and display and some miscellaneous widgets and its use in application. And I explained about how to make front end design.

I used python language as a backend. I taught that how to connect the Glade file with python through GTK(Gnome Tool Kit) called ‘PYGTK’. I created a sample Hello world program in gtkBuilder format and made connection using pygtk with it.

Here you can view the file attached.

Glade design in gtkBuilder format and Pygtk

Boomin GNU/Linux,

செல்வமணி. ச