Thursday, November 29, 2007

Vista Screen Saver Started Working Again!

A few weeks ago, my Dell Inspirion 1501 laptop, running Vista, suddenly stopped displaying screen savers for some reason. I tried everything I could Google, including rolling back to a restore point, downloading the new HID driver, playing around with a wireless mouse, etc.

This morning, my wife and I were discussing lithium ion batteries, and I removed mine from my laptop (to check the manufacture date). When I put the battery back in, the screen saver magically started working again. Go figure. Something to try if you're having the same problem...

Saturday, November 17, 2007

Vista Mail Using 100% of CPU?

When I got my new Dell Inspirion 1501 laptop, one of the first things I did was port my email from Outlook Express that was on my old Windows XP desktop.

Ever since, every time I open Vista Mail, the CPU shoots up to 100%, and stays there for hours. I finally, accidentally, figured out the cause. I was looking for certain files on my hard drive, and noticed I had hundreds and hundreds of zero-byte EML files. So I searched for all EML files (using Agent Ransack), and found 41,000 of them - 30,000 of which were zero-byte!

After I deleted the empty ones, Mail immediately started behaving normally. Of course, that was three days ago, and when I checked just now, I see I have 284 empty EML files. Haven't Googled to see what may be going on, but I'm just glad for now Mail works correctly. For a while, at least. Now if I could just get any screen saver to start working again...

Thursday, November 15, 2007

TinyUrl.com for Long E-mail Addresses

When you're job hunting, you realize the importance of an e-mail address that's easy to spell and pronounce. Both in phone conversation, or when someone is reading a hardcopy of my resume, it's much easier to work with TinyUrl.com/LAL-2010 than with www.larryleonard.net/files/LarryLeonardResume.docx.

Now if only the nice people at TinyUrl.com would you let you pick you own tiny url... "tinyurl/lal77", for instance!

Tuesday, October 2, 2007

An Unabashed Brag

When I was a contractor at The Coca-Cola Company back in 1994, during a seasonal lull, I was tasked with creating a "consumer presence" screen-saver for the company, and SkiBear was the result. I wrote it in C, targeting Windows 3.1, and used a cutting-edge (at the time) technique called 256-color palette "black-mask" animation.

You can still, 13 years later, find SkiBear at various freeware sites around the web; Googling for "skibear screen saver" led me to http://tinyurl.com/3xe5ay . The download is just 64 KB, and that includes a help file, a read me file, and several images! Those were simpler times.

The thing I'm quite proud of (and a little amazed, to be honest) is that it runs on every version of Windows starting at Windows 3.1all the way up to Windows Vista. This is a testimony to something, but I'm pretty sure it's not the programming skills I had in 1994. Probably has more to do with being written in C, directly against the Win16 API: no MFC, no OLE, no .NET. May be a lesson in there somewhere.

One interesting experience was trying to get the stars in the night sky to look realistic. My first thought was that they should simply be spread out randomly: that turned out to look very, very fake, which puzzled me. Are stars not spread out randomly from any vantage point? So, I began experimenting with various simple algorithms, and after a few days (hey, I was a contractor, during the holiday season), I finally came up with a scheme that worked pretty well. I would randomly place a star, and then position four or five stars near it, at increasing and random distances and directions. After that, I simply randomized the brightness of the stars (which did work well), and threw in the occasional red, blue, and yellow stars.

I still don't understand why a random dispersal didn't look realistic; anyone have any ideas? (I'm familiar with the plane of the Milky Way galaxy, Olber's Paradox, gravitational lenses, etc., but would love to hear a definitive answer.)

The "System Requirements" page is funny to read now:

SkiBear® requires Microsoft Windows 3.1 or greater. Full installation requires approximately 260k of disk space. For optimal results, a VGA monitor displaying at least 256 colors is recommended.

Due to the highly graphical nature of this screen saver, your PC's 'System Resources' must have at least 25 per cent free for the skiing bears to be displayed; otherwise, a minimal, 'StandBy' screen saver will appear. This 'StandBy' saver simply blacks the screen and scrolls a multi-color message across the screen (it also provides the standard password protection). You can check how much free System Resources you have by clicking the 'Help, About Program Manager...' menu item in the Windows Program Manager.

Thursday, September 27, 2007

Script to Find Disk Space Occupied by a Table

Before SQL Server 2005 Enterprise Manager made it easy, I used this script to figure out how much disk space a table took up, and the "real" (average, at least) width of a row.

-- Lists the tables in the selected database and the disk space they use. 
-- Also displays the average 'width' of each row in each table. 
SET NOCOUNT ON
DECLARE @sSourceDB AS sysname
SET @sSourceDB = 'Northwind'    -- <====== Set this value.

-- Holds the space used for each table. Column names reflect sp_spaceused().
CREATE TABLE #SpaceUsed 
(
   name       VARCHAR(128),
   rows       VARCHAR(11),
   reserved   VARCHAR(18),
   data       VARCHAR(18),
   index_size VARCHAR(18),
   unused     VARCHAR(18)
)

-- Create and open a cursor on the tables.
DECLARE curTables CURSOR 
    FOR 
 SELECT TABLE_NAME
   FROM INFORMATION_SCHEMA.TABLES
  WHERE TABLE_CATALOG = @sSourceDB
    AND TABLE_TYPE = 'BASE TABLE'

OPEN curTables 

-- Iterate the cursor, populating #SpaceUsed for each table from sp_spaceused().
DECLARE @sTableName sysname

FETCH NEXT
   FROM curTables
   INTO @sTableName 

WHILE 0 = @@FETCH_STATUS
BEGIN
   DECLARE @sSql SYSNAME
   SET @sSql = 'EXEC ' + @sSourceDB +
               '..sp_executesql N''INSERT #SpaceUsed EXEC sp_spaceused ' +
               @sTableName + '''' 
   PRINT @sSql
   EXEC(@sSql)

   FETCH NEXT
      FROM curTables
      INTO @sTableName
END

CLOSE curTables
DEALLOCATE curTables 

-- Display results.
SELECT
   name       AS 'Table Name',
   rows       AS 'Row Count',

   CASE CAST(REPLACE(rows, ' KB', '') AS INT)
       WHEN 0  THEN 'N/A'
       ELSE         1024 * CAST(REPLACE(data, ' KB', '') AS INT) /
                           CAST(REPLACE(rows, ' KB', '') AS INT)
   END        AS 'Avg Bytes/Row',

   data       AS 'Data Space +',
   index_size AS 'Index(es) Space +',
   unused     AS 'Unused Space =',
   reserved   AS 'Total Space'
  FROM #SpaceUsed
 ORDER BY CAST(REPLACE(reserved, ' KB', '') AS INT) DESC

-- Done.
DROP TABLE #SpaceUsed

Wednesday, September 26, 2007

Mostly Microsoft SQL Server Stuff

This blog will mostly be a place to publish my SQL Server T-SQL scripts, in the hope that someone else will find them useful. Currently, the focus is on SQL Server 2000, but hopefully that will change soon.