Wednesday, May 1, 2013

Passing Parameters to Perl DBI Queries

When we run SQL Queries in Perl using DBI Module, the below mentioned code will prepare and execute the query. This will prepare the query every time, the query is executed.
This will increase the total execution of the script.


Psuedo Code: 
my $dbh = DBI->connect($dbname,$dbuser,$dbpass);

while(<INPUT>)
{
    my $my_emp_id = chomp;
    my $query = "select emp_id,emp_name,dept
                from emp_table
                where
                emp_id = '$my_emp_id'";
    my $query_handle = $dbh->prepare($query) or die print "Error in Query";
    $query_handle = $dbh->execute();
    while(my @result = $query_handle->fetchrow_array())
    {
        print OUT "@result\n";
    }
    $query_handle->finish()
}


The above mentioned issue can be handled by preparing the query once and passing the variable in the query dynamically.

my $query = "select emp_id,emp_name,dept
from emp_table
where
emp_id = :p1";
#Passing the parameter to the Query as :p1. if more than one parameters are to be passed :p2. :p3 can be used.

 
my $dbh = DBI->connect($dbname,$dbuser,$dbpass);
my $query_handle = $dbh->prepare($query) or die print "Error in Query";
#passing the value of the parameters passed as :p1

 
while(<INPUT>)
{
    my $my_emp_id = chomp;
    $query_handle = $dbh->execute($my_emp_id);
    while(my @result = $query_handle->fetchrow_array())
    {
        print OUT "@result\n";
    }
    $query_handle->finish()
}

I hope this is informative.

OBIEE 10g and 11g Training Program

Hi Fellas,

For a Very Good Training Program on OBIEE 10g and 11g by an Expert Trainer. Follow OBIEE Training

Hope you all have a good time..! 


Wednesday, September 5, 2012

RAM: A small buying Guide

I recently bought a RAM for my laptop and really had troubles finding the right one. So, This is a short guide about RAM. How can you shop for RAM if you don’t even know what it is? Random Access Memory is a form of computer storage. It’s like your hard drive in your computer, but smaller and much, much faster. The part that makes it “random” is the fact that any data stored at any location can be accessed in constant time, meaning you don’t have to wait for the data to be found or for it to travel some distance to be read.

RAM is like, if your computer needs some piece of information it doesn’t waste time traveling to the address and getting the information, it can just get it. And no address in RAM is “closer” to its destination than another, for instance, the left side of the RAM chip isn’t read or accessed any faster than the right.

Also, your computer needs RAM to be able to even boot or do any task.

DDR (1,2, & 3) SDRAM – Double Data Rate Synchronous Dynamic Random Access Memory

These are the RAM's that one is going to look for when he is going to buy one for his/her desktop or laptop. Though laptop RAM's are smaller than desktops they also have one SO-DIMM type specifications.

DDR1

Standard Name  Memory      Clock Data Transfers/s         Module Name     Peak Transfer Rate
DDR-200  100 MHz 200 Million         PC-1600 1600 MB/s
DDR-266  133 MHz 266 Million         PC-2100 2100 MB/s
DDR-333  166 MHz 333 Million         PC-2700 2700 MB/s
DDR-400  200 MHz 400 Million         PC-3200 3200 MB/s

DDR2

Standard Name Memory Clock Data Transfer/s Module Name Peak Transfer Rate
DDR2-400 100 MHz 400 Million PC2-3200 3200 MB/s
DDR2-533 133 MHz 533 Million PC2-4200 4266 MB/s
PC2-4300
PC2-5300
DDR2-667 166 MHz 667 Million PC2-5400 5333 MB/s
PC2-6400
DDR2-800 200 MHz 800 Million PC2-8500 6400 MB/s
DDR2-1066 266 MHz 1066 Million PC2-8600 8533 MB/s

DDR3
Standard Name Memory Clock Data Transfers/s Module Name Peak Transfer Rate
DDR3-800 100 MHz 800 Million PC3-6400 6400 MB/s
DDR3-1066 133 MHz 1066 Million PC3-8500 8533 MB/s
DDR3-1333 166 MHz 667 Million PC3-10667 10667 MB/s
DDR3-1600 200 MHz 1600 Million PC3-12800 12800 MB/s

As you can see as the DDR level increases the Transfer rate increases. The better the DDR level the better the performance of the computer.
But Remember, your computer can support only one type of RAM. Before going to buy check what type of RAM does your system have and the same you can buy.

SO-DIMM (Laptop RAM)
SO-DIMM memory has the same specifications as regular DDR desktop memory except for the fact that SO-DIMM is smaller. Because of it’s smaller size it’s used in laptops and net-tops (like the Mac Mini). DDR1 and DDR2 SO-DIMM modules have 200 pins, whereas DDR3 SO-DIMM has 204.
NOTE: DDR1 and DDR2 SO-DIMM modules are not interchangeable, and the layout of the pins on the module prevent you from installing it into the wrong system.

Important Thing to know:
Windows XP (and other 32-bit operating systems) can only use 4GB’s of memory. This means 4GB’s of memory in the entire system. This includes your graphics card and any other peripherals that use even the slightest bit of memory.

This becomes a problem if you’re still hanging on to Windows XP but want a super-duper fast graphics card. Some graphics cards now have 1GB or 1.5 GB’s of video RAM, which means that will be taken out of the total 4GB’s that XP can address.

The answer: get a 64 bit operating system like Windows Vista x64 or Windows 7. Keep this in mind if you’re wanting lots of RAM but also wanting XP; there’s a tradeoff.


Wednesday, August 22, 2012

Web Infrastructure on Cloud





Hey Developers out there, if you are searching for a reliable server to host your applications. Here is a small help for all of you.

1. Cloudbees
2. Jelastic
3. Redhat openshift
4. Google Appengine
5. Amazon EC2

The importance of using a hosting service is that you don't have to worry about managing servers and resources. These hosting services provide autoscaling to your services, of-course there is some cost involved but at-least your services are up and running at all times without any type of congestion.

One can choose on variety of platforms like unix, windows or linux. You can choose if you need any relational DB. Generally My-SQL is present with all the vendors. Amount of disk space, max RAM utilization can be chosen but are generally based on pricing slot selected.

Well established services like redhat openshift, google appengine and amazon ec2, which are the pioneers of the cloud services guarantees 99.999% uptime.

Pricing:
Presence of small as well as big players in the market has led enormous competition. The prices are competitive. Prices are based on amount of computing power utilized by the application. The prices are as low as $0.0139 for small applications and as large as $1.477 per hour for high I/O instances on Amazon EC2.

Some other local services might provide you more competitive pricing yet they might have a lot of hidden charges, also they will not be able to provide you with a guaranteed 99.999% uptime.


Thanks Pratikabu for your insight information and feedback.

Please mention your feedback.

Monday, July 9, 2012

Move Gmail attachments to GoogleDrive

With Google now providing free space on Google Drive, on may want all the Gmail attachments that is gets on his email or that he already have on to Google Drive. This post explains a simple and fairly easy way to do that.

Prerequisites

If you would like to have a similar setup for your Gmail and Google Drive, all you need is a minute. Just follow these easy steps:
  1. Assuming that you are logged in to your Google account, create a copy of this sheet in your Google Docs (now Google Drive).
  2. Go to Gmail create a Label "GoogleDrive" to filter only emails that has attachments. Also, you will need to create a folder in the GoogleDrive with the name "Gmail". Please make sure that the names are correctly spelled.
  3. Open the sheet and you should see a new Gmail menu – click Initialize and grant the necessary permissions. This is your sheet (see source code) and you are not sharing your Google credentials or data with anyone else.
  4. Next go the Gmail menu again and select Run. Close the Google sheet and you are done.

Background Work

Here’s how the program works. The Google sheet will monitor your Gmail mailbox in the background (every two minutes) and as soon as it finds any message that has a label GoogleDrive, it will automatically save all the attachments in that message to the Gmail folder on your actual Google Drive.
Once the basic setup is ready, apply the label GoogleDrive to any of your email messages in Gmail and the attached files should become available in your Drive (both online and offline) in the next few minutes.

Troubleshooting

If you are getting errors like “Service invoked too many times,” you can increase the trigger duration. Open the same sheet in Google Docs, go to Tools – > Script Editor and then choose Resources – > Current Script Triggers. Change the value of Minutes timer from “Every 5 minutes” to say “Every 15 minutes”.
If you would like to stop the script from running in the background, go to the same trigger screen and simple delete the “SendToGoogleDrive” time trigger.

Friday, June 1, 2012

VI Editor: Cheat Sheet

In this post I am giving a cheat sheet of VI editor. I found it very useful, hope everyone finds it useful too.


Quitting
:x Exit saving changes 
:q Exit as long as there have been no changes 
ZZ Exit and save changes if any have been made
:q! Exit and ignore any changes 

Inserting Text
i  Insert before cursor 
I  Insert before line 
a  Append after cursor 
A  Append after line 
o  Open a new line after current line 
O  Open a new line before current line 
r  Replace one character 
R  Replace many characters 

Motion
h  Move left 
j  Move down 
k  Move up 
l  Move right 
w  Move to next word 
W  Move to next blank delimited word 
b  Move to the beginning of the word 
B  Move to the beginning of blank delimted word 
e  Move to the end of the word 
E  Move to the end of Blank delimited word 
(  Move a sentence back 
)  Move a sentence forward 
{  Move a paragraph back 
}  Move a paragraph forward 
0  Move to the begining of the line 
$  Move to the end of the line 
1G  Move to the first line of the file 
G  Move to the last line of the file 
nG  Move to nth line of the file 
:n  Move to nth line of the file 
fc  Move forward to c 
Fc  Move back to c 
H  Move to top of screen 
M  Move to middle of screen 
L  Move to botton of screen 
%  Move to associated ( ),  { }, []

Deleting Text
Almost all deletion commands are performed by typing d followed by a motion. For example,  dw deletes a word. A few other deletes are:
x  Delete character to the right of cursor 
X  Delete character to the left of cursor 
D  Delete to the end of the line 
dd  Delete current line 
:d  Delete current line 


Yanking Text
Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:
yy  Yank the current line 
:y  Yank the current line 


Putting text
p  Put after the position or after the line 
P  Put before the poition or before the line 

Search for strings
/string  Search forward for string 
?string  Search back for string 
n  Search for next instance of string 
N  Search for previous instance of string 

Replace
The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).
:s/pattern/string/flags Replace pattern with string according to flags. 
g Flag Replace all occurences of pattern 
c Flag Confirm replaces
& Repeat last :s command 
:.=  Shows current line number 
:=  Shows number of lines in file 


VI Settings
Note: Options given are default. To change them, enter type :set option to turn them on or :set nooption to turn them off.To make them execute every time you open VI, create a file in your HOME directory called .exrc and type the options without the colon (:) preceding the option Set Default Description
:set ai noai  Turns on auto indentation 
:set all  Prints all options to the screen 
:set ap aw  Prints line after d c J m :s t u commands 
:set aw noaw  Automatic write on :n ! e# ^^ :rew ^} :tag 
:set bf nobf  Discards control characters from input 
:set dir=tmp dir = /tmp  Sets tmp to directory or buffer file 
:set eb noed  Precedes error messages with a bell 
:set ed noed  Precedes error messages with a bell 
:set ic noic  Ignores case when searching 
:set lisp nolisp  Modifies brackets for Lisp compatibility. 
:set list nolist  Shows tabs (^l) and end of line ($) 
:set magic magic  Allows pattern matching with special characters 
:set mesg  mesg  Allows others to send messages 
:set nooption   Turns off option 
:set nu nonu  Shows line numbers 
:set opt opt  Speeds output; eliminates automatic RETURN 
:set prompt prompt  Prompts for command input with : 
:set re nore  Simulates smart terminal on dumb terminal 
:set ro noro  Changes file type to "read only" 
:set scroll=n scroll = 11  set n lines for CTRL-d and z 
:set showmode nosm  Indicates input or replace mode at bottom 
:set sm nosm  Show matching { or ( as ) or } is typed 

Saturday, May 12, 2012

Set Default OS in Fedora 16

This is for dual boot OS users, there are many who prefers dual boot to keep another OS optional. For any reason if you wish to change boot sequence unlike grub, grub2 requires couple of commands to run.

Here will take example to keep Windows as default boot.
First of all find menuentry for Windows

#cat /boot/grub2/grub.cfg |grep Windows
the output will be:

menuentry "Windows 7 (loader) (on /dev/sda1)" --clas-clss window -ass os {

To set Windows menuentry as default (only entry mentioned in either " or ' from above command)
I had problem using doubble quotes in the command line. The problem was resolved when in changed the keyboard type from "US" to "US(Engish)" using


#system-config-keyboard

To set Windows menuentry as default (only entry mentioned in either " or ' from above command)

#grub2-set-default "Windows 7 (loader) (on /dev/sda1)"

Verify default entry

#grub2-editenv list

Generate updated grub.cfg

#grub2-mkconfig -o /boot/grub2/grub.cfg

If you get grub error "Environment block too small" then:
#rm -rf /boot/grub2/grubenv
and then rebuild it using
#grub2-editenv /boot/grub2/grubenv create


Now follow all the above steps.