Formatting XML in ViM

September 11, 2012 Leave a comment

I love ViM. I use it for a lot of coding – especially non-project-based coding like creating or modifying PowerShell scripts. It’s also great for diagnosing log files or just a general purpose vanilla text editor/viewer with powerful regular expression search capabilities.

A common pattern of use is to open large minified XML files – like a Burn bundle manifest (which for Visual Studio 2012 is huge). Parsing all that information as a single line is a daunting task – one made more simple by formatting (indenting) the XML. I had a way that involved opening the file in another editor, formatting it, then saving it. But then I stumbled across another tip that inspired the following 2 commands that do all this in ViM:

:%s/></>\r</g
 =gg

This uses the default indentation ( :help c-indenting ) shipped with the main ViM distribution and works great for XML. It even provide progress by counting down the lines left to process.

Categories: Computers and Internet Tags: , ,

A faster way to output unique objects in PowerShell

August 15, 2012 Leave a comment

Many times – mainly when writing function cmdlets for other purposes – I find that I need to output all unique objects based on one or two properties but want all the objects’ properties returned. PowerShell’s built-in Select-Object doesn’t let me do that. Apart from enumerating and collecting all objects before outputing them to the pipeline, it only return the properties that you specified.

To let all the objects flow through the pipeline as they are enumerating, I added my own Select-Unique cmdlet to my $profile a couple of years ago but wanted to share it now as a Gist.


function Select-Unique
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, Position=0)]
[string[]] $Property,
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
$InputObject,
[Parameter()]
[switch] $AsHashtable,
[Parameter()]
[switch] $NoElement
)
begin
{
$Keys = @{}
}
process
{
$InputObject | foreach-object {
$o = $_
$k = $Property | foreach-object -begin {
$s = ''
} -process {
# Delimit multiple properties like group-object does.
if ( $s.Length -gt 0 )
{
$s += ', '
}
$s += $o.$_ -as [string]
} -end {
$s
}
if ( -not $Keys.ContainsKey($k) )
{
$Keys.Add($k, $null)
if ( -not $AsHashtable )
{
$o
}
elseif ( -not $NoElement )
{
$Keys[$k] = $o
}
}
}
}
end
{
if ( $AsHashtable )
{
$Keys
}
}
}

view raw

gistfile1.ps1

hosted with ❤ by GitHub

See the comments on the gist for more information.

How to split PST files in Outlook 2010

October 15, 2011 1 comment

For various reasons I’ve started splitting my archive folders into separate files separate by date. There is a fairly simple object model for Microsoft Outlook and utilizing built-in search in 2010 this would be even easier to write my own program, but being a pragmatic programmer I figured I’d see if anyone else has done this. There is many applications out there, but some were for-pay and none came from sites with which I was familiar.

Then I found buried in Outlook a way to archive even the archive folders with the ability to do so by date.

  1. Open Microsoft Outlook 2010 if not already open.
  2. Optional: Clean up archive folders to reduce size and decrease the time to process (see below).
  3. Click on File.
  4. Click on Cleanup Tools, then Archive….
  5. Scroll down and select “Archive Folders”.
  6. Set the date for which older items are moved into a new folder.
  7. Set the location for the new archive PST file.
  8. Click OK.

When complete, the archive PST is attached to your Outlook profile and will be indexed.

The optional step is clean up each folder before splitting your PST. I do this every month or so on my current folders as well before they are archived to reduce the active archive PST as well (too bad the Auto Archive settings don’t allow for this). While this is supposed to work on sub-folders, it has not seemed to work for me. So to clean up each folder,

  1. Select the folder to open it.
  2. Right click on that same folder and select Clean Up Folder.

Hopefully this tip helps you split PST files by date easily and freely.

Categories: Computers and Internet Tags: , ,

Create a custom name for an existing Bit.ly link

March 28, 2011 1 comment

Bit.ly is a URL shortening service that also allows you to track referrers. Like many other such services, it shortens long URLs with a generated code like http://bit.ly/f4FrgD. When this link is first generated, Bit.ly allows you to change “f4FrgD” to something else.

But if you’ve already created a link and navigated away from the page, Bit.ly will not let you add a custom name. In fact, http://bit.ly/gQBJgW says you can’t edit a link once it’s created. While this makes sense for the generated permalink ID like “f4FrgD”, adding a custom name can work: add the same long URL in Bit.ly again gives you an error that the URL has already been shortened, but also gives you a chance to customize it – to get it a long name.

The custom name will persist, and you can then use links like http://bit.ly/vscollect even while http://bit.ly/f4FrgD continues to work.

Categories: Computers and Internet Tags: ,

Customizing icons and behaviors for UPnP devices on Windows

February 19, 2011 Leave a comment

I’ve been doing research into home automation through UPnP lately (the underlying technology for DLNA devices). One nice thing about UPnP devices is that they are easy to communicate with (when you have an implementation that allows for it) and appear in Windows Network Explorer. If you have an Internet gateway (router) or an Xbox 360, for example, you’ll see these devices appear in network explorer. This is UPnP behind the scenes.

A cool little customization I discovered was how to customize icons, verbs, and other shell extensions for different device types. A device URN describes the device type, and would look something like “urn:schemas-upnp-org:device:DimmableLight:1” (dimmable light). Using the device URN, you can add a registry key in Windows to customize for that device type.

  • HKEY_CLASSES_ROOT
    • NetworkExplorerPlugins
      • urn:schemas-upnp-org:device:DimmableLight:1
        • DefaultIcon
          • @ = Path, index to icon
        • Shell
          • Verbs
        • ShellEx
          • Shell handlers

The types of shell extensions supported are at least context menu and property sheet extensions, as evident from Internet gateway devices (IGDs).

Give your laptop a shot of caffeine

January 24, 2011 Leave a comment

Tired of your laptop sleeping on the job whenever you walk away for a short while? Give it a shot of caffeine!

Caffeine is a small utility application written on top of the Windows Presentation Foundation that allows you to keep your monitor and/or system awake. It does not disable your screensaver, nor prevent your system from sleeping when you force it – like when you close the lid – so you’re in complete control. You do not need to change your power options – which you may forget to revert later. Just run the application and click whether you want to keep your display, system, or both awake. When you quit the application it remembers your settings and allows your system to sleep as configured again.

So give your system a shot of caffeine today and keep it working all night too!

This is a sample application I wrote and published as a helpful utility I’ve needed quite a few times. Baristas, obscure indie music, and free wi-fi not included.

Categories: Computers and Internet Tags:

Jealous over Windows Phone 7

November 21, 2010 Leave a comment

If I hear someone else gloat over their new cool Windows Phone 7 device and flash it in my face, I’m likely to scream, grab it, and run. Yes, it’s a great device that fits nicely between the form and function of iPhone (minimum set of hardware requirements, which works great for developers) and the availability on different hardware as Android (or Windows Mobile) with no real requirements (and a pain for developers).

But I’m on Verizon, and no CDMA Windows Phone 7s are available yet. Sprint has announced one or two already, and Verizon seems they will get an HTC sometime next year (after Sprint, since Verizon apparently takes longer to test devices).

So dear friends and colleagues, be happy with your device but when you show how cool it is to me, make sure you hold on tight!

Messenger on Zune HD

October 1, 2010 Leave a comment

Engadget tipped me off that in addition to Microsoft Windows Live Essentials 2011 having released yesterday, the team also released Messenger for Zune HD. So since I have to wait until H1 2011 (whatever that means) to get my Windows Phone 7 with Verizon, I can use all the cool new social features in Messenger on my snappy Zune HD. And if that’s anything like Windows Phone 7 – and it’s supposed to be better – I’m even more excited!

Moved to WordPress

October 1, 2010 Leave a comment

As reported on CNET et. al. Microsoft will be closing down Windows Live Spaces where I’ve kept my personal musings for a few years now. Microsoft has, however, made migrating a Live Space to WordPress.com a breeze that carries over most everything including posts, images, and categories no matter how old.

It’s a good platform and I’m looking forward to playing around with it. Definitely an improvement, which I’m sure is one reason Microsoft chose to focus their efforts on other projects and leave WordPress handle what it does best.

Picking a name wasn’t easy. When I signed up for Spaces, it was still beta so I could get the name I wanted easily. However, WordPress has been around for a long time so a lot of ideas were taken. I considered a few like “heathing” which my old doctor, mentor, Scout master, and friend used to say I was doing when whatever I was doing was otherwise undefined. Like other ideas, it looked word as a URL. Sorry, Doc.

So in honor of Monty Python – which I my wife just loves (not really) – I chose “lifeofheath”. Unfortunately squatters took several more reasonable names, but what can one do?

So while I continue to post work-related posts about deployment, Visual Studio, .NET and other such topics to http://blogs.msdn.com/heaths; here I’ll post things about what’s going in life with my family and me. It’s not the most exciting life, but I’ve got a wonderful wife, sweet daughter, and joyful (and not always annoying) dog that make it fun.

Categories: Family

Drive Icon for Seagate Expansion External Drives

February 7, 2010 6 comments

I saw some posts where people were asking for the icon and Autorun.inf files that shipped with the following drives from Seagate.

  • ST305004EXA101-RK – 500 GB
  • ST310005EXA101-RK – 1 TB
  • ST315005EXA101-RK – 1.5 TB
  • ST320005EXA101-RK – 2 TB

If you formatted your drive or are otherwise missing these files, just extract the contents of the following ZIP archive to the root of your expansion drive. Changes may not appear right away. You may need to unplug and re-plug in your drive.

Download: http://sdrv.ms/TEm13j