• Running Fedora Core 6 On Microsoft’s Virtual PC 2007

    Running Fedora Core 6 On Microsoft’s Virtual PC 2007

  • Visual Studio Keyboard Tip #7 – Incremental Search

    Visual Studio Keyboard Tip #7 – Incremental Search

Text Editors — Back To Vim!
Text Editors — Back To Vim!

Being the keyboard kind of guy that I am, I’ve totally gotten back into the Vim editor. I had used it years ago, and discovered it again recently when I was looking for a text editor for some Ruby code I was writing.

WinDBG Tips
WinDBG Tips

I had previously blogged about finding some good tutorials on how to get started. I’ve been using the WinDBG debugger a little bit more lately and I’ve put together a “cheat sheet” that I use for the most common commands and I thought I would share them.

C# WeakReference Example
C# WeakReference Example

A WeakReference is an object with a very interesting behavior, it allows you to keep a reference to an object while still making it possible for it to be garbage collected. See a previous post for a little more detail and links.

Ruby On Rails – Part Four – Rake

I have always been interested in automating common development tasks. I have used Ant, Maven, and Nant pretty extensively and now I’m learning the details of Rake. There’s something special about seeing messages fly by in a command shell, and know that the computer is doing all these repetitive tasks — not you!

What is different about Rake then any of the others build tools mentioned is that you create a Rakefile by writing Ruby code, instead of using xml. There is a

I would recommend you read this excellent article on defmacro.org (take your time and read through it — it’s really worth it) that does a good job of explaining the benefits of Lisp. A cool thing, since we’re talking about build automation, is one section, titled “Ant Reloaded”, talks about how Java could have been used instead of XML. In our case it’s Ruby being used in a Rakefile.

This tutorial is written by the developer of Rake, and is a good tour through the main features of Rake. I would suggest you read it first, followed by this article by Martin Fowler which reviews some examples of interesting things you can do with a Rakefile.

I created a simple example Rakefile. I’m sure no one would actually need a script like this, but the simple scenario was good for an example of how to use Rake.

I’ve included the code below, the formatting is off because I pasted it in my blog editor, but I hope it will be a good example to someone just getting started with Rake. If you have any suggestions on how to improve this simple Rakefile example, please add a comment to this post.

# ———————————————————-

# This is just an example to illustrate how to use Rake

# By Rob Herbst

# ———————————————————-

# Require rake/clean to get the built in clean task

require ‘rake/clean’

# Require ftools to get File.copy

require ‘ftools’

# Define constants we’ll use later

HTML_SRC_DIR = “html”

WEB_DEST_DIR = “website”

IMAGES_DIR = “images”

SITE_MAP = “sitemap.html”

HTML_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.html”]

IMAGE_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.jpg”]

# Add the WEB_DEST_DIR to the list to get cleaned

CLEAN.include(WEB_DEST_DIR)

# The default task depends upon the package task

task :default => [:package]

# The package task depends upon clean, create structure, and the task to create the site map file.

task :package => [:clean, :create_structure, :sitemap] do

     puts “The package task was called.”

             # Copy over the html files

     HTML_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}”)

     end

             # Copy over the image files

             IMAGE_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}/images”)

     end

end

# Utility task to create the structure of the website

task :create_structure do

     puts “The create_structure task was called.”

     Dir.mkdir(WEB_DEST_DIR)

     Dir.chdir(WEB_DEST_DIR)

     Dir.mkdir(IMAGES_DIR)

     Dir.chdir(“..”)

end

# Task to create the sitemap.html file

task: :sitemap do

     open(“#{WEB_DEST_DIR}/#{SITE_MAP}”, “w”) do |outs|

          outs.puts “<html><head>Site Map</head><body><ul>”

          HTML_SRC_FILES.each do |f|

               file_name = f.sub(HTML_SRC_DIR + “/”, “”)

               outs.puts “<li><a href=\”#{file_name}\”>#{file_name}</></li>”

          end

          outs.puts “</ul></body>”

     end

end

Google Rss Reader is very cool

I have recently switched my RSS aggregator to Google Reader. This app is still officially in the Google Labs environment, so once in a while there will be a slight hiccup. But, overall I have found this to be a great rss reader.

It has full keyboard support!

  • J to move down article list
  • K to move up article list
  • SPACE to page through a long post, then when the end is reached it moves to the next unread item in your list

It also has support for tags or categories, or labels as Google calls them, which comes in handy if you want to categorize your feeds. You can also share your “starred” items, this feature I have not checked out yet, but it seems interesting.

If you go to the familiar Google search box at the top, it allows you to search for new blogs on a topic. For example, go to the search box at the top, enter “Rob Herbst”, then hit the button labeled “Search for new content”. Now click on the subscribe button….only kidding.

Google Reader also supports mobile devices, which is great if you have to catch up on your feeds on the go.

This post on the Google Reader Blog reviews a sample of what the top errors in the xml feeds that the development team sees. Pretty interesting to see the number two is mismatched tags!

Overall, I think this is a great rss reader that is definitely worth checking out.

Update 8/11:

My friends Pete and Nick don’t like Google Reader. I guess it all comes down to your personal workflow. I used to read my blogs in a similar fashion but that just didn’t work for me. I realized that I had subscribed to way too many blogs, and there was no way I was ever going to have time to read them all. I’m glad that method works for Pete & Nick.

Actually, looking at all those unread items in my Newsgator/Outlook newsreader made me feel like I wasn’t able to keep up — very unmotivating for me. So what I did was to radically trim down the number of feeds that I read. It was difficult to do, but I tried to look at each one and really determine if I was really getting any value from it.

I was able to cut my subscribed list down to just a handful, so the approach that Google Reader takes works perfectly fine for me. I only get about 15-20 new posts per day, so cruising through them in the one place is okay with me. I guess, it also resonates with my Getting Things Done experience. With this approach I have an inbox, where I process the items one at a time. I understand that if you have a much larger & varied subscription list this approach doesn’t seem to work well.

As for keeping entries for future reference, you can either “star” them, or inside the view when you are reading the item, you can check the “keep unread” and it will be displayed until you manually clear it.

I do have to say I was on the train today and I was very happy being able to read my blog entries on my smartphone (which is true of any server based aggregator). That was very cool!

Anyway, Pete & Nick, I’m sorry you guys don’t like Google Reader, but like I mentioned at the top I think it all comes down to personal workflow in how you read your feeds. Both of you seem to have a similar approach were a tool like BlogLines or Newsgator is a better fit.

Text Editors — Back To Vim!

Being the keyboard kind of guy that I am, I’ve totally gotten back into the Vim editor. I had used it years ago, and discovered it again recently when I was looking for a text editor for some Ruby code I was writing.

It’s one of those power tools that most people, myself included, really didn’t like very much the first time you use it. But then you achieve a certain level of proficiency and you can slice and dice any text you have to edit so quickly that you become very spoiled.

I also have switched to using a black background. I found a great dark color scheme for Vim called Moria, that I would highly recommend. It’s a very readable, easy on the eyes scheme, that just seems right to me. I’ve posted an image of my setup using the abbrev.rb file from Ruby 1.8.5.

If you like using keyboard shortcuts, you owe it to yourself to try the Vim text editor. It does take some time to get used to a modal editor, but if you are going to be editing lots of text, it’s time well spent.

I still really like the text editor built into Visual Studio and will continue to post any tips and keyboard shortcuts that I find useful there too.

WinDBG Tips

I had previously blogged about finding some good tutorials on how to get started. I’ve been using the WinDBG debugger a little bit more lately and I’ve put together a “cheat sheet” that I use for the most common commands and I thought I would share them. Almost all of these commands are specific to the SOS extension to debug .NET code.

If you are a seasoned WinDBG user, you’ll know all of these command by heart, but if you are just getting started this might help. The first thing to do is run, don’t walk to setup your “Symbol Search Path” setting. Enter CTRL+S from inside WinDBG, mine looks like this:

You can find out more about it in this Microsoft support article.

The WinDBG command line has TAB completion, so when you type the first few characters of a command, hit TAB to cycle through the possible completions.

I have picked up the majority of these tips by reading some of the great blogs on MSDN. If you are interested in learning a lot more about WinDBG and how to debug some very difficult problems you need to subscribe to Tess’s blog right away!

If you know of any other tips or helpful WinDBG command, please post them in the comments and I’ll add them to the list.

Command Description
.loadby sos mscorwks Loads the correct version of the SOS(.NET) extension dll based on the version of mscorwks currently loaded
.chain View the currently loaded extensions
.hh command Opens the help file for the specified command. For example: .hh ~
!help Displays help for extensions, including for SOS a list of commands
!help command Displays help for the specified extension command. For example: !help clrstack
.cls Clears the sceen
~ List all threads
!threads List managed threads
~# s Set current thread, where # is a thread number, for example: ~3 s
!clrstack Display the CLR stack
!clrstack Display the CLR stack with parameters
kb Display the stack frame for the native thread
!dso Dump objects on the stack
!do Dump managed object
dc Display the contents of memory as DWORDS and ASCII chars
!dumpheap Dumps the contents of the managed heap
!dumpheap -stat Display stat summary of managed heap
!dumpmt address Dumps the MethodTable of the specified address
!dumpmt -md address Dumps the MethodTable of the specified address and displays a list of all the methods on the object
!dumpclass address Displays the EEClass for the specified address
!dumpobj address Display the details of the object at the specified address
!eestack Runs !DumpStack on all threads
!dumpruntimetypes Displays all System.RuntimeType object from the managed heap
!runaway Displays thread time statistics
.time Displays System Uptime, Process Uptime, Kernel Time and User Time
!syncblk Displays synchronization lock info
!dumpheap -thinlock Displays objects locked with thinlocks instead of syncblk’s
!dumpheap -type System.String -stat Displays count and total size of the specified type (in this case System.String) on the heap
!address Display virtual memory stats, load addresses and reserve/commit info
!address -summary Display just the summary virtual memory info
!eeheap -gc Display garbage collector generation info
!pe Print exception details
~*kb Display callstacks for all threads
!finalizequeue Display stats and contents of the finalizer queue

Running Fedora Core 6 On Microsoft’s Virtual PC 2007

I was able to get Fedora Core 6 running very well on Microsoft’s Virtual PC 2007 with just two small tweeks. The main problem is the emulated S3 video card doesn’t support 24 bpp mode, whereas the actual hardware card does! I wish I could find the blog or newsgroup post that I found that originally pointed this out so I could give credit to whoever figured this out — thanks! If you know please contact me and I’ll update the blog post.

Here’s all that i had to do:

  1. Run the install in text mode. You do this by entering “linux text” without the quotes at the initial prompt.
  2. When Fedora boots:
  • Login
  • vi /etc/X11/xorg.conf
  • In normal mode: type /DefaultDepth — which if you are not familiar with vi, just means search for the string “DefaultDepth”
  • Change 24 to 16
  • :wq to save and exit vi
  • Enter “startx” without the quotes at the terminal to start X.
    That’s all you should need to do!

Rails Plugin For VIM

I found a plugin for VIM that was designed just for Rails coding by Tim Pope. I thought the first line of the documentation was great

“TextMate may be the latest craze for developing Ruby on Rails applications,
but Vim is forever.”

It provides:

  • quick navigation commands from model to view and controller
  • rake integration
  • extends ‘gf’ command to understand Rails
  • CTRL+X, CTRL+U autocompletion
  • interface to the script commands
  • convenient log file viewing

Fun With GC.SuppressFinalize

I was able to get Fedora Core 6 running very well on Microsoft’s Virtual PC 2007 with just two small tweeks. The main problem is the emulated S3 video card doesn’t support 24 bpp mode, whereas the actual hardware card does! I wish I could find the blog or newsgroup post that I found that originally pointed this out so I could give credit to whoever figured this out — thanks! If you know please contact me and I’ll update the blog post.

Here’s all that i had to do:

Run the install in text mode. You do this by entering “linux text” without the quotes at the initial prompt.
When Fedora boots:
Login
vi /etc/X11/xorg.confWhile discussing some code with a colleague, I ran across an unexpected behavior of GC.SuppressFinalize. I’ve put together a small sample for our discussion.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
public class Base
{
~Base()
{
Console.WriteLine(“Base Finalizer called”);
}
}

public class Derived : Base
{
~Derived()
{
Console.WriteLine(“Derived Finalizer called”);
}

public void Suppress()
{
GC.SuppressFinalize(this);
}

}

class Program
{
static void Main(string[] args)
{
Derived d = new Derived();
d.Suppress();

Console.ReadLine();
}
}
}
Okay, so what gets printed out at the console?

Actually, nothing.

It was a little surprising to me at first, especially since after years of C++ programming the ~ immediately invokes destructor semantics in my head. I worked through a number of different variations, but I always got the same result. I used the !FinalizeQueue command available in the SOS extension of WinDBG to verify that there was only the Derived class reference on the queue. So when you say, SuppressFinalize(this) you really mean it!

Now, granted, this is a cheesy example. But the discussion came up when talking about the correct way to implement IDisposable. In the example provided, SuppressFinalize(this) is called in the Dispose method. Now that’s a good thing, because you want to prevent the call to the finalizer since you have already cleaned up any resources via your Dispose implementation. But, what happens if a class you derived from, either your own or a third party, does not implement IDisposable and instead is relying on the finalizer? Or they do implement IDisposable but somewhere else along the virtual method override chain someone forgot to call the base class implementation.

This really never should be a problem if your code implements the IDisposable interface correctly. And since implementing a Finalizer on your class has a negative performance impact you should only use them when you really need to. Anyway, this makes a great conversation at any nerd party

Visual Studio Keyboard Tip #7 – Incremental Search

The Visual Studio editor has a very useful incremental search feature built in. Let’s try it out.

  • Create a new Windows Application project.
  • Open up the Form1.Designer.cs file in the editor.
  • CTRL + I (this activates Incremental search mode)
  • Type: “disp” (without the quotes)
  • The selection should have moved to the first match of “disp” in the file.
  • Type CTRL + I again. This moves you to the next match.
  • CTRL + SHIFT + I moves you to the previous match.
  • BACKSPACE removes the last character from the search string.
  • ESC cancels incremental search mode.

ScottGu’s ASP.NET 2.0 Tips/Tricks TechEd Talk Posted

If you develop with ASP.NET you need to subscribe to Scott Guthrie’s blog.

His blog is full of detailed and well written articles that provide invaluable insight to any ASP.NET programmer.

He just posted the PowerPoint presentation and the sample code from his TechEd talk. I would highly recommend you download and review the sample project. I know every time I download samples that Scott has posted I learn something new.

Some of the features shown:

  • app_offline.htm
  • cross page postbacks
  • maintaining scrollback position
  • default button
  • custom databinding expressions

My Addition to the “Top 10 Ways to Motivate Geeks” List

Here’s my addition to the lists started on the Retrospector blog and commented on by Michael Affronti and Steve Clayton:

Geeks like to be challenged with really interesting problems.

Most geeks, myself included, want to be challenged with really interesting problems to solve. The kind of problems that are only limited by your own creativity and determination to come up with the most simple, elegant and effective solution.

Do you have any more you would add to the list?