Backup with cp on Linux
by Siraj Sayeed on Feb.03, 2009, under Linux
In one of our Linux servers, I had to overwrite a large number of files but at the same time I needed to maintain backup copies of the files that are being replaced. The number of files and folders were too many to do it manually and I am not an expert on scripting. After some searching I found a very simple option for cp which does the trick. It renames all the files with ‘_old’ prefix and then copies the source over to destination recursively.
sudo cp -rb -S_old /data01/source/* /data01/destination/
Passing search parameter in cfgrid
by Siraj Sayeed on Oct.17, 2007, under Ext JS, ColdFusion
Todd Sharp has posted a nice blog on his cfsilence on how to do it by modifying the bind parameter. Based on that and code from Gary Gilbert and implemented it myself. Here is the code:
<cfform name="form01">
<cfgrid
format="html"
name="employeeGrid"
pagesize=11
stripeRows=true
autoWidth=true
width="800"
pictureBar=true
bind="cfc:employeeService.getDataByParam(
{cfgridpage},
{cfgridpagesize},
{cfgridsortcolumn},
{cfgridsortdirection},
getFirstNameSearchParam(),
getLastNameSearchParam())"
delete="yes"
selectmode="edit"
onchange="cfc:employeeService.editData({cfgridaction},{cfgridrow},{cfgridchanged})"
>
<cfgridcolumn name="Emp_ID" display=true header="Employee ID" select="no" />
<cfgridcolumn name="FirstName" display=true header="First Name"/>
<cfgridcolumn name="LastName" display=true header="Last Name"/>
<cfgridcolumn name="email" display=true header="Email" />
</cfgrid>
</cfform>Look at the last two params in the cfc, I used JS functions to get the firstName and lastName from some text boxes and send those to the CFC. Here are the JS functions:
function getFirstNameSearchParam(){
return document.getElementById("firstName").value;
}
function doSearchEmployee() {
ColdFusion.Grid.refresh('employeeGrid', false);
}
The first function simply gets the text field value and returns it. The second function is triggered when users click the ‘Search’ button and refreshes the Grid to get the resultset again from the backend.
Next I tried to do the same with a different approcah, instead a calling the CFC, I called an url (though same cfc metheod) like the following:
bind="url:employeeService.cfc?method=getDataByParam&page={cfgridpage}&pagesize={cfgridpagesize}&
gridsortcolumn={cfgridsortcolumn}&gridsortdirection={cfgridsortdirection}&
firstname={insertForm:firstName}&lastname={insertForm:lastName}&returnFormat=json"
Notice, passing these four parameters is very important otherwise ColdFusion will through erros: {cfgridpage},{cfgridpagesize},{cfgridsortcolumn}, {cfgridsortdirection}. Next two parameters are “firstname={insertForm:firstName}” and “lastname={insertForm:lastName}” which will take the values of firstName and lastName fields of the form ‘inserForm’ and pass it through the url parameters. But only problem is, it binds the text fields with the grid and every time I tab out of the field, it refreshes the Grid even before I click the search button whcih I do not want. Probably there is a way to do it but I do not know. Also the final parameter of “returnFormat=json” is very important. Otherwise ColdFusion returns a WDDX packet. Interestingly there is no special code block in the function ‘getDataByParam’ to handle retrunFormat (probably ColdFusion takes care of it internally):
<cffunction name="getDataByParam" access="remote" output="false">
<cfargument name="page">
<cfargument name="pageSize">
<cfargument name="gridsortcolumn" default="">
<cfargument name="gridsortdirection" default="">
<cfargument name="firstname" default="">
<cfargument name="lastname" default="">
<cfquery name="team" datasource="cfdocexamples">
SELECT Emp_ID, FirstName, LastName, email
FROM Employees
WHERE
1=1
<cfif len(firstname)>
AND FirstName like '%#firstname#%'
</cfif>
<cfif len(lastname)>
AND LastName like '%#lastname#%'
</cfif>
<cfif gridsortcolumn neq "" or gridsortdirection neq "">
order by #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn QueryConvertForGrid(team, page, pageSize)>
</cffunction>
First trial with ExtJS
by Siraj Sayeed on Oct.11, 2007, under JavaScript, Ext JS
Few days back I stumbled on Ext JS and I was literally “WOW! JavaScript can be so cool!” Then I started exploring it and I was amazed with the kind of things these guys have done. This is the best JS library I have ever seen. I started with the Grid Component and went through the Screencast by Scott Walter. On the Ext JS site, the video was not complete (or stopped for me at about 80%). So I downloaded it from Scott’s website and went trough the whole tutorial. This is really good. Within few hours I had a working grid. Next hurdle was to get it talking to a cfm page to my SQL database through JSON. He did it with php and did not share the code. Actually the problem was with the JSON format Ext JS data reader does not like the format generated with CF8. Anyway, I had it resolved in a hard way through multiple trial and errors and watching the Firebug Ajax console. But trust me, the time was worth spending and I will blog about that later. Next I tried to build a complete application with Ext JS. In fact, last your I built an AjaxCFC based application but that time none of the “cool” components were available. I got the tab from one place, table with sortable column and fixed header from two different places etc. So I wanted to build everything using one library so that the overall look and feel is the same. And here is the result of my last six weeks of work which has:
|
I have yet to work on the data loadmask, login screen, another tab, issues with Internet Explorer etc. but I though of writing up whatever I have learnt so far before it is too late….
Hacking DB password in CF Datasource
by Siraj Sayeed on Sep.26, 2007, under ColdFusion, Database
I wanted to create a new datasource in CF Admin but somehow I could not find the password associated to the user account in the database. Of course, I could create a new user in the DB, assign a new password and use that password in CF Admin. But I did not want to do that either. And retrieving password from the database using some third party tool seemed too risky. So I started looking into the neo-query.xml file where ColdFusion stores all the data source information. The file resides in “\cfusion-ear\cfusion-war\WEB-INF\cfusion\lib” folder. I went into another JRun instance, opened up the ‘neo-query.xml’ and copied the encrypted password string for the same database-user combination from that and pasted it into the instance I am working on. I had to restart the CF server after saving the file. And as expected, the datasource worked! Sweet!! Next time I will probably ask the DBA for the password instead of going through all the hassle…:-)
Hello world!
by Siraj Sayeed on Sep.24, 2007, under Uncategorized
Welcome to my blog! After being dorment for one and half year I fianlly decided to revive my blog again. Probably this time I will be blogging more often….