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.

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!

Follow

Get every new post delivered to your Inbox.