Friday, March 13, 2015

[CentOS][Ruby]How to Change the default Sinatra listening port 4567 to a user define port in ruby applications?

Recently I have come a cross a situation where I wanted to up 3 different ruby web applications at once on the CentOS server which uses the Sinatra. When I was trying to run the first application by running the ./application1.rb, I was able to access the service in the 4567 port. While it was running I tried the second application by running ./application2.rb command. Then it gave the error regarding the port is already in used. 

So that is acceptable. Because we all know the same port can not listen to two different applications at the same time. And according to my requirement I needed to run different ruby applications at the same time. So my target was to separately define different ports to each. So that I can use them without any interruptions. So how I achieved that?? I searched the web for the required details. 
The very first thing I wanted to find out was, where these default configuration details come from. So I got the result. 

The default Sinatra configuration details are put in the base.rb file. Once I checked that I have found out that the default port was set as 4567 as shown in the following figure.


So I have checked the application1.rb file and added a new line to change the default port to a port I preferred as follows.
"set:port, 4568"
That is to overwrite the default ruby listening port by introducing custom port number. And I checked the output by running the application1.rb file. Yay !! :D. It was running with the port I have defined. So I added different ports to other files as well. And now all the services are up and running in the ports I wanted. :) Hope this will help for someone else too !!! :)


Cheers!
"do good and good will come to you!"'

Tuesday, March 10, 2015

[CentOS]How to overcome the issue of remotely access Python application running using the Flask?

Well. This is regarding an issue once you may get when you try to run a python program which uses the framework flask. :D 

Do you know about Flask??

Flask is a micro-framework for web development using python

You can read more from here: http://flask.pocoo.org/docs/0.10/

And my problem was accessing the service up and running using flask. Actually the application was up and running in the http:0.0.0.0:5000/. 

But I was unable to access it using the server ip. That is, I was unable to access it remotely. So I have surfed the web for a solution. After trying out different methods I was able to resolved my problem. And it was a simple change to the code. Just changed the call for the run method as follows. 

app.run(host='0.0.0.0')

And it worked as expected. !! So hope this will help some one else too!! :)


Cheers!
"do good and good will come to you!!"

Wednesday, March 4, 2015

[CentOS]Installing Ruby on CentOS

This time it is installing Ruby on CentOS :D. Yes. I did it. And I want to share the steps I have followed with you all !! :) :)

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
tar xzvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
 ./configure
 make install

Done !! And I tried to run a ruby script and it gave the error related to permission to the file.
So I have changed the permission for that file as folows,

chmod +x hello.rb

Cheers!
"do good and good will come to you!"

Tuesday, March 3, 2015

[CentOS]Installing mysql-server

Lets talk about how to install mysql-server on CentOS. I wanted to install it and following describes the steps I have followed. 

sudo yum install mysql-server

But it gave an error :(

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

I didn't give up. I have checked the reasons for why I was getting that particulate error and found out that, it was because outdated certificate. So I used the command for upgrading the certificate. 

sudo yum upgrade ca-certificates --disablerepo=epel

And tried the previous command for installing again and it worked. :) I checked it by starting the mysql service like this.

sudo service mysqld start


Cheers!
"do good and good will come to you!"

[CentOS]Starting Apache server gives error -"Could not reliably determine the server's fully qualified domain name"

Did you ever come a cross a situation of getting this error??
I got :) Actually I have installed Apache on a CentOS server and I wanted to start it. So I used the following command on a Putty, i.e the SSH Client I have used to connect to the server. 

cmd -> sudo service httpd restart

output ->
Stopping httpd:                                 [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 10.157.1.134 for ServerName
                                                           [  OK  ]

So I was unable to start the Apache server. So I checked why I got this error. And I again tired for the command httpd, to check whether the server can identify the service,

cmd -> httpd

output -> httpd: Could not reliably determine the server's fully qualified domain name, using
10.157.1.134 for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

According to the error message I got, it pointed out the error, that is, it can not determine the domain name. So I have checked the Apache httpd.conf  file. 

cmd -> vim /etc/httpd/conf/httpd.conf

And checking through it, I have found out that there was actually no qualified server name under the section #ServerName . So I have added the server name i wanted and it was like this. 

previous -> #ServerName www.example.com:80
new -> ServerName 10.157.1.134:80

And I have tried the Apache restart command again and it  worked as expected. :) 

cmd -> /etc/init.d/httpd restart

output -> 
Stopping httpd:                                          [  OK  ]
Starting httpd:                                            [  OK  ]


Hope this will help some one else too !! :)


cheers!
"do good and good wi come to you!"




Monday, March 2, 2015

[CentOS] It is Yummy !! All about "yum" Command :D

Yes. It is new to me. It is all about the yum command. I wanted to post it here because this yum command helped me a lot recently. So that is why I am here to share my knowledge with you. You may have used it too. It is an important command for users who are working on Linux based platforms such as RHEL , CentOS.

"yum" is abbreviated from the "Yellowdog Updater, Modified". It is an open source command line package management utility for Linux operating systems using the RPM Package Manager. yum works with software repositories. And those repositories can be accessed locally or over a network connection.

1) How to use yum command for install packages?

yum [options] [command] [package ...]

eg: yum install -y nodejs

This yum install command can be used  to install the latest version of a package while ensuring that all dependencies are satisfied.

2) How to use yum command for upgrade packages?
sudo yum upgrade ca-certificates --disablerepo=epel          


You can read more on here:

Reference:

Cheers!
"do good and good will come to you!!"

[CentOs]How to find out information about the Kernal

As Software Engineers, you may come across situations of working on different Operating Systems. When you get a task of installing different software to a newly setup operating system, which is not the operating system you used to work on, you have to learn new things. So I had, and it was with CentOS, So I am here to share the things I have learnt from playing with CentOS with you. :)

What is CentOS?
Do you know about this OS? This was the first time I worked with CentOS. The name is abbreviated from "Community Enterprise Operating System". And it is a community-supported Linux distribution for enterprise class. Simply it is kind of a compatible version of Read Hat Enterprise Linux(RHEL). 

The very first thing I wanted to do was to know about the OS. Since it was a separate server, I had to use SSH client Putty for logged to the server. Then I wanted to check the information of the installed OS. And what I have found out and checked it out as follows.

1) How to find the kernel name ? 
(-s)
cmd# uname -s
Linux

2) How to find the Network node hostname ?
(-n)
cmd# uname -n
abc-vm

3) How to find the kernel release ?
(-r)
cmd# uname -r
2.6.32-220.el6.x86_64

4) How to find the kernel version ?
(-v)
cmd# uname -v
1 SMP Tue Dec 6 19:48:22 GMT 2011

5) How ti find the machine hardware name ?
(-m)
cmd# uname -m
x86_64

6) How to find the processor type ?
(-p)
cmd# uname -p
x86_64

7) How ti find the hardware platform?
 (-i)
cmd# uname -i
x86_64

8) How ti find the operating system ?
(-o)
cmd# uname -o
GNU/Linux

Hope this will help some one else too !! :)


Cheers
"do good and good will come to you!"


Thursday, February 19, 2015

How to download an excel file with the correct extension

Recently one of my friends asked me about, did you notice any issue with downloading excel files from one of the web applications that we have used?
I said, no actually, since I haven't recently tried it.:D 

And his problem was that, excel files were not downloading with the correct extension in some browsers. So that he cannot open it with MS-EXCEL. I was so sure about that, since it worked for me before. Anyway since he asked I have checked it again.

Oh no, the issue is there too. :o

I have checked with other browsers as well. Oh yeah, it was working fine with IE. And sadly not with firefox. Since I knew that there were no any recent changes with the code and this functionality had worked fine before, I wanted to inspect the elements in the web application. So I have monitored it and found out the fact.

I knew that inorder to set up the file extension for a .xls format in the response header the value for the 'content-type' attribute should set as "Content-Type:application/vnd.ms-excel". And it was Ok. 




And I have checked the content-disposition and I have noticed that the file name is there, but not the extension. So I have added the change and then the application worked fine. I just added the ".xls" extension to the end of the file name for the value of content-disposition attribute in the code level. And this is how it appeared after the changes.



Since this solution worked fine and actually it saved my time and his too, I wanted to share this with others. So I hope this will help for someone else too.!! :)



Cheers
"do good and good will come to you!!"

Sunday, February 15, 2015

Oracle DB Triggers

Recently I have come a cross a task of writing a DB Trigger. My requirement was to save some intermediate data in to a new table. Instead of changing the code for saving those data to a new table, I used the method of recording those data using a db trigger to the relevant table. That was again a new experience for me. So I am sharing the things I have learnt with you all !!:)

Do you know about db triggers ? What is a db trigger ?


I am using one of the available definitions in the web for define the db trigger. 
"Oracle allows you to define procedures that are implicitly executed when an INSERT, UPDATE, or DELETE statement is issued against the associated table. These procedures are called database triggers." Hope you can get the idea.

When I surf the web for more information I have found out more facts about triggers.

What are the parts of  a typical db trigger ?

Mainly there are 3 parts of the db trigger.

1. Triggering Statement
2. Trigger Restriction
3. Trigger Action



What is Triggering Statement ?

A triggering statement is the SQL statement that causes a trigger to be fired. This Triggering Statement can be an INSERT, UPDATE or DELETE statement on a table.

What is Trigger Restriction ?

A trigger restriction specifies a Boolean expression that must be TRUE for the trigger to fire. 

What is Trigger Action?

A trigger action is the procedure (PL/SQL) that contains the PL/SQL code to be executed when a triggering statement is issued.

What are the available types of Triggers ?

There are 2 types of Triggers.  So I have to find out which one suites for me in this case. I searched for them. 

There are two types of triggers as follows.
1. Row Triggers
2. Statement Triggers

What is Row Level Trigger?


A row trigger is fired each time the table is affected by the triggering statement.

When to use Row Level Triggers?

A row trigger is useful if the code in the trigger action depends on data provided by the rows that are affected.

What is Statement Level Trigger?

A statement trigger is fired once on behalf of the triggering statement. There is no concern about the number of rows in the table that the triggering statement affects

When to use Statement Level Triggers?

Statement triggers are useful if the code in the trigger action does not depend on the data provided by the triggering statement or the rows affected.

According to my requirement. I had to use the Row Level Trigger. Because I wanted to apply the code inside the triggering action to be executed for each row.

Next was to choose one from BEFORE or AFTER Triggers. Because when defining triggers we can specify the time, that is when to fire the trigger action.

What is this BEFORE Trigger?

As it name implies, Before trigger executes the trigger action before the triggering statement. Actually this types of triggers helpful to derive specific column values before executing the triggering statement.

What is AFTER Trigger?

After trigger executes the trigger action after the  triggering statement.  

According to my requirement I have to choose the After Trigger. So I have designed the skeleton of my trigger as follows.

CREATE OR REPLACE
    TRIGGER MY_FIRST_DB_TRIGGER AFTER
    INSERT OR
    UPDATE OR DELETE  ON TRIGGER_ON_TABLE 
    FOR EACH ROW
    DECLARE        
    -- define parameters here
;

   BEGIN
        
   IF inserting THEN    
     
     -- logic that should execute for the inserting event
        --INSERT INTO NEW_TABLE (column_1, column_2)
           --VALUES (:NEW.ID, :NEW.NAME );

    ELSIF updating THEN
   
    -- logic that should execute for the updating event
    ELSE
   
     -- logic that should execute for the deleting event
   
    END IF;
    END MY_FIRST_DB_TRIGGER;


How to access the column values in Row Triggers?


Within a trigger body of a row trigger, the PL/SQL code have access to the old and new column values of the current row affected by the triggering statement. So that you can access the new value for the row is being created as :NEW and the already available column value as :OLD. 

Actually in this case,
* If the trigger has fired by an INSERT statement has meaningful access to new column values only and the old values are null. Because there is only the :NEW value for the row being created.
* If the trigger has fired by an UPDATE statement has access to both old and new column values.
* If the trigger has fired by a DELETE statement has access to :OLD column values only.


Cheers
"do good and good will come to you !!"

Wednesday, February 4, 2015

dbms_scheduler.create_job

Do you know that you can create Schedulers running in db level? Yes. We can create them. Recently I have come a cross a situation, where I had to create a oracle db level scheduler. Requirement was to periodically searching for modified data using a complex query and inserting them to another table. The same thing can be achieved using a application level scheduler job, but we moved to the db level solution. And it was a new experienced for me. So I am ready to share the knowledge I gathered with that task with you !!

BEGIN
dbms_scheduler.create_job (
job_name=> 'Rep_data_pumping',
job_type=> 'STORED_PROCEDURE',
job_action=> 'pumpRepData',
number_of_arguments=>0,
start_date=> TO_DATE('2015/02/07', 'yyyy/mm/dd'),         
repeat_interval=> 'SYSTIMESTAMP + INTERVAL '30' MINUTE',
end_date=>NULL,
job_class=> 'DEFAULT_JOB_CLASS',
enabled=>TRUE,
auto_drop=>FALSE,
comments=>     'pump rep data periodically');
END;
/

This creates the job named Rep_data_pumping which executes the stored procedure named pumpRepData.  And this will be starting on February 07th and then it runs in every 30 minutes. And this job is enabled. You can use the following commands for different actions as described. 

1. How to run a job manually?
call the dbms_scheduler.run_job procedure and the job will start immediately. 

BEGIN
dbms_scheduler.run_job(job_name=> 'Rep_data_pumping');
END;
/

2. How to stop a running job?
call the  dbms_scheduler.stop_job procedure and the job will stop the running job.

BEGIN
dbms_scheduler.stop_job(job_name=> 'Rep_data_pumping');
END;
/

3. How to disable the job?
call the  dbms_scheduler.disable procedure and the job will disable. One thing to note, if the job is running you will get an error. You must first stop the job and then try to disable the job

BEGIN
dbms_scheduler.disable(job_name=> 'Rep_data_pumping');
END;
/

4. How to enable the disabled job?
call the  dbms_scheduler.enable procedure and the job will enable.

BEGIN
dbms_scheduler.enable(job_name=> 'Rep_data_pumping');
END;
/

5. How to drop a job?
call the  dbms_scheduler.drop_job procedure and the job will drop. And again if the job is runing you will get an error. First stop the job and then drop it.

BEGIN
dbms_scheduler.drop_job(job_name=> 'Rep_data_pumping');
END;
/

Hope you can schedule the next job in db level!! :) :)

Cheers!!
'do good and good will come to you'




Why PATH :..;%JAVA_HOME%\bin;?

It is all about setting up PATH variable for JAVA_HOME with some interesting facts. I had some questions about things related to this topic long time ago. And I wanted to share the things I have found out related to the topic with you all.


1. What is this variable 'PATH' ?
  • It is the system variable that operating system uses to locate the required executables from the command line. 
  • The value assign for that is series of directories separated by semicolons. 
2. Is it necessary to setup PATH variable once we have installed the jdk ? and Why ?
  • Actually it is not necessary, but it is convenient for us :)
  • If you do not set the PATH variable, you need to specify the full path to the executable every time you run it.
  • If you do set the PATH variable you can conveniently run the executables from any directory without typing the full path in the terminal.  
3. Why we set the path for the JAVA to the 'bin' directory in jdk installation ?
  • Because Java compiler and interpreter executables are placed in the 'bin' directory. So that Windows can find them. 

4. How can we setup PATH variable for java in Windows??
  • Select Start -> Computer -> System Properties -> Advanced system settings -> Environment Variables -> System variables 
  • You can introduce new System variable as JAVA_HOME and give the path to the jdk or you can edit the PATH variable it self. I used the first method.


  • Then select the PATH system variable and add a semicolon to the end of the existing value and then put the %JAVA_HOME%\bin as follows.
  • Finally check that you have setup it correctly, type the java -version in the terminal and check the installed jdk version details. 
  • Now you are done with the setting up PATH for the JAVA_HOME.Go home safely and play with JAVA !! ;)


Cheers!!
'do good and good will come to you'


How to display output using DBMS_OUTPUT.PUT_LINE() in SQL Developer

This was a problem I have faced sometimes back, where I wanted to display output messages from the DBMS_OUTPUT.PUT_LINE() function, when I executing a PLSQL function using the SQL Developer. 

The line I used is as follows,

DBMS_OUTPUT.PUT_LINE('An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);

Once I called the function no output displayed anywhere in the SQLDeveloper. I was thinking what happened to the output. But I wanted to see the output so badly. So I searched for that and found the solution for that. So I am sharing it with you all.:)

1. Step: You have to 'Enable' the "Dbms output" functionality in the SQLDeveloper. 
Select View -> Dbms Output, click 'Enable'.


Now you can see the Dbms Output is enabled as follows.


2. Step: Run the script and see the output. :)

And also this panel gives you the chance of changing the buffer size. The default buffer size is 20000 characters and you can increase it. 

Hope this will help anyone who are wondering about what happened to the output line you put in 
DBMS_OUTPUT.PUT_LINE("You just wait output. I can see you now :D :D!!! ")

cheers !!
'do good and good will come to you'



Reply for "In Appreciation"

I would like to share my first blog post with the thoughts, which are freely flown through my mind. Hope this is a good day to start writing freely, because today is the 67th Independence Day of my country.:)
I thought to start my blog with one of the nice memories of my work place.  Actually this was a good starting for the year 2015. Even though I wanted to start posting to the blog since long time ago, it delayed with different reasons. And this is the trigger which fired to motivate me for start this as well.
It was one of the memorable days for me, hopefully for other team members as well. It was 2nd of January 2015 and was a normal working day. Most importantly a beautiful Friday ;) We got an email saying that we all have a meeting at 10.30 am. And we went to the conference room at 10.30. All of the members of my team were sitting around the table and curiously waiting for the presentation. And our most senior personal of the team started the presentation with an introduction. He wanted to appreciate each individual for the contribution they have put for the success of the project throughout the last year.  And he said that he is going to use 3 words for each and he will not repeat those for any other.
It was a presentation with one slide for each with a fun picture of that person and the 3 words that describes that person.  It was so nice to hear such a senior person describing about each and every junior members of the team and appreciating their efforts.  Not only it was a presentation with full of fun but also it was so touching meeting as well. It was really a wonderful way of appreciating others and thanking others. So this is how he described me with one of my crazy photographs. :D



Finally that wonderful presentation ended up with a piece of delicious cake that he bought himself for all of us. I left the conference room with the determination of adding different 3 words for me at the end of this year !!.
Even though I have different milestones to achieve throughout this year, I am keeping that promise to myself, because I know that will anyway help for my career path and also my personal life in future wherever I go. 


Thank you !!

Cheers !!
'do good and good will come to you'