Monday, February 12, 2007

SQL Server: How to shrink transaction logs

This is just a sequence that I forget sometimes-- every now and then I get a transaction log that is bigger than I want it to be. This shrinks it pretty well. One thing to be cautious about: make a full backup of the database after you do this.




use MyDatabase
go
checkpoint
go
backup log MyDatabase with truncate_only
go
dbcc shrinkdatabase(MyDatabase)
go
dbcc shrinkfile(MyDatabase_Log)


Now, make a complete backup of the database.




23:20 - Vine Street / Vurt by Jeff Noon

It's been a while since I wrote up a run, though I've been running pretty regularly. I think I'll be gearing up my running time again, as my yoga practice has come to a standstill.

I listened to an audio recording of Vurt, by Jeff Noon. It has to be the best audio book I've ever heard. It tells the story of a group of Manchester kids who are hooked on Vurt feathers, a drug that lets the user experience virtual reality as a dream (the mechanism is never made really clear, which adds to the intrigue). I picked up this recording in Denver well over ten years ago, and I never get tired of it. It ranks right up there with Hitchhiker's Guide to the Galaxy.

Saturday, February 10, 2007

VBScript/VB: How to write error messages to the Event Viewer

I work in a small IT shop where I do all of the internal programming, but also pitch in on help desk duties. Users often call because they got an error message, but cancelled it immediately without reading it.

I've often thought that it would be a good idea to write an entry to a log with any error message text that a program displays, so that a tech can read the error log when a user has cancelled the error message away.

I write a lot of VBScripts and VBA code. In Windows, there is a mechanism for putting messages directly in the event viewer log:




Set WshShell = CreateObject("WScript.Shell")
WshShell.LogEvent 1, "Error 972: Could not invert A-Frame"
WshShell.LogEvent 4, "Information Message: Everything went fine."


This has now become a standard part of my standard error-handler block in VB:




eh:
dim WshError
Set WshError= CreateObject("WScript.Shell")
WshError.LogEvent 1, "Error " & err.number & ": " & err.description


I'm going to start adding this for all of my programs whenever I display messages to my users. What I think would be cool would be if they API for displaying message boxes would include a "WRITE TO EVENT VIEWER" parameter as well.

Tuesday, February 6, 2007

VBScript: how to run a program from vbscript

I always need this one: how do you run a program from within VBScript? For example, you may need to launch notepad or wget from a VBScript. Here is the code to launch notepad:


sub shell(cmd)
' Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

shell "notepad"

Put that in a text file called "run_notepad.vbs", doubleclick it, and notepad will run. This may not seem too useful, but imagine that you use VBScript to run a series of WGETs, for example, based on input from SQL Server.


UPDATE

I have had a lot of requests for enhancements to this program. The following is the cadillac version. It calls an EXE and asks the user for parameters to pass to the EXE.

 
sub shell(cmd)
' Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

dim file_name
' Ask the user for a parameter
file_name = inputbox("What file to see?", "File name?", "c:\boot.ini")
if file_name <> "" then
' The user gave the parameter. Open the program
' with the value the user gave.
shell "C:\WINNT\system32\notepad.exe " & file_name
else
msgbox "User cancelled.", 16, "User cancelled"
end if

Monday, February 5, 2007

888-226-3713 - Blue Green Resorts (Be careful)

I get a call from the same number on my cell phone every day: 888-226-3713. When I answer the call, the caller hangs up immediately.

I finally decided to call the number back from my work phone. A recorded announcement thanked me for calling back, and said that the call was from Bluegreen Resorts. The recording pitched some 3 day trip to Vegas.

I thought this sounded fishy, so I Googled "bluegreen resorts", and about the 3rd link was for The Ripoff Report.

I have no direct experience with Bluegreen Resorts, but I would say that in the very least, you should proceed with caution if you deal with them.

(Note: that number was 8882263713, Bluegreen resorts.)

Tuesday, January 30, 2007

Bikram Yoga Session after months of inactivity

These last few months have not been good for my Bikram practice. I've probably made it in less than 10 times in the last three months. Between getting sick for a while, going to Barcelona, and the warmth of the bed vs. the cold of the street at 5AM, it has started to seem like less and less of a good idea to go to Bikram. Which is a shame. I really like the studio where I go (http://www.bikramphiladelphia.com). I've gotten to be friends with the owner there, Joel. And I feel better when I do it. So I'm going to try and get in more for the next week or two and see what comes of it.

Friday, January 26, 2007

Perl program to calculate major triad chord progressions

I've been playing guitar for 31 years (good lord I'm old). But I only recently got interested in learning the theory behind chord progressions. I wrote this simple piece of code to calculate major triad chord progressions in all of the keys. I suppose it could be extended easily to create minor chord progressions as well.




use strict;

sub chord_progression
{
# The parameter is the index of the root note in the @notes array
my $i = shift;
my @notes = ('C', 'C#/Db', 'D', 'D#/Eb', 'E', 'F', 'F#/Gb',
'G', 'G#/Ab', 'A', 'A#/Bb', 'B');
my @intervals = (0, 2, 4, 5, 7, 9, 11, 12);

# Create a scale based on the intervals in a major scale
my @scale = map {$notes[($i + $intervals[$_]) % 12]} (0..7);

# Create triads. Increment each note within the scale.
# All notes in the chord progression fall within the
# major scale.
my ($root, $third, $fifth) = (0, 2, 4);
my @name = ('Maj', 'min', 'min', 'Maj', 'Maj', 'min', 'Dim', 'Maj');
for (0..7) {
printf "%6s %3s: %6s, %6s, %6sn",
$scale[$root], $name[$_], $scale[$root],
$scale[$third], $scale[$fifth];
$root++;
$third++;
$fifth++;
$root %= 7;
$third %= 7;
$fifth %= 7;
}
print "n";
}

# Call the subroutine for each note in the scale
for (0..11)
{
chord_progression($_);
}


This produces output like this for the 12 root notes:



C Maj: C, E, G
D min: D, F, A
E min: E, G, B
F Maj: F, A, C
G Maj: G, B, D
A min: A, C, E
B Dim: B, D, F
C Maj: C, E, G
----------------------------------
C#/Db Maj: C#/Db, F, G#/Ab
D#/Eb min: D#/Eb, F#/Gb, A#, Bb
F min: F, G#/Ab, C
F#/Gb Maj: F#/Gb, A#, Bb, C#/Db
G#/Ab Maj: G#/Ab, C, D#/Eb
A#, Bb min: A#, Bb, C#/Db, F
C Dim: C, D#/Eb, F#/Gb
C#/Db Maj: C#/Db, F, G#/Ab
...

Thursday, January 18, 2007

18:51 - Center City

I went for a quick run today, bundled up as it has gotten very cold. I just looped around center city and watched the people. It started snowing just a little after I stopped-- a pity, I've always loved running in the snow.

Monday, January 15, 2007

12 years

I celebrated 12 years today. Not much to say about that, another little miracle in a long series of little miracles.

Sunday, January 14, 2007

Back from Rome and Barcelona.

We're back from Spain now. We were in Barcelona from 30-Dec-06 - 14-Jan-07. We stayed with our friends Beatriz and Ricardo, who are kind of like Daniel's surrogate grandparents.

When we landed in the Madrid Airport, we saw the damage from the ETA bombing. Folks, it was a lot worse than the US news made it out to be. The news here in the US said that it was a minor bombing with about 15 people treated for ear injuries. In reality, an entire four story parking lot was completely demolished, and two people were killed. I was taking photos of the broken glass all across the front of the airport when Sonia told me to look at the parking lot across the street. It was unbelievable. There was even a slight crater where the parking lot was before. For days afterwards the rescue workers dug to find the bodies of two innocent Equadorian immigrants who could not get out of the parking lot when it was evacuated.

ETA are a bunch of gillipollas. How does killing a couple of innocent immigrants forward their cause? The one thing I am sure of is that if there ever were an independent Euskera, I certainly wouldn't want that bunch of bloodthirsty clowns to be in charge of it. I doubt that the Basque people want that either.

Sonia and I were able to go to Rome for a weekend and leave Daniel with Ricardo and Beatriz. Rome was great. We took about 200 photos (at http://picasaweb.google.com/sontida). It was impossible to take a bad photo in Rome.

We're glad to be home, but are already planning our next trip.