Skip navigation

Author Archives:

Ever have a lower case string and needed the initial letter of each word to be in capital? well I did and luckily found a nice regular expression via google.

rereplace(“this string is all lowercase”, “(\b\w)”, “\u\1″, “all”) would produce ‘This String Is All Lowercase’

problem solved.

The other day while I was walking to work I found myself day dreaming. As my thoughts wondered I dreamt of a perfect world where you could use regular expressions whenever, wherever you liked.

Once arriving at work I was back to reality not everything in life can be a regular expression!

As I worked away writing some boring queries, I figured I might liven up my day and try using regular expressions to improve a query. After some research, much to my surprise I found that MySQL could handle regular expressions… maybe my day dream was coming true.

In my case I was looping over a list and comparing with another list found within the database, previously I had been using numerous ‘LIKE’ statements to match the two lists (see below)

<cfquery name="qData" datasource="#application.dsn#">
 SELECT *
 FROM tableName
 WHERE status != 'Archive'
 AND
 <cfset iCount = 1 />
 <cfloop list="#arguments.groups#" index="i">
 <cfoutput>
 (availability LIKE '#i#,%' OR availability LIKE '%,#i#' OR availability LIKE '%,#i#,%' OR availability = #i#)
 </cfoutput>
 <cfif iCount LT listLen(arguments.groups)>
 <cfoutput> OR </cfoutput>
 </cfif>
 <cfset iCount = iCount + 1 />
 </cfloop> 

 ORDER BY #arguments.sort# #arguments.sortOrder#

 </cfquery>

After some messing about with regexp (and some help from my boss) I was able to reduce this to a simple regular expression so my query became.


<cfquery name="qData" datasource="#application.dsn#">
 SELECT *
 FROM tableName
  WHERE status != 'Archive'
 AND
 <cfset iCount = 1 />
 <cfloop list="#arguments.groups#" index="i">
 <cfoutput>
 availability REGEXP '[^0-9]*(#i#)[^0-9]*'
 </cfoutput>
 <cfif iCount LT listLen(arguments.groups)>
 <cfoutput> OR </cfoutput>
 </cfif>
 <cfset iCount = iCount + 1 />
 </cfloop> 

 ORDER BY #arguments.sort# #arguments.sortOrder#

 </cfquery>

Next time you are writing a query take a second to ask yourself is this a good time to try out regexp? and hopefully the answer will be yes.

Good news for children everywhere… Tree Inspector now alerts you when you are with the wrong parent!

Ever thought your navigation node was appearing under the wrong parent node?

Well the updated Tree Inspector helps ease your anxiety, take a look at the image below.

In the case above you will see that the footer nodes parentid does not match the utility nodes objectid. There are two possible causes for this and I will explain them and the fixes below.

  1. The footer node is underneath the wrong parent; in this case you would simply update the nLeft and nRight (as normal) so that the node jumps underneath the correct parent node.
  2. The footer node is underneath the correct parent, but for some reason the parentid in the database in wrong; you would need to manually update the nested_tree_objects table so that the footer nodes parentid is the same as the utily nodes objectid.

Have a shot at using this release and if you have any thoughts / improvements please post them here.

At the moment jQuery is our javascript framework of choice – it is straight forward to use and you can create complex effects/functions with only the basic of knowledge. Although like many coding languages your source can quickly become bloated and start affecting the performance of your application. Luckily while reading my daily new feeds I found a great post written by Samer Kamel Draidi (originally by Jon Hobbs-Smith) which details 25 excellent tips to improve the use of jQuery.

The article ‘Improve your jQuery – 25 excellent tips‘ has many great tips to increase speed and generally improve how you code using jQuery and I feel it is a must read… so check it out.

The filter form on the top of the object admin page inherits the default properties, this can be problematic especially when you only want something to be display only.

When a property is set to display only, you are unable to filter by it.

To fix this modify the custom admin file as below.

<cfset stFilterMetaData = structNew() />
<cfset stFilterMetaData.thehiddenproperty.ftDisplayOnly= "false" />

<!--- set up page header --->
<admin :header title="News" />

<ft :objectadmin  typename="dmNews"
permissionset="news"
title="#application.adminBundle[session.dmProfile.locale].newsAdministration#"
columnList="title,catnews,publishdate,datetimelastUpdated"
sortableColumns="title,publishdate,datetimelastUpdated"
lFilterFields="title,source"
stFilterMetaData="#stFilterMetaData#"  
sqlorderby="publishdate desc"
plugin="farcrycms"
module="/dmNews.cfm" />

 

read more at http://docs.farcrycms.org/display/FCDEV40/Formtools+Object+Admin

Recently I had a problem with the categories tree within farcry. I was thinking, How can this be fixed?

As the Tree Inspector does such a great job in fixing the navigation tree, I wondered if it would work for categories, well it didn’t… but now it does !

This new version of the Tree Inspector now features a simple to use combobox, to select which type of Tree you would like to Inspect.

The other day I was fixing a navigation tree and the Tree Inspector crashed, after some debugging it turns out the problem was caused by nodes with high nlevels.

The data was being stored in an array and as such when it did not find nlevels between the 12 – 560 range it tried to be helpful and insert them for us. However this causes the Tree Inspector to freak out as the values actually do not exist.

To overcome the issue, the data is now stored within a struct and everything is sweet :)

The final addition to the new Tree Inspector version 0.4 is a handy quick property view. All you need to do is click on the object name and its properties will be display.

enjoy!

Follow

Get every new post delivered to your Inbox.