12 Nov

How to Get Stock Quote on Linux using Google ,Curl, Grep, Awk

If you are a Stock Market Addict and a Techie; normally working on Linux(es); this post will interest you as you still can get quote of your stock on your Linux prompt.

Consider, we have Google Finance url for Tata Consultancy Services Stock: http://www.google.com/finance?q=NSE:TCS

So, how do you get above stock price while you’re on Linux / Unix server?
It’s a sinlge line command and you get your stock’s current price. :)

curl --silent -X Get "http://www.google.com/finance?q=NSE:TCS" > /tmp/ChangeIsInevitable && cat /tmp/ChangeIsInevitable | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'

This work for other Stock Exchanges like NYSE as well:

curl --silent -X Get "http://www.google.com/finance?q=nyse:goog" > /tmp/bgz && cat /tmp/bgz | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' && date
617.19
Fri Nov 12 17:07:52 IST 2010

and that’s it. Well, I’m thinking thinking more about further extensions of this.
Special thanks goes to: Jignesh Bhai, Google, Curl, Grep, Awk.

28 Oct

Installing MySQL On Mac OS X (Darwin Kernel)

Recently I happen to install MySQL on Mac OS X (Darvin Kernel).  Below are the quick 5 steps to accomplish the task.

Step 1: Check Mac Version
Very first step is to verify the Mac OS X’s current version to decide MySQL Installation file to be downloaded.
For example for Mac version: 10.4 you should download “Mac OS X 10.4 (x86, 32-bit), Compressed TAR Archive (mysql-5.1.51-osx10.4-i686.tar.gz)”

How to Check Mac Version:
cat /System/Library/CoreServices/SystemVersion.plist

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"

"http://www.apple.com/DTDs/PropertyList-1.0.dtd">

</p> <plist version="1.0"> <dict>

<key>ProductBuildVersion</key>  <string>8S2169</string>

<key>ProductCopyright</key><string>1983-2007 Apple Inc.</string>

<key>ProductName</key> <string>Mac OS X</string>

<key>ProductUserVisibleVersion</key> <string>10.4.11</string>

<key>ProductVersion</key> <string>10.4.11</string> </dict>

Installation Error:

dyld: unknown required load command 0x80000022

I ran in to problems while I installed MySQL for Mac OS X 10.5. Ofcourse I missed the step one and paid for it.
It’s about MySQL binary’s version difference errors: “dyld: unknown required load command 0x80000022″.

Step 2: Download MySQL Installation (tar.gz) file from dev.mysql’s download section.
For example go to: http://dev.mysql.com/downloads/mysql/5.1.html

Select appropriate OS & version and get the exact download link from mirror:

cd /usr/local/
wget http://dev.mysql.com/get/Downloads/
MySQL-5.1/mysql-5.1.51-osx10.4-i686.tar.gz/from/http://mysql.mirror.rafal.ca/

Step 3: Create MySQL User and Group.

Through command line we can use NetInfo Utility as:
niutil -create / /groups/mysql
niutil -createprop / /groups/mysql gid 401
niutil -create / /users/mysql
niutil -createprop / /users/mysql gid 401
niutil -createprop / /users/mysql uid 401

Assign password to “mysql” user
passwd mysql

Step: 4 Installing MySQL using Generic Binaries
cd /usr/local
tar -xzvf mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf

Step: 5 Start MySQL Server:

bin/mysqld_safe –user=mysql &

This finishes basic installation of MySQL on Mac OS X. Make sure you follow “best practices” or “after installation steps” as recommended.

Recently I happen to install MySQL on Mac OS X (Darvin Kernel). Below are the quick 5 steps to accomplish the task.

<strong>Step 1:  Check Mac Version</strong>
Very first step is to verify the Mac OS X’s current version to decide MySQL Installation file to be downloaded.
For example for Mac version: 10.4 you should download “Mac OS X 10.4 (x86, 32-bit), Compressed TAR Archive (mysql-5.1.51-osx10.4-i686.tar.gz)”

How to Check Mac Version:
<code>cat /System/Library/CoreServices/SystemVersion.plist
<xmp>
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>ProductBuildVersion</key>
<string>8S2169</string>
<key>ProductCopyright</key>
<string>1983-2007 Apple Inc.</string>
<key>ProductName</key>
<string>Mac OS X</string>
<key>ProductUserVisibleVersion</key>
<string>10.4.11</string>
<key>ProductVersion</key>
<string>10.4.11</string>
</dict></code>
</xmp>

Installation Error: <h2>dyld: unknown required load command 0x80000022<h2>
I ran in to problems while I installed MySQL for Mac OS X 10.5. Ofcourse I missed the step one and paid for it.
It’s about MySQL binary’s version difference errors: “dyld: unknown required load command 0x80000022″.

<strong>Step 2: Download MySQL Installation (tar.gz) file from dev.mysql’s download section.</strong>
For example go to: http://dev.mysql.com/downloads/mysql/5.1.html

Select appropriate OS & version and get the exact download link from mirror:
<code>
cd /usr/local/
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.51-osx10.4-i686.tar.gz/from/http://mysql.mirror.rafal.ca/</code>

<strong>Step 3: Create MySQL User and Group.</strong>

Through command line we can use NetInfo Utility as:
<code>niutil -create / /groups/mysql
niutil -createprop / /groups/mysql gid 401
niutil -create / /users/mysql
niutil -createprop / /users/mysql gid 401
niutil -createprop / /users/mysql uid 401</code>

Assign password to “mysql” user
passwd mysql

<strong>Step: 4   Installing MySQL using Generic Binaries</strong>
<code>cd /usr/local
tar -xzvf mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db –user=mysql
chown -R root .
chown -R mysql data
cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf</code>

<strong>Step: 5     Start MySQL Server:</strong>

bin/mysqld_safe –user=mysql &

This finishes basic installation of MySQL on Mac OS X. Make sure you follow “best practices” or “after installation steps” as recommended.

29 Sep

Top 10 Suresh Kalmadi-CWG Jokes-Delhi 2010

A lot of SMSes and Jokes I’ve received and read online about Mr. Suresh Kalmadi and CWG. Well, it’s quite a bit serious matter but such a huge mess gave us chance to make fun of CWG.

Well as far as I see Mr. Kalmadi’s work profile I really doubt someone who has worked in Indian Airforce for almost 11 years with eight medals in his career can get involved in such a big scam!!
I do not doubt on politics anyways.

Last night I heard Mr. Suresh Kalmadi’s interview about CWG; who was ready for any kind of Judicial Inquiry and was conveying “Hang me if I’m found guilty”. Well if it’s corruption it’s not just one man!! We all know…

I’m not sure what’ll be the actions taken to all this huge corruption, irresponsibility and risking pride of India after the Common Wealth Games!!

Here you go with TOP 10 CWG – Kalmadi Jokes.

1.
“Breaking news…. A.R. Rehman song dropped from CWG …Instead, Kalmadi will dance at the opening ceremony, to the song. Delhi badnaam hui darling tere liye!”

2.
Prince Charles is thanking kalmadi and is actively convincing the Queen to visit dengue hit Cwg Delhi, this may be his last chance to become the king!

3.
Terrorists set to skip CWG 2010 citing thanx to Kalmadi. Unlivable conditions and fear for their safety

4.
It’s amazing but true. If u rearrange the letters “SIR U MADE LAKHS”, U get “SURESH KALMADI”

5.
Q: How many contractors are required to change a light bulb in Delhi CWG stadium?
Kalmadi: 1 Million. (1 to change bulb and rest 999,999 to hold the ceiling)

[ad#ad-2-300×250]

6.
“delhi cm Sheila Dixit to Kalmadi: Delhi badnaamhui darling tere liye!”. “Sadkein bhi jam hui, CWG tere liye”.

7.
Next edition of CWG will be called KWG, Kalmadi Wealth Games

8.
“A collapse a day keeps the athletes away”, Kalmadi mantra. Thus giving more scope to Indian Athletes to Win.

9.
In the name of Ayodhya, recent Bulk SMS ban was for preventing people forwarding ‘Kalmadijokes’.

10.
Suresh Kalmadi: We have a strong bid for Olympics.

Share if you have more :)
They are jokes and should be taken as jokes!!

22 Sep

Extreme Movie Review n Poll – Salman's Dabangg 2010

Friends, I saw movie dabangg and this is what I think about it.

Dabangg…It’s a bad movie… I don’t understand how come it became so “popular”…It’s typical South Indian styled mindless, over-‘hero centric’, senseless and pitiful storied movie… I’ll prefer to watch a South Indian movie than this. I didn’t even like action!! Damn…

And it just cannot come into comparison with 3Idiot… If 3Idiots=10 then…Dabangg=1.

My suggestion do not waste your resources watching Dabangg.  For many of you this might be a late review but I thought it’s not worth to waste my time writing about this. Its an insult to review such a bundle of crap movie. Its just publicity that gave it so much earnings.

But now, I want to know how do you like it as a movie!! As I have found differences of opinion for this with my friends. They says they really felt it from their heart and they liked it. I couldn’t digest and wanted to know what you guys think.

Please use below poll and let me know how do you like the movie Dabangg !!

[polldaddy poll=3803282]

[ad#ad-2-300×250]

16 Sep

MySQL Function to Convert Date To Words

Recently I saw a MySQL Stored Function requirement on Experts-Exchange for converting date into some specific words format.
You may find MySQL function for date to words conversion online; even udfs might be ready, but I decided to write my own.
I wrote this simple function mainly based on SELECT CASE to convert dates in to words as follows:

mysql>SELECT date_to_words(‘2010-05-08′);
Eighth Day of May Two Thousand Ten

Download sql file below the code.

DELIMITER $$

DROP FUNCTION IF EXISTS `date_to_words` $$
CREATE FUNCTION `date_to_words` (mydate DATE) RETURNS VARCHAR(100)
DETERMINISTIC
BEGIN

/* Converts date into words */

DECLARE yr INT;
DECLARE dateval INT;
DECLARE thousand INT;
DECLARE hundred INT;
DECLARE tens INT;

DECLARE tensword VARCHAR(10);
DECLARE onesword VARCHAR(10);
DECLARE thousandsword VARCHAR(20);
DECLARE hundredsword VARCHAR(20);
DECLARE datevalsword VARCHAR(20);

SET yr=year(mydate);
SET dateval=day(mydate);

/* DAY TO WORDS */

SELECT CASE dateval
WHEN 1 THEN ‘First’
WHEN 2 THEN ‘Second’
WHEN 3 THEN ‘Third’
WHEN 4 THEN ‘Fourth’
WHEN 5 THEN ‘Fifth’
WHEN 6 THEN ‘Sixth’
WHEN 7 THEN ‘Seventh’
WHEN 8 THEN ‘Eighth’
WHEN 9 THEN ‘Ninth’
WHEN 10 THEN ‘Tenth’
WHEN 11 THEN ‘Eleventh’
WHEN 12 THEN ‘Twelfth’
WHEN 13 THEN ‘Thirteenth’
WHEN 14 THEN ‘Fourteenth’
WHEN 15 THEN ‘Fifteenth’
WHEN 16 THEN ‘Sixteenth’
WHEN 17 THEN ‘Seventeenth’
WHEN 18 THEN ‘Eighteenth’
WHEN 19 THEN ‘Nineteenth’
WHEN 20 THEN ‘Twentieth’
WHEN 21 THEN ‘Twenty-first’
WHEN 22 THEN ‘Twenty-second’
WHEN 23 THEN ‘Twenty-third’
WHEN 24 THEN ‘Twenty-fourth’
WHEN 25 THEN ‘Twenty-fifth’
WHEN 26 THEN ‘Twenty-sixth’
WHEN 27 THEN ‘Twenty-seventh’
WHEN 28 THEN ‘Twenty-eighth’
WHEN 29 THEN ‘Twenty-ninth’
WHEN 30 THEN ‘Thirtieth’
WHEN 31 THEN ‘Thirty-first’
END into datevalsword;

/* YEAR TO WORDS */
set thousand=floor(yr/1000) ;
set yr = yr – thousand * 1000;
set hundred = floor(yr / 100);
set yr = yr – hundred * 100;

IF (yr > 19) THEN
set tens = floor(yr / 10);
set yr = yr mod 10;
ELSE
set tens=0;
END IF;

SELECT CASE thousand
WHEN 1 THEN ‘One’
WHEN 2 THEN ‘Two’
WHEN 3 THEN ‘Three’
WHEN 4 THEN ‘Four’
WHEN 5 THEN ‘Five’
WHEN 6 THEN ‘Six’
WHEN 7 THEN ‘Seven’
WHEN 8 THEN ‘Eight’
WHEN 9 THEN ‘Nine’
END INTO thousandsword;
SET thousandsword=concat(thousandsword,’ Thousand ‘);

SELECT CASE hundred
WHEN 0 then ”
WHEN 1 THEN ‘One’
WHEN 2 THEN ‘Two’
WHEN 3 THEN ‘Three’
WHEN 4 THEN ‘Four’
WHEN 5 THEN ‘Five’
WHEN 6 THEN ‘Six’
WHEN 7 THEN ‘Seven’
WHEN 8 THEN ‘Eight’
WHEN 9 THEN ‘Nine’
END INTO hundredsword;
if (hundredsword<>”) then
SET hundredsword=concat(hundredsword,’ Hundred ‘) ;
else
set hundredsword=”;
end if;

/*TENS To WORDS*/
SELECT CASE tens
WHEN 2 THEN ‘Twenty’
WHEN 3 THEN ‘Thirty’
WHEN 4 THEN ‘Fourty’
WHEN 5 THEN ‘Fifty’
WHEN 6 THEN ‘Sixty’
WHEN 7 THEN ‘Seventy’
WHEN 8 THEN ‘Eigthy’
WHEN 9 THEN ‘Ninety’
ELSE ”
END INTO tensword;

/*ONES To WORDS*/
SELECT CASE yr
WHEN 0 THEN ”
WHEN 1 THEN ‘One’
WHEN 2 THEN ‘Two’
WHEN 3 THEN ‘Three’
WHEN 4 THEN ‘Four’
WHEN 5 THEN ‘Five’
WHEN 6 THEN ‘Six’
WHEN 7 THEN ‘Seven’
WHEN 8 THEN ‘Eight’
WHEN 9 THEN ‘Nine’
WHEN 10 THEN ‘Ten’
WHEN 11 THEN ‘Eleven’
WHEN 12 THEN ‘Twelve’
WHEN 13 THEN ‘Thirteen’
WHEN 14 THEN ‘Fourteen’
WHEN 15 THEN ‘Fifteen’
WHEN 16 THEN ‘Sixteen’
WHEN 17 THEN ‘Seventeen’
WHEN 18 THEN ‘Eighteen’
WHEN 19 THEN ‘Nineteen’
END into onesword;

return concat(datevalsword, ‘ Day of ‘, date_format(mydate,’%M’),’ ‘,thousandsword,hundredsword, tensword,’ ‘,onesword);
END $$

DELIMITER ;

Download SQL Code for converting date to words.date_to_words.sql

-- Kedar Vaijanapurkar --