Updated Classic ASP TextMate Bundle

Aug 16

I downloaded this TextMate bundle a while ago for ASP — so I could have code coloring. However I’ve found that I really need the symbols to be correctly identified. So I updated the bundle to include public & private methods of classes in the list of symbols. I also added a permanent redirect snippet. (I have to write these frequently since mod_rewrite isn’t available to me)

Download my version of the bundle.

Note: The original bundle is available on the MacroMates bundles for the 1.0.2 release page. It was created by Rich Barton and based on the work of Justin French, Sune Foldager and Allan Odgaard on the PHP scripting dictionary.

 

Prevent jQuery.live() Handlers From Firing Multiple Times

Aug 05

Recently I was working on something where I needed to use jQuery’s .live() event handling. The problem I was experiencing was that my .live() handler was firing multiple times for the same event. I devised a rather simple way to avoid this issue and I’m going to share it with all of you.

The first thing we need to know is that the event object which is passed to all of the event handlers for that given event is the same object. You can modify it and the next handler will get the same object you just modified. So my method takes advantage of that fact and adds a .handled property to the jQuery event object. My event handler method then checks to see if this property is equal to true and if it isn’t, then it executes it’s payload. Otherwise it just returns false to prevent bubbling.

function myLiveEventHandler(event)
{
  if(event.handled !== true)
  {
    // put your payload here.
    // this next line *must* be within this if statement
    event.handled = true;
  }
  return false;
}

$('selector').live('event', myLiveEventHandler);

There you have it. We have bound a .live() event handler and prevented it from running twice. (If it just so happened that it were bound more than once.) Why might it be bound more than once? If you use jQuery Mobile or some sort of AJAX loading method for content then you may duplicate your event handler binding every time you load a new page. This is probably the poor man’s way of handling this problem and you should probably try to find a way to avoid double binding the event instead. Who has the time for that?

 

Gracefully Handling AJAX Requests with ASP Classic

Jul 06

I’ve been working with so-called “Classic” ASP for about two years now. Here’s a trick I’ve put into practice with great success. Often when writing data-driven web scripts you may need to alter the presentation of that data based on the requester or some other variable. For instance, a script may be requested via a web browser which expects HTML output. However that same script may also be requested via an XMLHTTPRequest from within the browser which might expect XML or JSON formatting. (AJAX) The simplest way to detect if a request is from AJAX or not is to check for the X-Requested-With header.

ASP provides you with the Request object which has many properties and methods to provide you information about the current HTTP Request being handled. Because ISAPI follows the CGI standard for accessing HTTP request headers you can just access them the same way you would a normal request header. Just append HTTP_ to whatever request header you want to access. Here’s the AJAX detection demonstration:

<%
If Request.ServerVariables("HTTP_X-Requested-With") = "XMLHttpRequest" Then
  ' do some stuff (Freaking VBScript comments)'
Else %>
<html>
  <body>
    <h1>Stuff</h1>
  </body>
</html>
<% End If %>
 

Lehigh Valley Ruby Meetup Notes 2011/03/02

Mar 05

Notes from the March second LV Ruby Meetup group. We built an ‘IdeaShouter’ app with haml, sass, and compass. By the end of these notes you should have built one too. Companion code can be had on github. more…

 

Automatically Update a Remote Mercurial Repository With Redmine

Feb 26

I recently started using Redmine to keep track of my freelance projects. I’ve found it to fit most of my needs. For the price — free — you can’t complain about anything. Some handy features include issue tracking, time tracking, wiki, file storage & upload (intended for software “packages”), and repository integration. This tutorial focuses on the repo integration feature.

Let’s assume that you’re a progressive developer and have taken to using a “social coding” platform such as GitHub for git or BitBucket for Mercurial. I happen to use both. I prefer Mercurial over git, but you are welcome to your own opinions. Since you keep your code in the cloud and not on your own private server, then you’ll need to integrate Redmine into that remote repository. I prefer to use private key encryption since the types of projects I use Redmine for are not public code bases. I also want to back up my repository on my own server. So that now I’ve got it in three places; BitBucket, my server, and my dev machine. more…