Saturday, February 18, 2012

These days, I’m using the Sublime Text 2 Beta as my text editor of choice on Windows. I searched around to find the magical incantation to use that would allow Git to use it as my commit message editor and came up empty. It turns out not to be a big deal. Just create a batch file that launches sublime_text.exe with --wait and --new-window arguments. Something like the following:

"C:\Program Files\Sublime Text 2\sublime_text.exe" --wait --new-window "%1"

Then it’s just a matter of setting the batch file as the core editor used by git:

git --config core.editor C:/Scripts/sublime.bat

Update (2/25/2012): The –multiinstance command will do a much better job when launching sublime_text.exe from the command prompt, especially when you already have an instance of sublime_text.exe open. Update your batch file to look like so, and you should be good to go.

"C:\Program Files\Sublime Text 2\sublime_text.exe" --wait --multiinstance "%1"
posted on Saturday, February 18, 2012 12:25:58 PM (Pacific Standard Time, UTC-08:00)  #    Comments [9]

kick it on DotNetKicks.com
 Friday, March 07, 2008
Google has released Google Calendar Sync, which will automatically sync your Google Calendar to and from Microsoft Outlook. As an avid user of both calendars, I rushed to download and install the tool. It installed quickly, accepted my Google Apps email, and was ready to go. However, after the first sync, I was puzzled as to why the items from Google Calendar hadn't shown up in Outlook yet. I tried a few manual syncs, but still nothing happened.

I have to admit that I rarely read instructions before installing software, so I had missed the following important information on the Google Calendar Sync: Getting Started page, which reads:

"Keep in mind that it's not possible to sync events on secondary calendars at this time. Google Calendar Sync will only sync events from your primary Google Calendar and your default Microsoft Outlook calendar."

Ugh. I didn't notice my events coming into Outlook because I don't have much in my primary Google Calendar. I was expecting to see everything come into Outlook, but the tool doesn't actually support that.

Are they serious about this? So, I can't use multiple color-coded calendars in Google Calendar? That's right. Any events not on the primary calendar will simply not be synced. And of course, the problem exists on both sides. If you happen to use multiple calendars in Outlook, you're out of luck.

calendar

To make matters worse, the tool doesn't handle event collisions very well. So, if the same event exists in each calendar before the first sync, you'll wind up with two items in both calendars. Yup. If you have "St. Patrick's Day" in your Google Calendar and Outlook, you'll find two "St. Patrick's Day" events in each after syncing for the first time.

C'mon Google, you can do better than this! Supporting only the most basic use case isn't enough. I need a tool that does it all with the ease-of-use that I've come to expect from Google's tools. I don't need a tool that 1) requires babysitting, or 2) limits the number of features that I can use.

Somebody please let know when this really works. Until then, it's uninstalled.

posted on Friday, March 07, 2008 10:36:40 AM (Pacific Standard Time, UTC-08:00)  #    Comments [4]

kick it on DotNetKicks.com
 Wednesday, January 02, 2008
I guess I've been a little busy lately because I completely missed the release of Ultramon™ 3.0.1 Beta 2 back on December 15th. Ultramon is simply the best management tool for multiple monitors available. I would not survive for long in front of my monitor setup without it.

This release has some welcome changes and bug fixes for Windows Vista. The full release notes are here.

posted on Wednesday, January 02, 2008 1:52:50 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]

kick it on DotNetKicks.com
 Wednesday, December 19, 2007
Launchy, my favorite utility for launching applications, received a much-needed update yesterday. In fact, I didn't realize just how badly the update was needed until I downloaded the new version.

Launchy in action

Check out the list of changes:

  • Launchy has been completely rewritten with QT
    • Your old plugins/skins will no longer work
    • Your old configuration will be wiped
  • A new look! New icons and skin thanks to Tyler Sticka
  • Much better skinning support
  • Options merged into a single, tabbed dialog
  • Skin selection now shows previews
  • Plugins much more configurable
  • Launchy can hide when it loses focus
  • Fade in/out effects
  • Customizable transparency
  • Optional shallow scan of directories
  • Unicode support for Firefox bookmarks
  • Vista support
  • It’s just better.

After running the new version for a short while, I can verify that the last item in that list is quite true. Launchy 2.0 really is just better. If you've been on the fence with regard to application launchers or (shudder!) don't use one at all, stop reaching for the mouse and take Launchy for a spin.

posted on Wednesday, December 19, 2007 6:32:36 AM (Pacific Standard Time, UTC-08:00)  #    Comments [3]

kick it on DotNetKicks.com
 Monday, September 24, 2007
Recently, I've been using Lutz Roeder's indispensible .NET Reflector to explore how C# 3.0 LINQ query expressions are compiled. To make this easy, the .NET Reflector supports a useful "optimization" setting that specifies which version of the .NET Framework the disassembler should draw features from for code generation. Changing the setting is pretty easy. Just select "Options..." from the "View" menu to display the Options dialog. Then, modify the "Optimization" value on the "Disassembler" page.

Reflector options for optimizing disassembled code to a specific .NET Framework

With the disassembly optimization set to .NET Framework 3.5, here's how a simple query expression looks:

LINQ code disassembled with Reflector and optimized for .NET 3.5

That's pretty cool, but it doesn't really give any insight into the compiler magic happening under the hood. To get a better picture of this, the optimization setting should be changed to ".NET 2.0." Once this is done, the disassembler no longer generates query syntax, and it uses anonymous methods. This makes it plain to see which extension methods are compiled for the different clauses of a query expression. In addition, the method calls are hyperlinked, making it easy to dig deeper.

LINQ code disassembled with Reflector and optimized for .NET 2.0

While this is all very helpful, I do have a few complaints:

  1. I should be able to change the disassembler options on the fly. It'd be great if the Disassembler window sported a toolbar for modifying its options. The current user experience requires me to open the options dialog, make the change, click OK and wait while the .NET Reflector unloads and reloads all of the assemblies that are open. In fact, if I open the options dialog, make no changes and click OK, Reflector will still unload and reload everything. At the risk of inviting comment abuse from Reflector devotees1, I have to say that this strikes me as a pretty lame UI cop out.
  2. The .NET 2.0 optimization isn't accurate because it generates syntax for extension methods. I'm a bit torn by this because this inaccuracy actually makes it easier to understand the code. If this is changed/fixed, there should be an additional option that hides query syntax and shows the underlying method calls with lambda expressions instead of anonymous methods. That way, Reflector could display this LINQ expression:
var query = from m in typeof(String).GetMethods()
            orderby m.Name
            select m.Name;

Like this:

var query = typeof(String).GetMethods().OrderBy(m => m.Name).Select(m => m.Name);

Regardless of these issues, which I hope are addressed (are you reading this, Roeder?!?), the .NET Reflector is a life-changing tool. If it isn't already a part of your developer's toolbox, you should go download it right now.

1I'm one of them.

posted on Monday, September 24, 2007 9:46:09 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]

kick it on DotNetKicks.com
 Wednesday, September 19, 2007
Recently, a reader inquired as to how I format the source code samples on my blog. After writing up the set of steps that I normally run through, I decided that I should post them here so that 1) interested readers might benefit, and 2) I won't forget my own process.

First of all, I should point out that there are several tools available to help format source code for the web, and Brig Lamoreaux has a good review of several here. My personal tool of choice is CopySourceAsHtml. It does a great job of getting code out of Visual Studio with accurate syntax highlighting. With a few tweaks to the HTML, it can produce exactly what I need.

Here is the exact process that I go through to create code samples that look equally good on the web and in RSS feeds.

Step 1: Write Your Code

Step 1: Write Your Code

Some important tips:

  • The code should be concise and well formatted. Most readers skim code, so it should be clear enough to get the general idea from a brief overview.
  • Make sure the code compiles! It can be quite embarrassing to be contacted by a reader who, after copying and pasting the code, found that it didn't compile.

Step 2: Copy As HTML

Step 2: Copy As HTML

Select the code sample in Visual Studio, and decrease the indent (Shift+Tab) until the code is aligned at column 1. Next, select "Copy As HTML..." from the editor's context menu. At this point, you'll be presented with the "Copy As HTML" dialog.

The first time that the dialog is displayed, some options need to be set. Fortunately, the dialog remembers your settings so that you don't need to change them next time. On the "General" tab, uncheck everything except for "Embed styles."

Step 2a: Copy As HTML (General tab)

Next, switch to the "File Style" tab to add additional CSS styles to the <div> tag that will surround the HTML-formatted code sample. Here are the styles that I use for my blog:

border: 1px dotted rgb(221, 221, 221);
margin: 4px;
padding: 4px;
font-family: Consolas,'Courier New',Courier,monospace;
font-size: small;
color: rgb(0, 0, 0);
background-color: rgb(255, 255, 255);

Step 2b: Copy As HTML (File Style tab)

Finally, click the OK button to copy the code to the clipboard.

Step 3: Massage the HTML

Once pasted in the HTML source editor of your choice, the code sample will render like this:

Sub Main()
  Dim publicationdate = Date.Today
  Dim isbn = 42
  Dim price = 0.99D
  Dim firstName = "Dustin"
  Dim lastName = "Campbell"
 
  Dim book = <book publicationdate=<%= publicationdate %> ISBN=<%= isbn %>>
               <title>F#: For The Excessively Nerdy</title>
               <price><%= price %></price>
               <author>
                 <first-name><%= firstName %></first-name>
                 <last-name><%= lastName %></last-name>
               </author>
             </book>
End Sub

Unfortunately, CopySourceAsHtml wraps every line in the code sample with <pre style="margin: 0px;"></pre> tags. These tags override some of the CSS styles that we specified for the <div> tag. Thankfully, this is easily corrected with two replace operations:

  1. Replace all instances of <pre margin="0px"> with blank text.
  2. Replace all instances of </pre> with <br /> to preserve the line breaks.

The syntax coloring is achieved by using <span> tags. Occasionally, a space will appear between two uses of a <span> tag. For example, in the code sample above, "End Sub" is actually represented like this:

<span style="color: blue;">End</span> <span style="color: blue;">Sub</span>

Some RSS readers make the mistake of removing the space in between these <span> tags, causing the words to run together. To fix this potential problem, just replace all instances of "</span> <span" with "</span>&nbsp;<span".

When finished, the code sample should render like this:

Sub Main()
  Dim publicationdate = Date.Today
  Dim isbn = 42
  Dim price = 0.99D
  Dim firstName = "Dustin"
  Dim lastName = "Campbell"
 
  Dim book = <book publicationdate=<%= publicationdate %> ISBN=<%= isbn %>>
               <title>F#: For The Excessively Nerdy</title>
               <price><%= price %></price>
               <author>
                 <first-name><%= firstName %></first-name>
                 <last-name><%= lastName %></last-name>
               </author>
             </book>
End Sub

Really, it's not that much effort. Once the CopySourceAsHtml options are set to your liking, it is a simple matter to copy, paste and make a few modifications to get the desired result. Most of the work is in writing the code sample.

posted on Wednesday, September 19, 2007 1:39:54 PM (Pacific Standard Time, UTC-08:00)  #    Comments [3]

kick it on DotNetKicks.com
 Thursday, August 16, 2007
After writing up this post, I found similar instructions elsewhere. Oh well... you can't always be first.

CopySourceAsHtml on the context menu of Visual Studio's editorCopySourceAsHtml is an extremely useful Visual Studio add-in that places a new menu item on the context menu of the editor. This is especially helpful for bloggers looking for an easy way to get rich source code highlighting into their blogs.

In general, I usually find it necessary to massage the HTML results a bit to get code to look good in RSS feeds, but it is far easier than, say, manual highlighting.

Yesterday, while working on my Art of Currying article, I found it necessary to highlight some C# 3.0 code and was disappointed to find that the trusty "Copy As HTML..." menu item wasn't available. Fortunately, it's very easy to install the add-in into Visual Studio 2008 beta 2.

The CopySourceAsHtml installer drops four files in the "My Documents\Visual Studio 2005\Addins" directory:

  • CopySourceAsHtml.AddIn -- an XML file that describes the add-in and is used for registration with Visual Studio.
  • CopySourceAsHtml.dll -- the add-in itself.
  • CopySourceAsHtml.dll.config -- a configuration file that contains various user settings.
  • CopySourceAsHtml.pdb -- debugging symbols for the add-in. This really isn't needed but it doesn't hurt anything either.

Simply copy these files to the "My Documents\Visual Studio 2008\Addins" directory. If the "Addins" subdirectory doesn't exist, just create it. If you are using Windows Vista, substitute "Users\CURRENTUSER\Documents" for "My Documents".

Next, in a text editor, open the CopySourceAsHtml.AddIn file that you just copied and change the two <Version> tags from 8.0 to 9.0. When you're finished, it should look like this:

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<
Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
  <
HostApplication>
    <
Name>Microsoft Visual Studio Macros</Name>
    <Version>9.0</Version>
  </
HostApplication>
  <
HostApplication>
    <
Name>Microsoft Visual Studio</Name>
    <
Version>9.0</Version>
  </
HostApplication>
  <
Addin>
    <
FriendlyName>CopySourceAsHtml</FriendlyName>
    <
Description>Adds support to Microsoft Visual Studio 2005 for copying source code, syntax highlighting, and line numbers as HTML.</Description>
    <
Assembly>CopySourceAsHtml.dll</Assembly>
    <
FullClassName>JTLeigh.Tools.CopySourceAsHtml.Connect</FullClassName>
    <
LoadBehavior>1</LoadBehavior>
    <
CommandPreload>0</CommandPreload>
    <
CommandLineSafe>0</CommandLineSafe>
  </
Addin>
</
Extensibility>

Save the file and... your're done! Start up Visual Studio 2008 beta 2, and that handy context menu item is now available and works great.

posted on Thursday, August 16, 2007 8:03:44 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]

kick it on DotNetKicks.com
 Wednesday, March 28, 2007
While giving a talk at the Dayton-Cincinnati Code Camp, my computer started dragging to a crawl—PowerPoint was hung, Visual Studio 2005 wouldn't respond—very bad. I'm comfortable with multi-tasking so I fired up Process Explorer while I continued to introduce the session topic. When Process Explorer was up, the culprit was revealed. Both cores of my CPU were pegged by the Adobe Updater software. Discovering this, I couldn't help pointing out the problem to the audience (with some choice comments) and logged a todo item in the back of my mind to get rid of the Adobe PDF Reader ASAP.

Today, I am Adobe Free. I removed the PDF Reader and the diabolical Adobe Updater. Today I'm running Foxit and I couldn't be happier. It's much faster than Adobe's reader. My machine actually responds as if chains have been removed from it. Thanks Foxit!

posted on Wednesday, March 28, 2007 7:13:41 AM (Pacific Standard Time, UTC-08:00)  #    Comments [5]

kick it on DotNetKicks.com