All posts by JB

About JB

Owner, Author, Delusional.

Google Maps: Screw the highway, Cut across town!

I’m expecting a package, shipped by ground from Las Vegas to my home in Adrian, MI. I decided to see how long Google Maps thinks that trip would take.

As I perused the results, I traced the little blue line for a while, to see what course they’re following, and what towns it goes through. I didn’t expect it to actually go through a town.. Lo and behold, I’ve found that Davenport, Iowa is in mortal peril. Google has decided it’s more effective to cut across town than to take the highway around it. Beware, Davenport.

Screw the highway, Cut across town

Actually, you’ll notice the blue line veers off the road a bit on the east side of town, too. Does Google’s blue line get drowsy like a real driver? Is that a side-trip to see the world’s largest ear of corn?

And by the way, I flipped 230,000 miles on my CR-V yesterday. I think upon 239,000, I’ll christen the car “Alice”. As in, “To the moon, Alice!”

ASPLint

This is ASPLint.vbs:

Actually, it’s more like ASP-VBScript Lint. Sorry, JS programmers. Sorry, .NET programmers.

Here’s what it does, and why…
in ASP when you “SET object = …” an object, that object starts occupying memory. If you don’t release that memory (SET object = Nothing), it never lets go of that memory. Even after the page finishes. Even 3 days later. IIS isn’t too sharp about its “garbage collection”.

ASPLint exists to scan a web server directory for files that have objects SET, and never released. It traverses the entire directory tree you start it at, and examines separately, and in context, every ASP page in there. It creates a log of the objects that aren’t closed, by filename, approximate line number and variable name. Should make finding and fixing memory leaks in your ASP apps much easier.

It doesn’t count comments. It doesn’t calculate white-space. It doesn’t have a neat interface. It doesn’t cost $400. It does help solve the memory leak problems I was having.

How it works:
Assign the four variables near the top of the script: strRoot, strTypes, strLogFile, and intLimit. They tell the script what directory to start in, what file types to look at, what logfile to create, and how many errors are a good stopping place (I hate being overwhelmed by errors to fix). Call the script from the command line: cscript.exe asplint.vbs Go get a pot of coffee.

While you’re gone, the script will start in strRoot, and open every file that matches the filetype extensions you gave it. For each file, first any #include-d file is also opened, and chunked together with the current file – just like ASP does when it displays a page on your webserver. This does NOT actually change your file – the chunkin’ happens in memory. Virtual or File types of #Includes both work, although if you use virtual include types to virtual directories, well, that’s just crazy, and ASPLint won’t go there.

Once the entire file (includes and all) has been assembled, ASPLint starts from the top and looks for any occurence of “set (somevariable) =”. I’ve attempted to be smart about it – it’ll find SETs that are on a line by themselves, or are in one of those annoying : colon : separated : lines that gang several instructions onto a single line. Punk. Don’t code that way. Lines that are ‘ commented out get skipped, so the count should be half-accurate.*

If a SET if found, a corresponding SET … = Nothing is also searched. If that’s not found, that filename, approximate* line number and variable name get logged to the logfile you named.

I tried to make the logfile smart enough so that each file’s dangling objects will only be listed once.
I Tried.

* About all those asterisks…
First, you can probably guess that flow-control statements are obeyed in ASP, and skipped in ASPLint.
Consider this:

if 1=1 then set objMe = Some.Object
if 1=0 then set objMe = Nothing

ASP will obviously only perform one of those two commands. Yay for ASP. ASPLint assumes they both worked. Boo for ASPLint. But accounting for Flow-control statements gives me a headache. You should be writing better code than that anyway — I’m not your mother, I don’t clean up after you.

Second, because ASPLint chunks all those included files together, its count of lines from the top of the whole memory chunk isn’t quite accurate. Sure, I try to calculate the space taken by includes, and I do a decent job of detecting objects opened/closed in includes instead of the file that included them, but there’s a really good chance the line numbers you see in the log will be wrong. The degree of wrong goes up as the number of includes increases. I didn’t feel like figuring the whole thing out. Given the right filename, the right variable name and an approximate line number, you should get close enough to find the little bugger yourself.

There. Now you know what I was planning. You can browse/change/steal the code below, and make any use of it you want. Is that a GPL License? Creative Commons? I dunno. I don’t care. Do what you like, but when you speak of me, speak kindly.

Oh, and realize there’s probably bugs in here (inefficiencies, stupidities, vagueries, etc.). I know that. But I have a real job to get done, and this was just a hacked-together means to an end that I’m giving the world for free. Complain not. If you DO happen to fix or enhance something, please do send me a copy – Jonathan @ this website. I’ll put it back on my website for the rest of us ASP coding peons to enjoy.

CSS Width Shorthand

I knew this existed, just didn’t know exactly how it works. Now I’ll remember. Because I wrote it. Here.

If there is only one value, it applies to all sides. If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively.

Shorthanding the Shorthanded:

So where you usually have
margin: 6px 12px 6px 12px

You could actually just have
margin: 6px 12px

And in those odd cases where you have
margin: 6px 12px 25px 12px

You could actually just have
margin: 6px 12px 25px

And of course, you could always just have
margin: 6px

Here’s how I’ll remember this: If you see a pattern duplicated, eliminate the duplicate. 6px 12px 6px 12px becomes just 6px 12px.