Adding JqGrid to Coldfusion 9 page

Download JQGrid from http://www.trirand.com/blog/?page_id=6

 

In test.cfm:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

<link rel="stylesheet" href="jquery-uiGrid.css" />
<script src="grid.locale-en.js" type="text/javascript"></script>
<script src="jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function(e) {

        jQuery("#domainUserGrid").jqGrid({
            url:'cfc/user.cfc?method=getTestUser',
            datatype: "json",
            height: "auto",
            colNames:['#','Username','Phone','Last Updated','Actions'],
            colModel:[
                {name:'userPhoneId_int',index:'userPhoneId_int', width:30},
                {name:'username_vch',index:'username_vch', width:160},
                {name:'phone_vch',index:'phone_vch', width:160},
                {name:'dateUpdated_dt',index:'dateUpdated_dt', width:100},
                {name:'actions',index:'actions', width:120}
            ],
            rowNum:25,
            pager: jQuery('#pager2'),
            rowList:[10,20,30,40],
            pager: '#pager2',
            sortname: 'update_dt',
            viewrecords: true,
            sortorder: "desc",
            caption:"Domain Users",

            jsonReader: {
              root: "ROWS", //our data
              page: "PAGE", //current page
              total: "TOTAL", //total pages
              records:"RECORDS", //total records
              cell: "CELL",
              id: "" //will default first column as ID
              }           
        });

    });
</script>

<table id="domainUserGrid"></table> <div id="pager2"></div>

 

In cfc/user.cfc

<cfcomponent>
    <cffunction name="getTestUser" access="remote" returnformat="plain">
        <cfargument name="page" required="yes">
        <cfargument name="rows" required="yes">
        <cfargument name="sidx" required="yes">
        <cfargument name="sord" required="yes">
        <cfargument name="domain" required="yes">

        <cfparam name="series" default="0">
        <cfset var dataout = '0' />
        <cfset var LOCALOUTPUT = {} />

        <cfquery name="getUsers" datasource="#application.ds#">
            SELECT userPhoneId_int,domainId_int,userid_int,insert_dt,update_dt,username_Vch,phone_vch
            FROM users
            <cfif sidx eq 'undefined' or sidx eq ''>
                order by update_dt desc, insert_dt desc
            <cfelse>
                order by #sidx# #sord#
            </cfif>
        </cfquery>

        <cfif getUsers.recordcount GT 0 AND rows GT 0>
            <cfset total_pages = ceiling(getUsers.recordcount/rows)>
        <cfelse>
            <cfset total_pages = 0>        
        </cfif>

        <cfset LOCALOUTPUT.PAGE = "#page#" />
        <cfset LOCALOUTPUT.TOTAL = "#total_pages#" />
        <cfset LOCALOUTPUT.RECORDS= #getUsers.RECORDCOUNT# />

        <cfset start = ((page-1)*rows)+1>
        <cfset end = page*rows>

        <cfset LOCALOUTPUT.rows = ArrayNew(1) />
        <cfset i = 1>
        <cfloop query="getUsers" startrow="#start#" endrow="#end#">

            <Cfset LOCALOUTPUT.ROWS[i] = StructNew() >
            <cfset LOCALOUTPUT.ROWS[i].ID = "#userPhoneId_int#" />
            <cfset dt = dateformat(update_dt,'mmm dd, yyyy') & ' ' & timeformat(update_dt,'HH:mm:ss')>
            <cfset LOCALOUTPUT.ROWS[i].cell = [#numberformat(i)#,"#username_vch#","#phone_vch#","#dt#","Actions here"] />

            <cfset i = i+1>
        </cfloop>

        <cfreturn  SerializeJSON(LOCALOUTPUT)>
    </cffunction>
</cfcomponent>

Tags: , ,

Minesweeper game

minesweeper game

minesweeper

 

DEMO

Tags: , , ,

Call webservice method with parameter in flex 4.5 mobile application

This section contains the declaration of webservice:

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:WebService
id="getSummaryWeb"
wsdl="http://xyz.com/webservice/serv.cfc?wsdl"
fault="getSummary_faultHandler(event)"
result="getSummary_resultHandler(event)">

<s:operation name="getSummary">
<s:request xmlns="">
<site_id>{p.getProperty('p_sid')}</site_id>
<contact_id>{p.getProperty('p_uid')}</contact_id>
</s:request>
</s:operation>
</s:WebService>
</fx:Declarations>

You can call the above defined web-service at craetionComplete of mxml file using:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Alert Summary"
creationComplete="getSummaryWeb.getSummary.send()">

“getSummary” is the name of method defined in the .cfc page.

Now to get the result of web-service you can use the following code:

public function getSummary_resultHandler(event:ResultEvent):void
{
summaryCollector = event.result as ArrayCollection;
}

Here summaryCollector is a variable of type ArrayCollection.

Tags: ,

Search into your coldfusion log files

Its a small search tool that could come handy if you have multiple coldfusion servers, or you have lots of things running on your server.

You need to enter the Ip address of your server. In my case all the servers are happened tp be on windows platform and installed in C:/ . Also make sure the server you are running this code should be able to access other servers.

<cfif structkeyexists(form,"submit")>
    <Cfset servervalue = form.server>
    <Cfset lfvalue = form.lf>
    <Cfset termvalue = form.term>
    <Cfset conditionvalue = form.condition>
    <Cfset nottermvalue = form.notterm>
<Cfelse>
    <Cfset servervalue = ''>
    <Cfset lfvalue = ''>
    <Cfset termvalue = ''>
    <Cfset conditionvalue = ''>
    <Cfset nottermvalue = ''>
</cfif>

<Cfform name="logdetails" id="logdetails" action="log.cfm">
    <table>
        <tr>
            <td>CF Server</td>
            <td><cfinput type="text" name="server" id="server" required="yes" message="Please enter the value" value="#servervalue#" /></td>
        </tr>
        <tr>
            <td>Log File Name</td>
            <td>
                <select name="lf" id="lf">
                    <option id="lf1" value="scheduler.log" <cfif lfvalue eq 'scheduler.log'>selected </cfif> >scheduler.log</option>
                    <option id="lf2" value="application.log" <cfif lfvalue eq 'application.log'>selected </cfif>>application.log</option>
                    <option id="lf3" value="eventgateway.log" <cfif lfvalue eq 'eventgateway.log'>selected </cfif>>eventgateway.log</option>
                    <option id="lf4" value="mail.log" <cfif lfvalue eq 'mail.log'>selected </cfif>>mail.log</option>
                    <option id="lf5" value="mailsent.log" <cfif lfvalue eq 'mailsent.log'>selected </cfif>>mailsent.log</option>
                    <option id="lf6" value="server.log" <cfif lfvalue eq 'server.log'>selected </cfif>>server.log</option>
                </select>
            </td>
        <tr>
            <td>Search Term</td>
            <td>
                <cfinput type="text" name="term" id="term"  value="#termvalue#"/>
                <select name="condition" id="condition">
                    <option value="exact" <cfif conditionvalue eq 'exact'>selected </cfif>>Exact</option>
                    <option value="or" <cfif conditionvalue eq 'or'>selected </cfif>>OR</option>
                    <option value="and" <cfif conditionvalue eq 'and'>selected </cfif>>AND</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Should not contain</td>
            <td>
                <cfinput type="text" name="notterm" id="notterm" value="#nottermvalue#"/>

            </td>
        </tr>
        <tr>
            <td><cfinput type="submit" name="submit" id="submit" /></td>
        </tr>
    </table>
</cfform>
    <Cfoutput>

        <cfif structkeyexists(form,"submit")>

            <cfif FileExists('\\#form.server#\C$\ColdFusion8\logs\#form.lf#')>
                <cfset pathToFindLog = '\\#form.server#\C$\ColdFusion8\logs\#form.lf#'>
            <cfelseif FileExists('\\#form.server#\C$\CFusionMX7\logs\#form.lf#') >
                <cfset pathToFindLog = '\\#server#\C$\CFusionMX7\logs\#form.lf#'>
            <cfelseif FileExists('\\#form.server#\C$\ColdFusion9\logs\#form.lf#')>
                <cfset pathToFindLog = '\\#form.server#\C$\ColdFusion9\logs\#form.lf#'>
            <cfelseif FileExists('\\#form.server#\ColdFusion\logs\#form.lf#')>
                <cfset pathToFindLog = '\\#form.server#\ColdFusion\logs\#form.lf#'>
            <cfelse>
                <cfset pathToFindLog = 0>
            </cfif>    

            <cfif pathToFindLog neq 0>
                <cffile action="Read" file="#pathToFindLog#" variable="logvar">
                <Table border="1">
                    <tr>
                        <td><strong>Severity</strong></td>
                        <td><strong>ThreadID</strong></td>
                        <td><strong>Date</strong></td>
                        <td><strong>Time</strong></td>
                        <td><strong>Message</strong></td>
                        <td><strong>Application</strong></td>
                    </tr>

                    <cfloop list="#logvar#" delimiters="#chr(13)##chr(10)#" index="i">
                        <Cfset i = rereplace(i,',,',', ,','ALL')>
                        <Cfset show = 1>
                        <cfset msg = ListGetAt(i,6,'","')>
                        <cfset continue = 1>

                        <cfif form.notterm neq ''>
                            <cfif findnocase('#form.notterm#',msg)>
                                <cfset show = 0>
                                <cfset continue = 0>
                            </cfif>
                        </cfif>

                        <Cfif continue and form.term neq ''>
                            <Cfset show = 0>
                            <Cfif form.condition eq 'exact'>
                                <cfif findnocase('#form.term#',msg)>
                                    <cfset show = 1>
                                    <cfset term1 = "<strong style='color:blue'>"&form.term&"</strong>" >
                                    <cfset msg = replacenocase(msg,term,term1,'ALL')>
                                </cfif>

                            <cfelseif form.condition eq 'OR'>
                                <cfloop list="#form.term#" delimiters=" " index="c">
                                    <cfif findnocase('#c#',msg)>
                                        <cfset show = 1>
                                        <cfset c1 = "<strong style='color:blue'>"&c&"</strong>" >
                                        <cfset msg = replacenocase(msg,c,c1,'ALL')>
                                    </cfif>
                                </cfloop>
                            <cfelseif form.condition eq 'AND'>

                                 <cfloop list="#form.term#" delimiters=" " index="c">

                                    <cfif findnocase('#c#',msg)>
                                        <cfset show = 1>
                                        <cfset c1 = "<strong style='color:blue'>"&c&"</strong>" >
                                        <cfset msg = replacenocase(msg,c,c1,'ALL')>
                                    <cfelse>
                                        <cfset show = 0>
                                        <cfbreak>
                                    </cfif>
                                </cfloop>
                            </cfif>
                        </Cfif>

                        <cfif show>

                            <tr>
                                <td>#ListGetAt(i,1,'","')#</td>
                                <td>#ListGetAt(i,2,'","')#</td>
                                <td>#ListGetAt(i,3,'","')#</td>
                                <td>#ListGetAt(i,4,'","')#</td>
                                <td>#msg#</td>
                                <td>#ListGetAt(i,5,'","')#</td>
                            </tr>
                        </cfif>
                    </cfloop>

            <cfelse>
                No infor for <Cfdump var="#form#">
            </cfif>

        </cfif>

    </Cfoutput>

Above code is not fully optimized. Any suggestions or questions are welcomed!

Tags: ,

How to change MySql privileges for users

To find out the permissions that users have on MySql server

select * from mysql.user
where host like 'X.X.X.X'

To Update the privileges

update mysql.user
set Select_priv = 'Y', Insert_priv='Y',Update_priv='Y'
where host like 'X.X.X.X';

flush privileges;

Don’t forget to flush the privileges, it just clears out the cache of MySql privileges.

Complete list of privileges for MySql users:
http://dev.mysql.com/doc/refman/5.1/en/privileges-provided.html

Tags: ,

Exporting data in mysql 5.5 innoDB

I used to export my data using option MySQL Admin -> data export/restore -> export to self-contained file, for MyIsam.

But when I switched over to InnoDB and option checked for ‘innodb_file_per_table’ and did my data export using self contained file, and imported it back to other mysql 5.5 machine. It created only one innodb data file for all my database table.

Solution for keeping separate .ibd files for all DB is to check ‘Export to dump project folder’ and then import that folder. Doing this will keep one innodb file per table.

Tags: , , ,

How to play counter strike like games on 64 bit windows machine

Yes, it is possible to play game like counter strike, half-life in 64 bit windows. I am playing condition zero on my Windows 7 home premium 64 bit machine.

Please follow below steps to avoid error message like ‘available memory less than 15 mb’ :
1) Right click on Application(.exe) file of your games [like czero.exe]
2) Click ‘Properties’.
3) Go in ‘Compatibility’ tab.
4) Choose Windows XP Service pack 2 as compatibility mode and Apply the setting.
5) Now you are all set to play ~Frags On~

Importing all emails from one gmail account to another

Its very easy to do:

Step1: Email account from which you have to fetch of all emails
a) Go to top right of page. Click on ‘Settings‘.
b) Under ‘Settings‘, click on tab names ‘Forwarding and POP/IMAP‘.
c) Inside ‘POP Download‘ click on the ‘Enable POP for all mail (even mail that’s already been downloaded)
d) Click on ‘Save changes‘ button at bottom.

Step2: New Emails account in which you have to import all emails from old account:
a) Go to top right of page. Click on ‘Settings’.
b) Under ‘Settings‘, click on tab names ‘Accounts and Import‘.
c) Now click on very first button named ‘Import mail and contacts‘. It will open a pop-up window asking your username first then your password. Its very simple just keep on filling information and clicking continue.(NOTE: Allow pop-up here if your browser is blocking it)
d) You are done. All emails backup will be done in back-end. Time for backup depend upon the number of emails you import. In my case there were around 5550 emails and it took 2 days to import all emails.

Forwarding and POP/IMAP

Tags: , , ,

Unwanted cfscript tag in xmlhttlrequest for cfchart in IE

I wanted to refresh whole div containing cfchart with updated chart using simple xmlHttpReq. I simply write another .cfm page having new charts with which i replace chart in my calling .cfm page. It worked fine in Firefox n safari, but i can’t see any updated chart in IE, whole div was blank. There was not even any java script error shown. Problem was that IE inserts tag at the top of html code. So all the html beneath that is not displayed in IE. Below code will solve that purpose.
All it does is replace any found in the xmlHttp.responseText

xmlhttp.onreadystatechange=function()
{
  if(xmlhttp.readyState == 4 && xmlhttp.status==200)
  {
     var res = xmlhttp.responseText;
     res = res.replace(new RegExp("[<||\>]","gi"),"");
     document.getElementById("charts").innerHTML = res;
  }
}

Tags: , , ,

Happy Birthday Ankur

Ankur Saxena, I met him in Jan 2008. We use to play for same team ‘Trojan Tiger’. Its his birthday today, I wish him all the luck and hope his year turn out to be greatest of all.

He is a very good at heart. He likes ‘billiya’ (cat) a lot. Bcoz his nick name is ‘Billi ka Bacha’ lolz.. He is 25 now. And will be married to Dheera in Jan 2011.

When it comes to cricket he is a very good batsman. Good keeper – almost always takes best keeper award at cromwell (USC internal cricket series) and a good bowler too.

Happy Birthday bro,,,

Tags: