Monday 31 May 2010

Few Handy Javascript functions for HTML forms

Here are few handy javascript function, which I use on day today basis in my Web development:

// Returns string after trimming spaces from both sides
function AllTrim(str)
{
str = LTrim(str);
str = RTrim(str);
return str;
}
//Returns string after trimming spaces from left side
function LTrim(str)
{
return str.replace(/^\s+/g,'');
}
//Returns string after trimming spaces from right side
function RTrim(str)
{
return str.replace(/\s+$/g,'');
}
// validates email form field, if you pass true, it checks for empty field as well
function checkEmail(str, required)
{
regexPattern = /^[a-zA-Z_0-9-]+(\.[a-zA-Z_0-9-]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$/;
str = AllTrim(str);
if (required == 'undefined' || required )
{
if( str.length == 0 )
{
return false;
}
}
else
{
if( str.length == 0 )
{
return true;
}
}
return regexPattern.test(str);
}
// returns selected radio button value from a group of radio buttons in a form
function getSelectedRadioValue(formObj, obj)
{
var selected_radio_val = '';
for (var i=0; i < document[formObj][obj].length; i++)
{
if (document[formObj][obj][i].checked)
{
selected_radio_val = document[formObj][obj][i].value;
break;
}
}
return selected_radio_val;
}

Saturday 29 May 2010

Coldfusion 8 Query feature

This post is the extension of my earlier post - 10 March 2009

Actually I wrote about getting Identity column value, when inserting a new record in MSSQL data base. but few days ago I found out from Ben Forta's blog, here is the link to that blog and content:

If you are using a database table with an identity (auto-increment) field, ColdFusion 8 can automatically return the newly created field value for you, without needing a trigger or a subsequent . All you need to do is look in the optional RESULT structure, and if available the value will just be there. This feature is very DBMS and driver specific (and unfortunately does not seem to be supported by Apache Derby), and the name of the structure member containing the generated value is different based on the DBMS being used. Here are the ones you should be aware of:

* SQL Server: result.IDENTITYCOL
* Oracle: result.ROWID
* Sybase: result.SYB_IDENTITY
* Informix: result.SERIAL_COL
* DB2: result.KEY_VALUE
* MySQL: result.GENERATED_KEY (MySQL 4 and 5 only, MySQL 3 does not support this feature)

Ben Forta's Article link

Upgrade to Flex 3.5 - removes html templates files

I came across the problem when I upgraded my Eclipse Flex Builder Plugin to use Flex 3.5 SDK.

When I was using clean my project option, it was removing html-template folders content, and solution is (I found a solution on web from one blog/ article):

Go to your project's properties (right click, Properties)
Go to Flex Compiler
Under "Html wrapper" un-check "Generate HTML wrapper file" Click "Apply"
Then check "Generate HTML wrapper file" (the same one you just unchecked)
Click "Apply"
You should now see that the html wrapper files are regenerated.

This happened to me when I used the clean option on one of my projects.

Thursday 27 May 2010

How to find Function, Stored Proc, Table, View Details

In Microsoft SQL Enterprise Manager

Open The query Tab for the DB

Write the object name (just name without DBO etc)

Select the object name and press Alt + F1

Will list all information related to that object
i.e. For function

Will list
1) Creation /owner etc details
2) Output details with type etc
3) Input needed by that function

Sunday 23 May 2010

Configuring Secure Virtual Host on Mac OS X

I had requirement to test my Flex Application, which I build for Raileasy in Secure environment.
It was quite difficult to configure my Mac, as I couldn't find a good post/ Blog or any article on it.
I asked few of my friends, who are using Mac for their development work and only Andy Allan gave me few tips and links:

Following are the articles helped me to set-up my Mac:
1) Mark Liyanage - article on Configuring mod_ssl on Mac OS X

2) Generating an SSL Certificate with Apache+mod_ssl

Here are the steps I took to configure my Mac (which are based on above articles):
First Open a terminal window and type in these commands:
  • sudo -s
  • cd /etc/apache2
  • mkdir ssl
  • chmod 700 ssl
  • cd ssl
  • gzip -c --best /var/log/system.log > random.dat
    (This step will create a file with the name and zip the file, which we will use to generate key)
  • openssl rand -rand file:random.dat 0

I was looking for a certificate to put on my local machine (which is self signed certificate) and to get that, here are the steps I took:
Issue following command in the already opened terminal window (which should be all in one line):

Before run the command get following questions answers ready:
***********
* Country Name (2 letter code) [AU]:GB
* State or Province Name (full name) [Some-State]:London
* Locality Name (eg, city) []:London
* Organization Name (eg, company) [Internet Widgits Pty Ltd]:Dev Co.
* Organizational Unit Name (eg, section) []:Development
* Common Name (eg, YOUR name) []:www.yourlocal.com
* Email Address []:admin@yourlocal.com
(It's important that you enter the host name of your web server exactly as it will be used later on in the "Common Name" field, like www.yourlocal.com or ssl.yourlocal.com.)
***********
COMMAND to run in terminal window:
openssl req -keyout privkey-2010.pem -newkey rsa:1024 -nodes -x509 -days 365 -out cert-2010.pem

Make sure that "TextEdit" is not running, then type these lines into the terminal window:
  • chmod 600 privkey-2001.pem
  • chown root privkey-2001.pem

On Mac Snow - Apache comes with default config file for SSL
Open following files in any text editor

/etc/apache2/httpd.conf (main config file for Apache)
/etc/apache2/httpd-ssl.conf

1) In ssl.config file look for
VirtualHost definition
You would see like this:
<VirtualHost _default_:443>

But above setting didn't work for me, I had to change it to like this, and I don't know the reason though, but it worked:
<VirtualHost www.yourlocal.com:443>

Change the DocumentRoot to the right root for your web site.
You might need to Add Directory access rights for the document root:
<Directory /sites/yoursite/wwwroot>
allow from all
Options +Indexes
</Directory>

Find the following and change them with right path and file name:
SSLCertificateFile "/etc/apache2/ssl/cert-2001.pem"
SSLCertificateFile "/etc/apache2/ssl/cert-2001.pem"

Save the file

You need to un-comment following line in httpd.conf file
#Include /private/etc/apache2/extra/httpd-ssl.conf

Save the file

from terminal window

run pwd command and make sure you are at
/etc/apache2/

run following commands:
apachectl stop
apachectl start
Now your server will provide secure access to your website.

The one thing I didn't understand was, by doing tis, all of my local website turned into secure websites.

But I was able to test my website under secure environment.

Thanks to the writers of above articles.

:)

Thursday 20 May 2010

Flex Spy (fxSpy)

This is a nice component, if you are a Flex Developer:

I found out this component today, when Anuj showed me.

This is very impressive, and useful to play with styles like you can do with firebug.



Here is the Project:

http://code.google.com/p/fxspy/



And an article by Anuj as well:

http://www.anujgakhar.com/2009/09/05/triggering-flexspy-with-a-keyboard-shortcut/



Another one from some developer:

http://blogs.warwick.ac.uk/stevencarpenter/entry/flex-spy_live_component

Wednesday 19 May 2010

Few helpful links for MAC

MAMP
http://www.mamp.info/en/index.html

SQLLite

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/sqlite3.1.html


Installing Railo + Apache in Mac OSX

http://www.luismajano.com/category/getrailo/