Entries for month: May 2010
Something that comes up often in code reviews at my office is that you should combine and minify JavaScript and CSS to reduce the number of http requests that need to be made to render the page, and to minimize the amount of data that needs to be returned for those requests. Usually this involves pointing out that the YSlow and PageSpeed extensions for FireFox will easily point out this and other things that will improve your page load times.
Knowing, though, is only half of the battle. The other half is doing; and sometimes people think that the effort involved in creating and maintaining these combined and minified resources is a hassle, and not without reason. It definitely can be.
There are tools available that make the process fairly easy, but none that I have found that make it transparent and dynamic, so I set out to do just that.
in
ColdFusion |
HTML/CSS |
JavaScript |
4 Responses
Posted 2010-05-17 12:08
I'm working on a webservice that has the potential to be quite dangerous. In the wrong hands, it could be used to spoof email, calendar, etc data from any person in our organization. So you can imagine that there is some concern about restricting access, even in development.
Since I'm working on my local machine, I simply need to limit access to this website in IIS to one specific IP address: localhost (127.0.0.1). In the days of IIS6, this was fairly easily done in the website properties dialog. On the directory security tab there were options to restrict to certain IP addresses or ranges.
These days, I'm on Windows 7, which comes with IIS7. And in IIS7, (of course!) this functionality has been buried. So I'm posting this both to help others, as well as to be a reminder for myself later down the road when I want to do this again.
The first thing you need to do is open up Control Panel > Programs and Features, and from there, choose Turn Windows Features on or off. Navigate to Internet Information Services > World Wide Web Services > Security and enable IP Security.

After you do this, you'll need to run iisreset before the change takes effect. If you have UAC enabled, be sure to run your command dialog as an administrator, otherwise you won't be able to run iisreset.
Lastly, to create the restrictions, open up the IIS Manager and select the website that you want to restrict. Open the IP Address and Domain Restrictions module, and then in the actions panel (on the right side) choose Edit Feature Settings.... To only allow local browsing, you should deny by default. Choose Deny from the dropdown, and hit OK. Then add your exceptions -- the IP's or ranges that you want to allow access to. To do that, choose Add Allow Entry... from the action panel, and add all the exceptions you need.
These changes should take effect immediately.
in
Misc |
No Responses Yet
Posted 2010-05-14 11:40
For my personal projects, I have switched entirely over to Git for version control. However, at work I still have to use Subversion so that everyone on my team can share. That is not to say that Git isn't perfectly capable of working for our team, but that the team isn't ready to make the switch.
While I am extremely curious about the prospect of using Git as my Subversion client -- something that I understand is not difficult to do -- I haven't yet worked up the nerve to try it on something as important as a work project. I can't afford for something to go wrong. So for the time being, I'm still using native SVN clients.
Recently I decided that I would give the Subversive client a try. When I first started with SVN I used Tortoise, and when I started developing with Eclipse and CFEclipse, there seemed to be (after very little research) a consensus that Subclipse was the better client; so it's what I've used for the last few years.
Myself and at least one other coworker have been using Subclipse and having some problems that we believe may be unique to Subclipse -- or at least to using Subclipse in our environment. We often have projects checked out onto a shared drive and have sometimes run into a situation where a commit can't be made from the root, or issues when selecting a few individual files in disparate directories. Suffice it to say, frustration is setting in and while the command-line works, it would be nice if IDE integration worked.
So that's why I'm trying something new. Not only is Subversive now an official part of the Eclipse project (a nice endorsement), but I've heard lots of praise for it recently. I've always wondered if I had made the right choice going with Subclipse, so now I'm aiming to find out.
Speed
My very first impression was how fast it seems to be. I haven't done direct side-by-side comparisons, but from a subjective standpoint it feels like browsing a large repository -- the Mango Blog repository, for example -- is extremely fast. Even a checkout seemed faster. And you can't complain about too much speed.
Does it work?
Of course, most importantly, is the reason that I switched: Does it work in cases where Subclipse seemed to fail us before. The answer is short and sweet: Yes! So far, I haven't run into any similar complaints about Subversive.
Shortcuts
I never knew how much I needed keyboard shortcuts for version control.
Update? Ctrl+Alt+U
Commit? Ctrl+Alt+C
Compare with latest from repository? Ctrl+Alt+L
And the list goes on. I could never switch to an Eclipse-based SVN client that didn't have these or similar keyboard shortcuts available and not experience some serious frustration.
Any complaints?
Actually, yes. I was quite surprised to find that after installing the client through the Eclipse update site, it still wasn't fully installed. It seemed like there was a framework in place for the functionality, but the first time I tried to anything with a repository, I was prompted to install a connector -- a step that (to the developer's credit) Subclipse completes during the original installation.
Now, this may not be that big of a deal, and I suppose it really isn't, but I am trying hard to use UAC in Windows 7. I have my reasons, but suffice it to say that I want my relationship with UAC in Windows 7 to work out. In order to install the plugin in the first place, I had to run CFBuilder as an administrator. Fine, did that. After the install, I was prompted to restart. Ok, that's not desirable, but fairly reasonable. Once I try to connect to a repository, I'm prompted to install a connector -- but oh wait, you can't just install it, you have to exit CFBuilder, run as an administrator, and install the connector. And then restart again, of course.
It's not the end of the world, but it was annoying enough that I thought I should mention it. And it's not CFBuilder's fault at all, this is a combination of seemingly-odd choices by the plugin developers and Windows UAC pains.
Do I recommend it?
Absolutely. Even if for the keyboard shortcuts alone. That plus added speed is a no-brainer for me. Where I can't use Git, I'll be using Subversive.
in
CFBuilder |
Subversion |
11 Responses
Posted 2010-05-13 11:05
ColdFusion's Query of Query functionality is a pretty unique and powerful tool, once you get your head around what's going on and how it can be useful to you.
Recently, one of my colleagues asked if it was possible to use the SQL UPDATE operation to modify the contents of the in-memory result set. While the answer to that question is ultimately NO, that doesn't mean you can't accomplish the same goal another way. As the saying goes, there's more than one way to skin a cat.
Let's start by creating a query object that we'll later want to change:
//create an empty query to work with
variables.qryFoo = queryNew("a,b,c","varchar,varchar,varchar");
//add a row and fill it with some data
queryAddRow(qryFoo);
querySetCell(qryFoo,"a","aaaaaa");
querySetCell(qryFoo,"b","aaaaaa");
querySetCell(qryFoo,"c","aaaaaa");
Now, as I said, you can't just UPDATE this query object via Query of Queries. This code won't work:
UPDATE qryFoo
SET b='bbbbbb', c='cccccc'
However, you can achieve the same effect with a SELECT statement:
<cfquery name="qryFoo" dbtype="query">
SELECT a, 'bbbbbb' AS b, 'cccccc' AS c
FROM qryFoo
</cfquery>
Simple, yet effective. I love it!
Update:
Per Nathan's comment, it wasn't clear that my original intention was to overwrite the query object with the QoQ select. I've updated the code above to reflect that.
By naming the QoQ the same as the original query object, the result of the select will overwrite the original data. This doesn't give you granular control to update a single record, but if you want to change the value of every row in specific column(s), then it's an easy way to go.
Of course, this begs the question: Is it possible to do a granular update using select and a union? And does QoQ even support Union?
Answer? YES!
<cfscript>
//create an empty query to work with
variables.qryFoo = queryNew("a,b,c","varchar,varchar,varchar");
//add a few rows and fill them with some data
queryAddRow(qryFoo);
querySetCell(qryFoo,"a","aaaaaa");
querySetCell(qryFoo,"b","aaaaaa");
querySetCell(qryFoo,"c","aaaaaa");
queryAddRow(qryFoo);
querySetCell(qryFoo,"a","bbbbbb");
querySetCell(qryFoo,"b","bbbbbb");
querySetCell(qryFoo,"c","bbbbbb");
queryAddRow(qryFoo);
querySetCell(qryFoo,"a","cccccc");
querySetCell(qryFoo,"b","cccccc");
querySetCell(qryFoo,"c","cccccc");
</cfscript>
<cfdump var="#qryFoo#" label="before">
<cfquery name="qryFoo" dbtype="query">
SELECT a, 'bbbbbb' as b, 'cccccc' as c
FROM qryFoo
WHERE a = 'aaaaaa'
UNION
SELECT a, b, c
FROM qryFoo
WHERE a <> 'aaaaaa'
</cfquery>
<cfdump var="#qryFoo#" label="after">
The dumps from the above code look like this:

As you can see, the code initialized 3 rows, with each record containing all A's, all B's, and all C's, and then with the QoQ, we've changed just the all A's row to have B's and C's in the B and C columns, using union.
Cool stuff.
in
ColdFusion |
Ask a Grokker |
6 Responses
Posted 2010-05-12 11:10
These days, I work with CF servers that are home to hundreds of applications simultaneously. We have some nice error reporting going on, with Application.cfc's onError() method to send email notifications, and using a backup of the CFError tags for when all else has failed. But I noticed that it was incredibly annoying waiting for error emails to arrive when my code would have an error in it. So I decided to disable custom error handling and pretty error pages in development.
Of course, to eliminate the potential for human error, we programatically determine if the application is running in dev, staging, or production:
<cfinvoke
component="cfc.AppStatus"
method="getEnvName"
returnVariable="appStatus"
/>
This code is in Application.cfc, and stores the result in a place shared with the entire application. We were already using this value to set things like the datasource password (which is different between your development and production environments, right?!). If it's not obvious, the function will return the string DEV, STAGE or PROD depending on which environment that server belongs to.
Then, in onRequestStart(), I added this little nugget:
<!--- If on dev, don't use error emails, just show errors --->
<cfif app_status neq "prod" and app_status neq "stage">
<cfset structDelete(this, "onError") />
<cfset structDelete(variables, "onError") />
<cfsetting showdebugoutput="true" />
</cfif>
And wrap the backup CFError tags like so:
<cfif app_status eq "prod" or app_status eq "stage">
<cferror
type="request"
template="/error_request.cfm"
/>
<cferror
type="exception"
template="/error_exception.cfm"
/>
</cfif>
Now, when my code throws an error while I'm developing and testing in the dev environment, I see it on screen instead of having to wait a minute or two for the email to come, and I don't have to worry about a rogue infinite loop filling up my inbox.
in
Best Practices |
ColdFusion |
2 Responses
Posted 2010-05-11 11:24