Rob Eberhardt

cleverness ensues

skip navigation

 Friday, June 24, 2005

From a Kentucky neighbor (whom I found via GeoURL), Chris Vaught writes about How to Start and Keep Blogging.

Good as it is, I have little more to add by blogging...
about blogging...
about blogging.
I guess it's just that good!

(So does this count as using my English Major, Mike? :>)

6/24/2005 4:32 PM Eastern Daylight Time  #    Disclaimer  |  Comments [1]  | 

*sigh*, more comment Spam today -- 150 in a few minutes, despite my nice new .Text spam filters (they were all identical).

Unfortunately, I can't just go into blog_content and delete the range (since the comment count wouldn't be updated), and I didn't want to click [Delete], [Yes], [Continue] 150 times, SO: I just fired-up SQL Profiler, reverse-engineered a standard delete call, and slapped together a utility Stored Procedure to loop that call, for big cleanup jobs.

It takes IDs for the first and last comment spam which make it through, and wipes them all out with .Text's native blog_DeletePost stored proc.  Just paste this into Query Analyzer and run to install:

CREATE PROCEDURE re_wipe_commentrange 
@p_ID int,
@p_lastID int
AS

DECLARE @v_sql varchar(8000)
WHILE @p_ID <= @p_lastID
BEGIN
	SET @v_sql = 'exec blog_DeletePost @ID = ' + cast(@p_ID as varchar(5)) + ', @BlogID = 0'
	EXECUTE(@v_sql)
	SET @p_ID = @p_ID + 1
END
GO
(Note: this is for single user .Text blogs.  Multiple-user blogs will need fiddling with the embedded BlogID parameter.)

Then to use it, call like so in QA: EXEC re_wipe_commentrange 900, 1000.

Might save someone a few minutes (even with writing and posting it here, I think I'd still be clicking delete right now).

Time to consider a way to implement MT-Blacklist...

6/24/2005 2:32 AM Eastern Daylight Time  #    Disclaimer  |  Comments [2]  | 

 Monday, June 13, 2005

Yes, this sounds like an all-too-familiar "Intro to Web Scripting" class or article, but I haven't actually seen these more advanced scripting topics compared before, so I wanted to nail it down in print. 

feature Javascript VBScript
Object-Oriented: Very powerul and easy to create custom object classes Now supported with version 5+ CLASS construct, but is comparatively less powerful and syntax is much more verbose
Object-Based: More object-based, wraps core functionality in intrinsic objects like Date, Math, Number, String, and Array Less object-based, dumps functionality into global functions
Optional procedure arguments: Supported Not supported! (hence kludgy workarounds)
Getter/Setter properties: Not supported! (yet?) Supported
Dialog/User-input support: None built-in, depends on the current object model (e.g. window.alert/prompt/confirm, or WScript.Echo/popup). Has powerful native Msgbox and Inputbox functions.
Convenience tools (aka synactical sugar): Few (escape/unescape?) Plenty (Explicit Conversions, Formatting, Dates, Strings)
Date Manipulation: Difficult (hence the need for a Javascript Date library Easy (see convenience tools)
Leftovers/Quirks:
• Has ternary operator (e.g. var foo= true ? 'bar' : 'grep';
• No ternary operator and no IIF function like VB (but a custom IIF can be added).
General strength Powerful, more "nuts&bolts" Easy-to-learn, more common functionality built-in
General weakness Some common tasks are much too inconvenient Verbose, disorganized, weak OO capabilities
key: good  bad  eh..

Yes, of course it's my opinion, based on experience (and frustration!)  Feel free to proselytize me otherwise, but back it up!

My perspective is this: scripting languages are about convenience -- quickly whipping out something that works, is readable, and is maintainable.  If you want perfect academic code, or fastest performance, get another tool!  For scripting languages, the less code and reference to accomplish a task, the better.

Interestingly, different scripting languages reach convenience by different routes.  For example, where VBScript chooses a "simple" route of a bunch of unorganized global functions, Javascript groups them as methods of intrinsic objects.  Normally I prefer simple, but Javascript's better organization makes me more efficient: I don't have to remember 90 or so distinct global functions -- if I can simply remember the object (Date/Array/whatever), then I'm set, because VS.net's Intellisense will help me quickly find the method I need without cracking a reference.

(Aside about Intellisense: it reminds me of the tabs -vs- spaces debate: I say tabs all the way.  Any decent code editor should be able to display tabs how you like.  Fewer characters to store/send, and less arrowing around pays for itself.  And yes, a coder should be using a decent code editor!)

To be clear, I favor neither VBScript or Javascript as a rule -- each has its time and place (goal of this chart).  Ideally, I'd like to marry them for the best of both.  Both Classic ASP and WSCs can use both in the same context, which rocks.  Too bad ASP.net lost this feature, but it matters less since it now runs full-fledged programming languages.

Finally, for entertainment, here's a hilarious thread on the "JS-vs-VBS" subject.  My favorite quote: "IF JScript was a movie, it'd be Citizen Kane, or The Shining. VBScript would be the Mariah Carey movie, or possibly 'Sgt Pepper's Lonely Hearts Club Band' starring Peter Frampton and the Bee Gees."

Update: added ternary/IIF note to chart 'leftovers'.

6/13/2005 5:45 PM Eastern Daylight Time  #    Disclaimer  |  Comments [3]  | 

Now that I'm color-coded, I may start a regular feature here where I publish smallish code bits I've written...

For WSH scripters out there, here's a handy one I wrote...

To explain, for GUI-type WSH scripts (usually run under the WScript engine), VBScript has a native Inputbox function, which prompts for user input via a dialog box.  Command-line-type scripts (running under CScript) have no command-line equivalent, though -- yes Inputbox works, but a GUI dialog doesn't really fit a command-line script.

So to fill that gap, I wrote this:

' Name:		InputLine
' Desc:		like Inputbox, but for use with cscript
' Author:	Rob Eberhardt, www.slingfive.com
' Params:	prompt as string, default value as string
' Returns:	user's answer
' History:
'		2005-06-13	added default param
'		2005-02-28	created original InputLine function
FUNCTION InputLine(p_strPrompt, p_strDefault)
	call Wscript.Echo(p_strPrompt & ":")
	IF p_strDefault<>"" THEN CreateObject("WScript.Shell").SendKeys(p_strDefault)
	DIM strInput
	Do While Not WScript.StdIn.AtEndOfLine
		strInput = strInput & WScript.StdIn.Read(1)
	Loop
	WScript.StdIn.skip(2)
	InputLine = strInput
END FUNCTION

Example usage:

DIM strChoice
strChoice = InputLine("Enter favorite color", "Red")
call WScript.Echo("You entered: " & strChoice)
...which would look like this from a command-line:
Enter favorite color:
Red
You entered: Red

For bonus points, you can detect if the current engine is CScript or WScript, and use InputLine or InputBox appropriately (like if you're note sure what engine will run your code):

DIM strChoice

'detect CSCRIPT context & use InputLine
IF Instr(lcase(wscript.FullName), "cscript")>0 THEN	
	strChoice = InputLine("Enter favorite color", "Red")

ELSE	'detect WSCRIPT context & use native InputBox
	strChoice = InputBox("Enter favorite color", "Color?", "Red")

END IF

call WScript.Echo("You entered: " & strChoice)

Hope someone can use it.

Note: I would have absorbed this engine detection logic into a single smart InputLine-like function, if only Javascript supported Inputbox, or VBScript supported optional arguments.  But, InputBox's optional 2nd "Caption" param makes no sense with InputLine, and unfortunately the languages leave no room to gracefully work around that.

6/13/2005 3:46 PM Eastern Daylight Time  #    Disclaimer  |  Comments [1]  | 

 Thursday, June 09, 2005

, and 90% were spam.

But I just got me a nice new .Text Anti-Comment-Spam SQL Trigger (in addition to the Anti-Referral-Spam SQL Trigger I've had the whole time!).
  ...Looks good so far!

6/9/2005 7:53 PM Eastern Daylight Time  #    Disclaimer  |  Comments [4]  | 

Trying out the new Windows Update v6 (now called "Microsoft Update").  Cool that they've finally integrated Office Update and other products (SQL Server for instance).

A few observations, though:

  • It took several ActiveX installs, plus closing and restarting IE for it to actually load fully.
  • Windows Update has been slooow for me lately (before this version even). Dunno why, but it still is. 
        Update: same slowness on sparkling fresh XPSP2 and SBS 2003 installs.  It ain't me.
  • Still a ton of French Spell Checker updates?? (2 for Office, 1 for Visio, 1 for Project) I saw this a lot with Office Update too. I have no French anything on any machines, so what's the deal?.

About time to reboot...

6/9/2005 3:14 PM Eastern Daylight Time  #    Disclaimer  |  Comments [4]  | 

 Tuesday, June 07, 2005

My friend Mike Butler posted a thought-provoker about blog self-censorship and choosing topics.

I've struggled with that dilemma too.

One one hand, I want my family, friends, and strangers to be able to read my blog without being offended or bored.  On the other, I need to express myself freely.  I realized early with this blogging venture that I have a habit of putting on personas for each situation.  That bugged me since it seemed disingenuous, and it was making me second guess myself.  I think I settled on making my blog just For Me (at least as far as topics) -- including the tech-geek, the father, the immature Jr. High dork, the business man, the music-fan, the navel-gazing philosopher, etc.

If a subject bores or bothers someone in real life, they have to grit their teeth.  Here at least they can ignore me without worrying about my feelings :>

I think my goal is no longer about avoiding boring/scaring people away, but rather trying to attract people by giving each of my facets a balanced representation.  For example, Me-the-father hasn't really posted yet (mostly due to the sheer magnitude of the thoughts I want to distill into a post), so there's a whole audience I've missed so far. 

Good food for thought.  Thanks Mike.

6/7/2005 2:56 PM Eastern Daylight Time  #    Disclaimer  |  Comments [1]  | 

 Friday, June 03, 2005

HTTP Compression is a wonderful idea.  Unfortunately, its implementation in IIS 5 was deeply flawed

Besides the usual issues, I've also found that HTTP Compression breaks Data Source Objects (DSOs) and Tabular Data Controls (TDCs) in IE (wonderful features for client-side data-binding in web apps).  IE loads the data (showing "XX items remaining" counting down in the status bar, and eventually "Done"), but it never data-binds to the table template or gives any error messages, leaving an empty table.  My guess is that IE uses a different mechanism for requesting DSO data resources from a webserver than it does for normal resources (pages and their referenced files like scripts, stylesheets and images).  I've never seen this issue documented by anyone else, which I attribute to the relative obscurity of DSOs and TDCs (they were never marketed to devs enough).

So you can imagine it was a big pain figuring this out the first time...

When IIS 6 came out, I heard a lot of excitement that it fixed HTTP Compression, so I was excited too.  Well I've recently/finally moved into IIS 6, enabled HTML compression, and then just got confused all over again today because my TDCs were broken.  Grrr...

Sure enough, turning off "Compress Application Files" (and restarting IIS) fixed it.  At least IIS 6 gives separate compression settings for dynamic and static files, so now I'm just compressing static files (e.g. HTML, CSS, JS, VBS, HTC), which should still help a bit (of course those files are cached by the browser anyway...).

Apparently Jeff Atwood has also found other big issues with IIS 6's HTTP compression.   He's got a lot of good info, plus a handy metabase snippet to help fix those problems.  Check it out.

6/3/2005 4:23 PM Eastern Daylight Time  #    Disclaimer  |  Comments [0]  |