Distant Shores - A Visual Studio Color Scheme

Link. March 23, 2008. Comments [0]. Posted in: VS Color Scheme

I created this color scheme a while ago but had not posted it yet. Distant Shores is a low-contrast color scheme with a dark background.

I've been using it for a while now and it's fairly usable (particularly on a bright screen); though it is a bit different than most of my other themes. It's (loosely) based on the Stormy Seashore color palette, with a few additions for contrast and provide basic coloring to user types in C#.

Code:

Distant Shores - Code

XML:

Distant Shores - Xml

As usual in most of my schemes, this one is using Damien Guard's Envy Code R VS font.

Visual Studio 2005 version.

Visual Studio 2008 version.

Editing PowerShell Scripts with Vim

Link. March 18, 2008. Comments [0]. Posted in: PowerShell | Vim

I've been using Vim to edit my PowerShell scripts for a while. I get full syntax highlighting and indentation thanks to Peter Provost's excellent scripts:

These work great most of the time, but a couple of things had been nagging me for a while:

  1. I occasionally enable syntax-based folding (:set foldmethod=syntax), but the PS1 syntax file doesn't enable this for blocks "{...}" in PowerShell scripts.
  2. The indent file always forces comments (#...) to start at the first column.

Fortunately, both of these issues are pretty easy to fix. To enable syntax-based folding, I just modified the syntax file to add this:

" support folding for blocks
syntax region  psBlock      start="{" end="}" transparent fold

To disable the comment indentation, I edited the Indent file and remove the # character as an indent key:

setlocal cindent cinoptions& cinoptions+=+0 cinkeys-=0#

Seems to be working fine for me, and it will now stop driving me crazy :-).

PowerShell Fortune

Link. March 17, 2008. Comments [0]. Posted in: PowerShell

The first version of Linux I ever used was Slackware 2.3 running one of those pesky 1.X kernels. Since then, one of my all-time favorite utilities has been the Fortune program, which displays quotes on the console when run.

fortune

I've always missed it on windows and even build (and lost) a clone of it myself once, but I'm too lazy now to try that again. Instead, this time around I simply settled for writing a simple PowerShell script that grabs a random quote from QuoteDB. It's not fancy. It has no error checking at all. It's slow (depending on your network connection and how loaded quotedb is), but alas, it works and it's fun to use.

I give you fortune.ps1:

$wc = new-object net.webclient
$js = $wc.DownloadString('http://www.quotedb.com/quote/quote.php?action=random_quote&=&=&')

function strip-html([string] $str) {
   $val = $str -replace '<[^>]+>', ''
   $val = $val -replace '`', "'"
   return $val
}

function next-word([string] $text, [int] $start) {
   $end = $start
   for ( ; $end -lt $text.Length; $end += 1 ) {
      if ( $text[$end] -eq ' ' ) {
         break
      }
   }
   return $text.Substring($start, $end - $start)
}

function wrap-text([string] $text) {
   $buf = new-object Text.StringBuilder
   $lnl = $host.UI.RawUI.WindowSize.Width - 2
   $pos = 0
   $linepos = 0
   while ( $pos -lt $text.Length ) {
      $word = (next-word $text $pos)
      if ( $linepos + $word.Length -gt $lnl ) {
         [void] $buf.Append("`n")
         $linepos = 0
      }
      [void] $buf.Append($word + ' ')
      $pos += $word.Length + 1
      $linepos += $word.Length + 1
   }
   write $buf.ToString()
}


if ( $js -ne $null ) {
   $js = $js.trim()
   $p1 = "^.+'(?<text>.+)<br>'\);"
   $p2 = '">(?<author>.+)</a>'

   $authorline = $js.Substring($js.LastIndexOf("`n"))
   $maintext = $js.Substring(0, $js.LastIndexOf("`n"))
   if ( $maintext -match $p1 ) {
      $matches.text.Split("`n") | %{
         wrap-text (strip-html $_)
      }
   }
   if ( $authorline -match $p2 ) {
      write "`t`t-- $($matches.author)"
   }
}

Dev Environment for PowerShell

Link. March 13, 2008. Comments [0]. Posted in: .NET | PowerShell

A few people have asked already about my PowerShell script for configuring a development environment for .NET / Visual Studio / SDK work, so I thought I might as well break it into it's own script.

Here it is:

###############################################################################
# Configures the .NET / Visual Studio / Windows SDK
# Build environment. Loosely based on the SDK batch files.
#
# First it will try to set up the environment for .NET 3.5
# and VS2008. Failing that, falls back to .NET 3.0/VS2005.
###############################################################################

$NETFXDIR = "$env:WINDIR\Microsoft.NET\Framework"
$FX20 = "$NETFXDIR\v2.0.50727"
$FX35 = "$NETFXDIR\v3.5"

function script:append-path {
   $env:PATH += ';' + $args
}
function script:append-lib {
   if ( test-path('Env:\LIB') ) {
      $env:LIB += ';' + $args
   } else {
      $env:LIB = $args
   }
}
function script:append-include {
   if ( test-path('Env:\INCLUDE') ) {
      $env:INCLUDE += ';' + $args
   } else {
      $env:INCLUDE = $args
   }
}
function script:get-vsdir([string] $version) {
   $regpath = "HKLM:SOFTWARE\Microsoft\VisualStudio\$version"
   if ( test-path($regpath) ) {
      $regKey = get-itemproperty $regpath
      return $regkey.InstallDir
   }
   return $null
}
function script:set-vsenv([string] $version) {
   $VSDIR = (get-vsdir $version)
   if ( $VSDIR -ne $null ) {
      append-path $VSDIR
      append-path "$VSDIR..\..\VC\bin"
      append-path "$VSDIR..\Tools"
      
      append-include "$VSDIR..\..\VC\include"
      append-lib "$VSDIR..\..\VC\lib"
      return $true
   }
   return $false
}
function script:get-psdkdir {
   $regpath = "HKLM:SOFTWARE\Microsoft\Microsoft SDKs\Windows\"
   if ( test-path($regpath) ) {
      $regKey = get-itemproperty $regpath
      return $regkey.CurrentInstallFolder
   }
   return $null
}
function script:set-psdkenv {
   $sdkdir = (get-psdkdir)
   if ( ($sdkdir -ne $null) -and (test-path $sdkdir) ) {
      append-path "$sdkdir\bin"
      if ( test-path "$sdkdir\include" ) {
         append-include "$sdkdir\include" 
      }
      if ( test-path "$sdkdir\lib" ) {
         append-lib "$sdkdir\lib"
      }
   }
}

set-psdkenv
# if .NET 3.5 is installed, default to that, otherwise use 2.0
if ( test-path($FX35) ) {
   append-path $FX35
}
append-path $FX20
if ( -not (set-vsenv "9.0") ) {
   [void] (set-vsenv "8.0")
}

Feel free to customize as you see fit :-).

PowerShell and the Windows SDK

Link. March 13, 2008. Comments [0]. Posted in: .NET | PowerShell

Nanda Lella's from the Windows SDK team is asking for feedback for the next version of the Platform SDK. Specifically, she asks whether a PowerShell-based build environment (as opposed to the current CMD-based one) would be a welcome addition to the SDK.

Personally, I think this is a great idea and hope it becomes a reality [1]. I'm sure that having it out of the box would make PowerShell a lot more popular amongst developers. Repeat after me: PowerShell is not just for sysadmins!.

Not having a build environment readily available in PowerShell kept me a long time from making it my default shell.

Because of this, I eventually sat down and wrote a custom profile script, like many others, to setup the build environment manually, loosely based on the original batch files in the Windows SDK and Visual Studio distributions. It's probably not perfect, but it does the trick and now I use PowerShell all the time.

Actually, I did make one significant modification to my script compared to the originals in the SDK: I keep machines with both .NET 3.5/VS2008 as well as .NET 3.0/VS2005, and wanted to keep a single profile script to avoid having to constantly modify my own environment.

My current profile script first looks and configures the environment for VS2008; failing that, it falls back to the .NET 2.0/3.0 and Visual Studio 2005 configuration. If anyone happens to be interested in it; ping me and I'll be happy to share it.

[1] Actually, there's no reason why this needs to be tied to a specific SDK version, but I imagine that's how it may/will happen. Frankly, it would be good enough for many people to have a pre-written version downloadable from somewhere easily searchable and accessible.

Nick Heppleston on PipelineTesting

Link. March 11, 2008. Comments [1]. Posted in: BizTalk

Nick Heppleston wrote a very nice piece on using my PipelineTesting library to test BizTalk Pipeline Components in isolation. Thanks for the kind words, Nick; they are much appreciated!

I wrote PipelineTesting for my own needs; I spend a substantial amount of my BizTalk development time working with schemas, pipelines and custom pipeline components, and frankly, it's a drag having to continually deploy or trying to use the very simplistic tools that BizTalk provides out of the box for this.

The time I've saved using PipelineTesting to test my own components has made up for the time I've spent developing the tool many times over already, but it's fantastic seeing other people liking it and using it for their own projects.

If anyone else has been using the library, I'd love to know about it! And of course, I'm always open to suggestions, bug reports or wishes and I'll do my best to incorporate them to the next releases.

NTFS Data Streams and .NET

Link. March 8, 2008. Comments [0]. Posted in: .NET

Several people have written in the past about accessing Alternate Data Streams in the NTFS file system from .NET code. The reason for this is that accessing streams is not natively supported in .NET. What you don't hear very often is exactly why this is so.

There are two things you might want to do with data streams:

  1. Manipulate them: create/read/write/delete them
  2. Enumerate them: list all the alternate data streams for a file

Neither of these operations are not supported by System.IO. To be perfectly honest, I think not supporting (2) is an understandable option; after all, it requires exposing some fairly specific windows APIs that are really only useful with NTFS itself (as far as I know). There's an old MSDN Magazine article on this topic by Stephen Toub, by the way.

But I was always pretty surprised that (1) wasn't natively supported. After all, you don't really need special APIs to do most of that stuff; it's built into the native Win32 APIs that .NET has to call anyway to perform the basic file and I/O operations. Heck, it is so basic that you can create a new alternate stream using "echo" in a cmd prompt!

You can find some mentions out there about this being because complexities introduced by file name aliases and what not, but I'm not sure I buy it. Seriously, number (1) should just work; if it doesn't then something smells wrong. After all, it takes work to get something that you get for free to not work at all!

I think the overall reason this doesn't happen is just that the way paths are handled (and path canonicalization is done) in regards to FileIOPermissions and such, but frankly, I'm not sure why it is such a big deal. There are certainly a bunch of other file system features in NT, which .NET doesn't supports either, but those are a bit more understandable (to me, at least).

Other than that, there's also the fact that System.IO.Path isn't particularly bright about how it handles paths. For example, it is hard to argue that this could be proper behavior:

path

Fortunately, using alternate data streams isn't so common, so this isn't such a big deal. Still, it is a curious bit.

TortoiseSVN and Putty

Link. March 7, 2008. Comments [0]. Posted in: Tools

Last week, I was trying to connect to an SVN repository over SSH, using TortoiseSVN and Putty. I found a the faq on how to configure everything and checked it to make sure I was doing everything right.

I tried to connect. TortoiseSVN asked for my certificate password. And then, nothing. I could see that indeed TortoiseSVN was connecting to the SSH server; but just sat there doing nothing. I had to kill it several times to abort the connection.

I had already tried connecting using Putty directly, and that seemed to work, so I kept checking my settings, but for the life of me I couldn't figure out what the deal was.

Eventually, I figured out what the deal was:

puttyssh

See that "Don't start a shell or command at all" checkbox? Yep; that should NOT have been checked, as it prevented the server from starting svnserve to handle the SVN connection. Don't know why I had checked it before, but everything worked as soon as I removed it from my Putty profile.

What I don't like about E: Cygwin

Link. March 7, 2008. Comments [0]. Posted in: Tools

My good friend Sam Gentile blogged about his new dev environment for Ruby using the E Text Editor alongside cygwin and Console. I find E an interesting editor because of its TextMate-like functionality, and because pretty much everyone who has used TextMate raves about it (though I haven't used it myself).

As a side note, last time I tried E wasn't very successful. In their defense, I'll say that I've since reached the conclusion that it was probably my virtual machines acting up. VPC2007 sometimes has nasty issues when running on Vista.

However, the thing I don't really like much about E is its dependency on cygwin. I understand the reason for it, but frankly, I just don't like cygwin much. Don't get me wrong, cygwin fills a valuable niche [1], and I've used it in the past, but the truth is that it's much more less needed now than it used to be.

For example, a few years ago it was pretty hard to find native ports of many GNU command line utilities. Now they are widely available (and before that there was unxutils). There are differences of course, but they are very usable for the most part.

Cygwin itself feels pretty clunky. In fact, I don't want a "unix within windows" at all, as that forces to many compromises (many of which aren't really all that needed). If I wanted to, I could always go with something like andLinux, which seems like a better option to me.

Frankly, between PowerShell, the Windows port of GNU utilities and a few other things, I feel right at home on Windows and switch to unix when using my ubuntu machine without much fuzz at all.

Back to Sam's post: he's right on the money about Console; it's pretty sweet. Unlike Sam, however, I dumped my VS environment tab and just configured all the necessary paths in my PowerShell profile. I haven't had a need to switch to a regular CMD.EXE prompt in a few weeks!

[1] There are certainly some cases where cygwin is actually warranted because some specific tools, but, personally, I prefer to just switch to a real unix at that point. It's less painful.

Irony

Link. March 5, 2008. Comments [1]. Posted in: .NET

I've been playing a bit with Irony, an open source .NET compiler construction toolkit created by Roman Ivantsov. My interest in Irony was sparked after watching the video of Roman's presentation at Lang.NET 2008 (I'd link to it, but they are unavailable at the moment).

Currently, I have a little side project where I've been experimenting with the Dynamic Language Runtime, for which I was using GPPG and GPLEX to build the parser and tokenizer. The tools are OK, but it certainly requires quite a bit of manual work, you need to keep regenerating the code, and, frankly, the error messages both tools produce leave a bit to be desired.

I'm aware of ANTLR, but frankly don't want to mess around with the whole java generator thing at this time (already have way too much crap around).

Irony is pretty interesting because all the tokenizer and grammar rules are expressed directly in C# code as a simple object model built from Terminal and NontTerminal objects. The syntax is fairly intuitive because Irony overloads several operators like | and & to make the grammar definition look a lot similar to BNF. Here's a sample of what a simple expression grammar in Irony looks like: http://www.codeplex.com/irony/Wiki/View.aspx?title=Expression%20grammar%20sample

After testing a bit Irony, I'm very encouraged to give it a try on my pet project, so I've been playing around with my grammar (unfortunately broken at this time because of some ambiguities I haven't resolved yet), and its looking very nice overall.

There's also a useful "Grammar Explorer" tool included with the Irony code which can be used to experiment and diagnose a compiled Irony grammar. Unfortunately right now it just has a predefined list of a few test grammars included with the project, but extending it to use others is trivial anyway, so I've been using it to test my grammar before actually committing to it.

Another useful thing in Irony is the concept of TokenFilters, which are objects that can filter the token stream as it is produced by the scanner and can either remove/modify/add new tokens as necessary or provide extra validations. Right now Irony provides two built-in filters, but you can extend it with new ones as necessary:

  • CodeOutlineFilter, which can be used in languages where whitespace is significant (indentation and/or newlines).
  • BraceMatchingFilter for matching brace characters, for example '()' in scheme/lisp.

About

Tomas Restrepo is co-founder of devdeo. His interests include .NET, Connected Systems, PowerShell and, lately, dynamic programming languages. More...

email: tomas@winterdom.com
msn: tomasr@passport.com
twitter: tomasrestrepo

Technorati Profile

devdeo logo

View my profile on LinkedIn

MVP logo

Syndicate

Ads


Links

Categories

Statistics

Total Posts: 1014
This Year: 84
This Month: 3
This Week: 2
Comments: 776

Blogroll

Post Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.1.8102.813

Sign In