Monday, September 13, 2010

Storing a Directory Path with a Space and Using it in PowerShell

Step 1: Store the path in a variable like so
$7Zip = "C:\Program Files (x86)\7za.exe"

Step 2: Wrap the reference in the double quotes and precede with the call operator like so
ForEach-Object { &"$7Zip" a ($_.fullname -replace "txt", "zip") $_.fullname }

Step 3: Complain silently in your head about the time you wasted trying to figure that out.

Friday, July 30, 2010

Find a Column in Your Database by Name

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%isTextbook%'
ORDER BY schema_name, table_name;


Props to SQL Authority.

Friday, July 23, 2010

Convert HTML Stored in SQL Server as varbinary to Text

I have a wonderfully exciting legacy database I'm handling and it contains a varbinary(MAX) field with HTML. For debugging purposes, every once in awhile I need to dig in and review what's stored there. Here's how I do that:

SELECT CONVERT(VARCHAR(MAX), mainText) AS htmlString FROM entry WHERE entryid = 1380915

Thursday, June 24, 2010

A Little URL Rewriting with Managed Fusion Rewriter

I'm stuck on IIS 6 for now and I needed to do a bunch of URL rewriting. No one wants to spend money these days, so we didn't spring for the Helicon ISAPI_Rewrite product. I have a lot of legacy URLs to handle, but we won't keep them in place for more than a year and by that time we'll likely be on IIS 7 with its own rewriting tools.

I went with the Managed Fusion Rewriter tool both for its promised flexibility and the fact that it used the Apache mod_rewrite syntax.

I like it, but I ran into a few quirks I thought I'd pass along.

First, if you're using RewriteCond and trying to grab query string parameter values, %1 will hold the name/value pair. %2 will hold the value you're probably looking for. If you have multiple values you're catching you would just continue to increment -- %3, %4, etc. Here's an example that works as I expected it:

RewriteCond %{QUERY_STRING} ^lessonid=([0-9]+)$
RewriteRule ^/Explore/KeyQuestions.aspx$ /Analyze/Display/%2 [R=301,NC,L]


Second, in mod_rewrite you can apparently stack multiple RewriteCond one on top of another. I was not able to get it to work with this tool.

Friday, June 11, 2010

New Phrase: Smells Like Mountain Oysters To Me

I suggest the casual usage of a new phrase: smells like mountain oysters to me.

What does it mean? Roughly, it means someone's trying to make you look like an fool, possibly in front of others, but definitely for their own gain. It could also simply mean someone's trying to feed you a line of bullshit.

Would you eat a bull's testicles? Neither would I, but that's what mountain oysters are. The thought of that makes me want to vomit. No one should be eating anyone else's balls. Ever. Calling them "mountain oysters" is so ridiculously misleading to me that it makes me want to punch your mom.

By the way, if you're reading this and you would eat them, stop reading my fucking blog and never ever come back.

So....

The next time you suspect someone's trying to get you to do something and you think they're withholding key information, smells like mountain oysters to me.

The next time someone's asking you questions and you think they're going to use the information against you in some way, smells like mountain oysters to me.

The next time you think someone's intentionally trying to lead you into making a bad decision to advance their own goals or just to entertain himself, smells like mountain oysters to me.