Showing posts from 2006

Does this dress make me look fat?

Here's a nice little bit of code that can be used to dynamically theme a website that has multiple domains at the same site.
using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; namespace URLThemeHandler { public class ThemeHandler : IHttpModule { #region IHttpModule Members public void Dispose() { } public void Init(HttpApplication context) { context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute); } void context_PreRequestHandlerExecute(object sender, EventArgs e) { HttpContext currentContext = HttpContext.Current; if (!(currentContext.Handler is System.Web.UI.Page)) return; System.Web.UI.Page myPage = currentContext.Handler as System.Web.UI.Page; string strHost = currentContext.Request.Url.Host; if(ThemeExists(strHost)) myPage.Theme = strHost; } bool ThemeExists(string theme) { string strPath = HttpContext.Current.Server.MapPath("~/App_Themes/" + theme); return System.IO.Directory.…

Can you hear me NOW?!?!

My wife is very disgusted with our packet8 telephone. Part of the issues we're facing are that our Belkin router will block the outbound voice (thinking that it is a DOS attack). In the security log, there was this entry:

07/17/2006 18:35:57 **UDP Flood to Host**, 8006->>, 62602 (from WAN Outbound)

So, thanks to a technical article I found, there is a support page that references this URL: which allows you to turn off the "SPI and Anti-DoS firewall protection:"

It should be easier to turn off a feature like this than an undocumented feature.

It's about time...

Time and space. Two of my favorite things. Time keeps everything from happening all at once. Space keeps everything from happening to you. Time AND Space keep everything from happening all at once to you!
The problem to be solved today is this: Create a .net object that has it's XML serialization saved to an XML column in a database table. Now, have a trigger (add/update) that takes that XML field and denormalizes its content to some additional columns. In this way, you have the denormalized data that you might want to use for joins and filtering without having to parse the XML field over and over.
You'd create a class something like this:
public class Foo { Guid _id = Guid.NewGuid(); //This is our object's database identifier DateTime _updated= DateTime.Now; //This was the last time the object was changed string _description = string.empty; public Guid Id{ get{return _id;} set{_id = value;} } public string Description { get{return _description;} set{_description = valu…

U-Turn (Going the other way)

So, here's a way to get back a delimited list of items from a table. In other words, concatenate values into one column (that you can then take together to pass to my parse table function).

--Setup a sample data to demonstrate the concept declare @Table1 as Table (id int, Item varchar(100)) insert into @Table1 values (1, 'a') insert into @Table1 values (1, 'b') insert into @Table1 values (2, 'c') -- show the table data select * from @Table1 --retrieve the data from @Table1 as a concatinated list Select distinct id, ( Select upper(Item)+' ' as [text()] from @Table1 S where id = for xml path('')) Items from @Table1 T1

A mighty conversion

I recently ran into a situation where I needed to create an array of integers to a comma-delimited string in .Net. This *should* be easily accomplished by some sort of intrinsic function (like .toString()). But alas, no. So, you can do this (and other sorts of arrays in the following manner:
string strCSV = string.Join(",", Array.ConvertAll<int,string>(SkuList, new Converter<int,string>(Convert.ToString)));
Going the other way you can use something similar to turn the whole thing inside out:
int[] result = Array.ConvertAll<string,int>(strCSV.Split(new char[] { ',' }), new Converter<string,int>(Convert.ToInt32));

X-Men Code 127

One of the more interesting things about SQL Server 2005 is the support for the XML datatype. Instead of playing around with wierd and funky stored procedures to manipulate XML, you get validation and a bunch of other features just by specifying a field or a parameter as XML.
Now, as nice as it is to be able to serialize a .net object and store the entire thing in one field in the database, I have my feelings that there is significant overhead to querying into that XML on a more than ad-hoc basis. So, you *might* want to add some additional fields to the table containing the xml. For example if you had the following XML:

<OrderLine ItemId="123" Quantity="2" Taxable="false" Price="12.34"

What!?? No clever title?!??

No clever title for this one. Just a reminder that you can turn on tracing in an web page by including the following in your page directive:
<%@ page trace="true" %>

And, lest you tire of remembering which specific pages you have this enabled on, you can turn on tracing for an entire application by including the following in the web.config:
<trace enabled="true" localonly="true" tracemode="SortByTime" pageoutput="true" requestlimit="10"><trace enabled="true">

Apple Core...Baltimore...Who's your friend?

I've always had a soft spot in my heart for Apple. While it wasn't my "first" computer, (that was a Commodore Pet), The Apple II was the computer where I learned about data structures, graphics, and really did some useful programming. In college when I needed to get a computer, I bought a Macintosh IIsi. While my computer programming career has been mostly Windows-centric, I still like the elegance and simplicity of products from Apple; especially when they are free.

After playing with Music Match and other music programs, I've pretty much decided to use iTunes in my home as a music library management and MP3 player. I like it's playlist management features, the fact that it is easy to rip and burn physical CDs and the user interface is simple and elegant. The visualizations are cool too. I don't buy much music through the iTunes store (only one to date), but I do buy music on CD and want to be able to listen to it without physically handling the CDs; or m…

Master and Commander

I just thought I'd put my favorite registry hack here. Create a text file with a .reg extension with this text:
Windows Registry Editor Version 5.00

@="Command &Prompt"
Once you have the file saved, just double-click it and merge it with the registry. This adds a context menu that can be used in the explorer to open a command prompt window to the highlighted folder.

How to skin a Turkey

Here is a very useful function created to parse a delimited list in TSQL. It is fairly straight forward. Pass the string to be parsed and the delimiter (defaults to a comma) and it returns a table with a single column containing the strings that were delimited together. Why Microsoft doesn't have something like this built in is beyond me.

CREATE FUNCTION dbo.fn_ParseDelimitedList ( @DelimitedList varchar(8000), @Delimiter char(1) = "," ) RETURNS @TableVar TABLE (Item varchar(100) NOT NULL ) AS BEGIN DECLARE @IDListPosition int DECLARE @IDList varchar(8000) DECLARE @ArrValue varchar(8000) DECLARE @Pattern char(3) SET @IDList = COALESCE(@DelimitedList, '') IF @IDList <> '' BEGIN -- Add Trailing delimiter to end of list so user doesn't have to IF RIGHT(@DelimitedList,1) <> @Delimiter begin SET @IDList = @IDList + @Delimiter END SET @Pattern = '%' + @Delimiter + '%' -- Loop through the comma demlimted string list WHILE…