Tuesday, September 18, 2007

Wednesday, May 09, 2007

Learning SQL

This post will help you to kick start SQL learning. There are many tutorials on net that will teach you SQL in 9 minutes. All you learn is only theory. You never get to try out even a single SQL query that you learn. So if you just wanna learn theory and forget it tomorrow you have reached a wrong place. Please close this window now.
So you wanna learn SQL the real way? Smart. I am not going to write a 40 pager that will make you a expert in all statements in SQL. I am just going to help you in setting up something so that you can use the other tutorials on internet to learn the better way. Pause here for a moment and read my other post for setting up MySQL server on your box if you have not - MySQL Setup
Now that you have everything ready on your box we will create a database and a table to play with. After connecting to the server from the command prompt, that is from your MySQL client, follow the following steps.

Enter the commands as below to create a database called learnsql, a table called test and some queries to insert values and select them.

C:\Documents and Settings\prathap>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.37-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database learnsql;
Query OK, 1 row affected (0.00 sec)

mysql> use learnsql;
Database changed
mysql> create table test (Id Integer not null, Name varchar(255) not null);
Query OK, 0 rows affected (0.08 sec)

mysql> desc test;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| Id | int(11) | NO | | | |
| Name | varchar(255) | NO | | | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)


C:\Documents and Settings\prathap>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.37-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database learnsql;
Query OK, 1 row affected (0.00 sec)

mysql> use learnsql;
Database changed
mysql> create table test (Id Integer not null, Name varchar(255) not null);
Query OK, 0 rows affected (0.08 sec)

mysql> desc test;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| Id | int(11) | NO | | | |
| Name | varchar(255) | NO | | | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into test values (1, 'prathap');
Query OK, 1 row affected (0.05 sec)

mysql> select * from test;
+----+---------+
| Id | Name |
+----+---------+
| 1 | prathap |
+----+---------+
1 row in set (0.00 sec)

Now follow the tutorial at sql-tutorial Make sure that you try all the statements in the client.

Tuesday, May 08, 2007

Setup MySQL server in Windows

I aim to help you folks in setting up mysql server in windows box in this post. Read the steps below and of course follow them Before you go ahead make sure you view the presentations at the end of the steps.

Steps:
* Go to http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.37-win32.zip/from/pick
* Pick the mirror that is closest to you and download the zip file
* Extract the zip file to your preferred location - you can use programs like 7-zip or winzip for this
* Double click the .exe file to install the mysql server
* Follow the wizard to complete the setup
* Enter the new root password if it asks for (make sure to note this down or remember)
* Once the setup is complete, start the server
* Now launch a command prompt - start -> run -> type 'cmd' and enter
* Now type mysql -uroot -p and press enter

Presentation Links:
* Install MySQL Server & configure a instance
* Connect to the server using mysql client and running a query

Tuesday, April 04, 2006

Backing up Official Email

Backing up Official Email

I had a necessity to back up all my official emails to a personal mail box to take all the information that I earned with me always. Yes PST (personal folders) is definitely one way of storing them and take them with you. But you always need outlook with you to read them. If you are comfortable with Microsoft and PST you can quit reading this piece. I decided to transfer my emails to Gmail which gives me the storage space I need with the search utility on top with few extra features. Now comes the question, how do you forward all the emails to gmail account?

There is a good tool that is written by Mark Lyon called Gmail Loader (http://www.marklyon.org/gmail/) which is capable of reading all your emails in mBox format and upload them to the Gmail using the APIs exposed by gmail. But unfortunately the PSTs are in pst format and not in open mBox format. Yes, Mark also has faced this problem and he has found some tools which can convert the PSTs to mbox format (http://www.marklyon.org/gmail/gmailapps.htm) which can be later supplied to the Gmail loader. I also did the same, but I got a lot of errors in the conversion process missing lot of emails. Later when I tried to use the uploader I came to know that the Gmail Loader uses a port that is blocked in my company’s firewall. Then I started looking up some alternative ways. I had some little experience in writing simple Macros to do some stuff in Excel sheets using VBA (Visual Basic for Applications). So I started looking at macros for Outlook that can forward emails to my personal ID.

Finally I ended up in writing a Macro which will read all my emails in the personal folder and forward it to gmail. Following is the macro,

Transfer all emails in a folder inside a personal folder

'Sub routine to call the kernel sleep API

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'Author : Pradhap Nirmal Natarajan

Sub ScanFolders()

'define the types of variables

Dim ns As NameSpace

Dim Item As Object

Dim i As Integer

Dim addr As String

'this module forwards all emails in a specific personal folder

Set ns = GetNamespace("MAPI")

'grab the personal folder you want to read

'in the code below cognizant is a personal folder inside which the folder Visa is present

Set projArchiveFolder = ns.Folders.Item("Cognizant").Folders.Item("Visa")

For Each Item In projArchiveFolder.Items

'dont forward read receipts for which class property is 46

If Not Item.Class = 46 Then

Set oOldMail = Item

'equivalent to the forward click in outlook

Set oMail = oOldMail.forward

'the recipient

addr = "prathapnirmal+cog.others.Visa@gmail.com"

oMail.Recipients.Add addr

oMail.Recipients.Item(1).Resolve

If oMail.Recipients.Item(1).Resolved Then

oMail.Send

Else

MsgBox "Could not resolve " & oMail.Recipients.Item(1).Name

End If

'sleep for a specific time (use this if you want a time gap between each send)

'Sleep 15000

End If

Next Item

End Sub

Transfer all emails inside all Folders in a Personal Folder

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub ScanFolders()

Dim ns As NameSpace

Dim Item As Object

Dim i As Integer

Dim addr As String

Set ns = GetNamespace("MAPI")

i = 0

Set projArchiveFolder = ns.Folders.Item("Cognizant").Folders.Item("Projects Archive").Folders

For i = 1 To projArchiveFolder.Count

For Each Item In projArchiveFolder.Item(i).Items

'dont forward read receipts

If Not Item.Class = 46 Then

Set oOldMail = Item

Set oMail = oOldMail.forward

addr = "prathapnirmal+cognizant.projects." & projArchiveFolder.Item(i).Name & "@gmail.com"

oMail.Recipients.Add addr

oMail.Recipients.Item(1).Resolve

If oMail.Recipients.Item(1).Resolved Then

oMail.Send

Else

MsgBox "Could not resolve " & oMail.Recipients.Item(1).Name

End If

'Sleep 5000

End If

Next Item

Next i

End Sub

If you look at the code above you will see that the personal ID is a little different. It says prathapnirmal+cog.visa@gmail.com It doesn’t mean that I have a ID like this exclusively for Visa. This is a feature that you can use in the email ids to classify emails. My wish is to move all these emails to a different folder in the mailbox to easily differentiate them as you write rules in outlook. Gmail provides a feature called labeling to do this. So create a filter to move emails to different labels based on the to address. Following is what I got,


The mails are routed to different labels based on to Address. Please write to me at prathapnirmal+questions@gmail.com in case of any questions. Some useful bookmarks at http://del.icio.us/pradhapnirmal/jobexit

Tuesday, March 28, 2006

Technologies for a web developer

Just a list of technologies/languages that you should be familiar with to be a good web developer,

* Java - used in most of the webbased applications for its scalablility and simplicity. MVC architecture understanding is a plus.
* SQL - query language basics is a must to deal with DB operations. Knowledge on persistence framework like hibernate is a plus
* JavaScript - Good knowledge on JavaScript which is the base of AJAX and ultimately web 2.0
* Regular Expressions - its everywhere, java, javascript, perl, python for a lot of operations
* HTML, CSS - which defines the structure and style of a web page.
* A Scripting language - Any one of the scripting languages which helps in some mundane operations you do. Perl, Python, PHP and Ruby are various options. Some of them have even evolved as equivalents to Java
* XML - Most commonly used technology for data isolation in many of the languages and applications
* XSD + DTD - Schema for XML, XSD is a successor of XSD
* HTTP Concepts - details about a http request, headers, and alternative protocols.

Yes, you definitely need good design skills. Knowledge on data structures and algorithms is essential.

Monday, March 20, 2006

webdev reference

JavaScript References

* Gecko DOM Reference
* Devguru Reference
* MSDN Reference for DHTML (as you know this will be specific for IE)


CSS References

*
W3Schools
* Html Help
* Blooberry

HTML References

* HTML 4.0

W3C Technical Reports

*
HTML Spec
* CSS Spec

ECMA Javascript Standards

From European Computer Manufacturers Association




Hard Earned Learnings

My Tough Time Learnings

I mention these Learnings are as tough time because I have really spent a lot of time in debugging these issues. This blog will be a mix-up of all the learning’s in various technologies. I start with PHP.

Configuring GD(Graphics Draw) for PHP

This write up guides you in installing and Configuring GD for PHP running as a Module in Apache for windows. The fact that I was using WAMP stack from Spike source took me some more time to identify the issue.

  • Get php_gd2.dll for windows – download php-5.1.2 binary from php.org. The distribution will contain a folder called “ext” which includes all the dlls. Copy this folder and paste it in your current php folder. For a WAMP stack it will be “C:\SpikeSource\oss\php5”. Also copy the dlls directly inside php-5.1.2-Win32 folder of the distribution and place it inside “C:\SpikeSource\oss\php5”. Now you have got all the dlls required for GD usage.
  • Configure php.ini – You have to tell PHP to load the GD extension for usage. For WAMP stack the php.ini file is under “c:\windows” directory. Don’t be taken away by the php.ini file in C:\SpikeSource\oss\php5 directory. This is just a copy. Open the php.ini file under c:\windows. Update the location of the extension folder.

; Directory in which the loadable extensions (modules) reside.

extension_dir = "C:/SpikeSource/oss/php5/ext"

Update the extension to be used. Remove the semi-colon from the line ;extension=php_gd2.dll

;Windows Extensions

;Note that ODBC support is built in, so no dll is needed for it.

extension=php_gd2.dll

  • Restart your Apache server. Now you are ready to use GD, great.
  • If you receive any errors in startup like - PHP Warning: PHP Startup: Unable to load dynamic library 'C:/SpikeSource/oss/php5/ext\php_gd2.dll' - The specified procedure could not be found. – then you haven’t copied the dlls completely.
  • Try the following program

header ("Content-type: image/png");

$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");

$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);

$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);

ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);

ImagePng ($img_handle);

?>

It should display a image for you. For further doubts contact me at prathapnirmal+gd@gmail.com.

Friday, February 17, 2006

Unicode

Unicode as I learnt

I couldn’t resist writing about Unicode as I learnt it. I know already that it’s a way of representing all the characters of various languages using a unique computer number. Following are some of the interesting jargons that I came across when I started learning Unicode.

  • Grapheme – a atomic unit of the script in any language
  • Glyph – a shape representing characters, punctuations and other stuff in a script
  • Phoneme – it’s the usual phonetics we talk about, a pronunciation. Its composed of one or more graphemes.
  • Digraph – two graphemes make a single phoneme called digraph. For example, the word ship contains four graphemes (s, h, i, and p) but only three phonemes, because sh is a digraph. An example of a trigraph is the tch in itch.
  • Trigraph – three graphemes

Confused? See here - http://en.wikipedia.org/wiki/Grapheme

Above all the encodings available right now, UTF-8 is the most widely used encoding followed by ISO 8859 1. UTF-8 is a variable four byte encoding set which can represent any available character in any character set. Its becoming the wide standard in web, email and storage applications. Following are the resources I referred to read about Unicode and understand encoding,