Passing additional data to CALLBACK function of jQuery.ajax

Posted by Pritesh on December 30, 2011
  0 comments

 

Now a days we can not imagine web application with AJAX and jQuery make stuff lot easier to us. We normally need to use ajax call to update web content asyncronously. $.ajax is really simple to use, well I haven't write this post to advertise $.ajax but to explain how we can pass our custom arguments to its callback function.

$.ajax callback function have three default parameter 1. Content 2.Status 3. HTTPResponse object and in most of the case this are enough information in case you want to alert user or display message on particular dom object.

 




Saving with EC2 Reserved instance: AWS

Posted by Pritesh on December 24, 2011
  0 comments

Recently working with client to move ColdFusion project to AWS which has seasonal traffic. Key points are saving cost and easily upgrade/degrade server whenever needed. Initially start with On-Demand instance to make sure everything working fine before we permanently move to Cloud. 

As to save we have option to create reservered instance instead of ondemand. Recently Amazon introduce three type of reserved instance.

  1. Light Utilization 
  2. Medium Utilization
  3. Heavy Utilization
Depending on utiization of server we can save money with reserving instance. As we are going to host website on one of the stance we are good with Heavy Utilization Reserved instance but really want to know how much actualy we can save money with Reserved Instance.

Prepare spreadsheet to compare On demand, Light, Medium and Heavy Utilization R.I. with small, large and Extra large instance. Statistics really interesting, we can same good amount in 3 Year reservered instance compare to On Demand. Obviously as we need to pay non refundable initial fee. But if you really looking for Cloud for long time 3 Years reserved instanace option is really good as we just cover up initial payment within around 1 Year and 2 Months and rest of 22 months will be saving :).

Click here to view comparision spreadsheet.

Hope this help




.cfc page not supported in ColdFusion 5, make it work using .cfm page

Posted by Mahavir on December 23, 2011
  0 comments

Recently i use ColdFusion 9 for development, one of the project in that i create findcity.cfc page that contains function 'findCity()' to get list of cities(with zipcode) of specified state.

Code of findcity.cfc is look like:




<cfcomponent displayname="findcity" output="false">
    <cffunction name="findCity" access="remote" returntype="query">
        <cfargument name="state" type="any" required="true">
        <cfquery name="cityResult" datasource="#Application.ds#" username="#Application.UserName#" password="#Application.Password#">
            select cityname, zipcode from cityZip
            where statecode = <cfqueryparam value="#arguments.state#" cfsqltype="cf_sql_varchar"> 
            group by cityname
            order by cityname
        </cfquery>
        <cfreturn cityResult />        
    </cffunction>
</cfcomponent>

I use one javascript function that send Ajax request that call 'findCity()' funciton.

Code look like:




function search_cities(id,state)
    {
        $.ajax({      
                type: "GET",
                url: "/cfc/findcity.cfc?method=findCity&state="+state,
                dataType: "json",
                success: function(data){     // callback function that fill 'City' comboBox
                    var i=0;
                    objCity = $("#"+id)[0];
                    objCity.options.length = data.recordcount+1;
                    objCity.options[0].text =" -Select City-";
                    objCity.options[0].value = "";
                    objCity.options[0].selected = true;
                    for(i=0 ; i < data.recordcount ; ++i)
                    {
                        objCity.options[i+1].text =data.data.cityname[i];
                        objCity.options[i+1].value = data.data.cityname[i];
                    }
                }
            });
    }



Issue is that project build on ColdFusion 5, so that not support .cfc pages.

For that i create 'searchCity.cfm' page that provide the same fuctionality same as 'findCity()' function of findcity.cfc page

Code of searchCity.cfm is look like:




<cfquery name="cityResult" datasource="#Application.ds#" username="#Application.UserName#" password="#Application.Password#">
    select cityname, zipcode from cityZip
    where statecode = <cfqueryparam value="#url.state#" cfsqltype="cf_sql_varchar"> 
    group by cityname
    order by cityname
</cfquery>

<!--- converting Query resultSet in to json format --->
<cfset dData = cityResult>
<cfset dJSONString = "" />
<cfset recordcountKey = "recordcount" />
<cfset columnlistKey = "columnlist" />
<cfset columnlist = LCase(dData.columnlist) />
<cfset dataKey = "data" />
    
<cfset dJSONString = dJSONString & '"#recordcountKey#":' & dData.recordcount />
<cfset dJSONString = dJSONString & ',"#columnlistKey#":"' & columnlist & '"' />
<cfset dJSONString = dJSONString & ',"#dataKey#":' />

<cfset dJSONString = dJSONString & "{" />
<cfset colPos = 1 />
<cfloop list="#cityResult.columnlist#" delimiters="," index="column">
    <cfif colPos GT 1>
        <cfset dJSONString = dJSONString & "," />
    </cfif>
    <cfset column = LCase(column) />
    <cfset dJSONString = dJSONString & '"' & column & '":[' />
    <cfloop from="1" to="#cityResult.recordcount#" index="i">
        <cfif i GT 1>
            <cfset dJSONString = dJSONString & "," />
        </cfif>
        <cfset dJSONString = dJSONString & '"' & cityResult[column][i] & '"'/>
    </cfloop>
    
    <cfset dJSONString = dJSONString &  "]" />
    <cfset colPos = colPos + 1 />
</cfloop>
<cfset dJSONString = dJSONString & "}" />
<cfoutput>{#dJSONString#}</cfoutput>



Now, call 'searchCity.cfm' page to fill 'City' comboBox using Ajax by setting 'url' attribute same as below,




url:"/cfc/searchCity.cfm?state="+state;



Hope this is helpful.




Strange ColdFusion issue, JRUN eating up to 50% of CPU.

Posted by Pritesh on October 31, 2011
  2 comments

 

For one of our project we recently move to Amazon EC2 to make system easily scalable. This is kind of seasonal website which has high traffic during September and October and rest of the year traffic reduced to 70% with compare to October month. I think Amazon's usage based model is perfect for this client as he doesn't need to pay much on his off season also we can easily scale and add new instances during peak season and cover cost that we saved during off season.

Finally we happily moved everything on cloud EC2 and working fine. Suddenly after 1 hour of so CPU usage increased to 50% and remain constance 50% for hour or so. While looking into Task manager we realize that JRUN is eating up that CPU but there wan't much traffic at that time (average 1 user/sec) and system was happily handling this much traffic in our dedicated server. Tried to install Fusion Reactor to see realtime users and other stats but it seem that even Fusion Reactor can not figure out who is eating up CPU. For a day we keep running server as our all sites working correctly and wasn't making much performance issue.

 




Configure ColdFusion with VisualVM.

Posted by Pritesh on October 31, 2011
  0 comments

For one of our project we are facing jrun high usage issue. When looking into task manager (Window 2008) I found jRun continously eating up 50% CPU usage even though there is no traffic (or may be 2 to 3 users) only on site. Initially I tried to install FusionReactor to get all kind of detail regarding ColdFusion. Started with trial version and thought if useful then get full version but it seems that giving me all application ColdFusion application related information but can't find anything why JRun eating 50% of CPU usage. After bit googing I found VISUALVM and JConsole for monitoring and troubleshooting java application. I like VisualVm due to it's nice GUI and also I can integrate JConsole as plugin to it. It win - win kind of situation. 




Task Scheduler was not working Social Engine video upload module - Solved

Posted by Vikas on October 21, 2011
  1 comments

Hi,

Recently I started reviewing SocialEngine (Short desc: create your own social networking site), and I face some issue with video uploading process.

I am using SocialEngine 4.1.7.

By default, user can only embed Video from YouTube and Vemio. But if you want to upload the Video file, you need to allow it by enabling settings from the Administrative area.




Sql Server Rank() v/s Dense_rank()

Posted by Bharat Patel on September 28, 2011
  2 comments

Hello Friends,

Some days before I was googling on sql server's system function and I got one site having sql server query puzzle. The site have very interesting puzzle. I got a puzzle during surfing and it is to find out second highest salary of each department and tie salary should also count. There are inbuilt functions in sql server to give rank as per result set.

The Rank() function of sql server returns the position of value within a partition of a result set. Rank() function left gaps where ranks are tie.

The Dense_rank() function of sql server returns the position of value within a partition of a result set. Dense_rank() function does not left gaps where ranks are tie.

Syntex :

Rank() over([partition_by] <order_by>)

Dense_rank() over([partition_by] <order_by>)



DECLARE @Employees TABLE(
EmployeeID INT IDENTITY,
EmployeeName VARCHAR(15),
Department VARCHAR(15),
Salary NUMERIC(16,2)
)


INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('T Cook','Finance', 40000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('D Michael','Finance', 25000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('A Smith','Finance', 25000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('D Adams','Finance', 15000)


INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('M Williams','IT', 80000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('D Jones','IT', 40000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('J Miller','IT', 50000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('L Lewis','IT', 50000)


INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('A Anderson','Back-Office', 25000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('S Martin','Back-Office', 15000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('J Garcia','Back-Office', 15000)
INSERT INTO @Employees(EmployeeName, Department, Salary)
VALUES('T Clerk','Back-Office', 10000)


select *,RANK() over(partition by department order by salary desc) as ranking
from @Employees


select *,DENSE_RANK() over(partition by department order by salary desc) as ranking
from @Employees


-- Final query


 


select * from (
select *,RANK() over(partition by department order by salary desc) as ranking
from @Employees
) As T where T.ranking = 2

Output




Complex password strength checking through regular expression

Posted by Pritesh on September 20, 2011
  0 comments

Currently working on project for well non credit card company where they have online registration form. They really want user enter enter strong password for their account and criteria for password listed below..

  1. Password must length between 8 to 18.
  2. Password must contain atleast one alpha and on numeric.
  3. Password must have one special characters from @,#,$.
  4. Password can not have repeative alpha and numeric.

This is really complex but can be done with four different conditions easily (right?) but I decided to make things more complex and check all four condition with single regular expression. After spending time on this finally figure out regular expression can perform all four condition.




Read File line by line in ColdFusion by using Java Classes

Posted by Vikas on September 20, 2011
  3 comments

HI,
I was having situation where I wanted to read a file and process each line.
I think cffile tag is not much to do it, so I use java classes.
Basically we need two kinds of classes.
1. InputSream
2. Buffer reader

Buffer reader is capable to read any input stream line by line.

Final code will look like:



<cfscript>

    FileName = expandPath('/temp.txt');

    objFileReader = createObject("java","java.io.FileReader");

    InputStreamReader = objFileReader.init(FileName);

    objBuffer = createObject("java","java.io.BufferedReader" );

    LineIO = objBuffer.init(InputStreamReader);

</cfscript>



<cfset eof = 0>

<cfset cnt = 1>

<cfloop condition="not eof">

    <cfset currline = LineIO.readline()>

    <cfif isdefined("currline") eq "no">

        <cfset eof = 1>

        <cfbreak>

    </cfif>

    <cfoutput>line #cnt#: #currline#<br/></cfoutput>

    <cfset cnt = cnt + 1>

    <cfflush>

</cfloop>





Making Paypal standard checkbout more user friendly

Posted by Pritesh on September 06, 2011
  0 comments

Recently working with paypal standard checkout and it so easy to integrate with any application as it will redirect to paypal site and customer login and make all kind of payment stuff at paypal site only. But this task make really tuff for new customer who has limited knowledge of intenernet/paypal.

How this works? Well, paypal has very good documentation here. Basic flow is.

  1. Customer click on "Paypal" button which redirect to paypal site.
  2. Customer need to login or enter credit card information.
  3. Paypal ask for confirmation of payment.
  4. Thanks page for placing order with link to return original site.