Fluid Grids

Saw this article today on relative font sizing using em units. Very nice. I’ve been using percentages for a while, but this seems a little more designer-friendly.

Fluid Grids: “How awesome would it be if you could combine the aesthetic rigor and clarity of fixed-width, grid-based layouts with the device- and screen size independence and user-focused flexibility of fluid layouts? Completely awesome, that’s how awesome. And with a little cunning and a tad of easy math, ALA’s Ethan Marcotte gets it done. We smell a trend in the offing.”

(Via A List Apart.)

Easy way to lock your Mac.

When I switched from a Windows box to a Mac, oddly enough the thing that I missed the most was the Windows+L hotkey to lock my screen. I tend to work in coffee shops and restaurants a lot, and if I get up to get something to drink or stretch my legs, I don’t like to leave my computer wide open. I know, someone could always go for the grab, but I’m just interested in discouraging the idly curious.

After googling around a little, I found out about the Login Window menu item (accessed through your user name in the menu bar), which is nice. But I was poking around with System Preferences (under the apple menu) yesterday and I came across the Exposé feature. It lets you assign actions (like run the screensaver) to “hot corners” of your display. Now, all I have to do is drag my mouse to the lower-right corner of my screen and the screensaver pops up. Almost as good as the old hotkey!

Free Internet at Starbucks (finally)!

Ok, so I’ve ended my long-running (5+ years?!?) feud with Starbucks because I can now get free Internet. In fact, I’m typing this from the Starbucks at the Columbiana Mall right now. The secret steps to getting your free access are:

1) Buy a Starbucks gift card. The minimum amount is $5, so guess how much I paid.
2) Fire up your laptop and look for a link on the free WiFi greeting page about “Complimentary Wifi”.
3) You’ll need to create a free Starbucks.com account using the new gift card # and the secret PIN (which you have to scratch-off).
4) Enjoy the yummy free WiFi!

The mother of all dynamic SQL Crosstab View Builders.

Ok, so maybe it’s not too poetic, but it’s descriptive. As I found myself writing a dynamic crosstab-query builder in MS SQL for probably the fifth time of my career, I decided I’d post it here to save you all just a little time in your day. Make sure you use the saved time for something I’d approve of (smoking a good cigar, playing a little poker, something like that).

This proc is designed for when you have a dynamic set of row-oriented data you want to pivot and show column-wise. It takes four parameters:

@tableName – Name of the source table (or view) that will be queried by the new crosstab view.
@excludeCols – A comma separated list of columns to exclude from the crosstab. In most cases, will be the ID column of the table.
@valueColName – Name of the column in the @tableName table that contains the value in a given row.
@targetViewName – Name of the view that the stored procedure will create. It will *automatically* drop this view before re-creating it, so be warned.

This proc also assumes that the @tableName table (or view) has a column called [colName]. It uses this value to create the corresponding columns across the top of the output view.

Good luck!


ALTER PROCEDURE BuildCrosstabView(
@tableName VARCHAR(100),
@excludeCols VARCHAR(1000),
@valueColName VARCHAR(1000),
@targetViewName VARCHAR(100)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @cols VARCHAR(4000)
SET @cols = ''

EXEC ('SELECT DISTINCT colName INTO ##colList FROM ' + @tableName)
DECLARE col_cursor CURSOR FOR
SELECT colName
FROM ##colList

OPEN col_cursor

DECLARE @colName VARCHAR(100)

FETCH NEXT FROM col_cursor INTO @colName

WHILE @@FETCH_STATUS = 0
BEGIN

IF @cols <> ''
BEGIN
SET @cols = @cols + ', '
END

SET @cols = @cols + 'MAX(CASE colName WHEN ''' + @colName + ''' THEN ' + @valueColName + ' ELSE NULL END) AS [' + @colName + ']
'
FETCH NEXT FROM col_cursor INTO @colName

END

CLOSE col_cursor
DEALLOCATE col_cursor

DROP TABLE ##colList

DECLARE @sql VARCHAR(3000)
SET @sql = 'SELECT DISTINCT ' + @excludeCols + ', ' + @cols + ' FROM ' + @tableName + ' GROUP BY ' + @excludeCols
PRINT @sql
EXECUTE (@sql)
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[' + @targetViewName + ']'))
EXECUTE ('DROP VIEW ' + @targetViewName)
EXECUTE ('CREATE VIEW ' + @targetViewName + ' AS ' + @sql)
END
GO

Bulk SQL inserting, anyone?

As part of the BlinkStory app, I needed to upload about 200K (200 thousand, for the geek-impaired) records into a MySql database hosted on a very inexpensive (cheap) hosting provider. I’d tried several options to get the data in, with frustrating results. Either my file upload would be interrupted, or an error would occur around row 75K, wasting an hour or so of my time.

So I decided, like any good programmer, to roll my own solution. I created a tool for bulk uploading SQL over the Internet that I call mysqlxfer. Not wanting to hoard it, I submitted it to SourceForge.net as an open source project. If you need to upload a bunch of data over an unreliable and slow connection, give it a shot. It does a couple of cool things, like automatically detecting your field separator character and logging the failed inserts in SQL format to a .err file. Check it out!

« Previous PageNext Page »