xcud

Sep 21

Out-AnsiGraph

Inspired by Chad Miller’s work MSChart I threw this ANSI barchart module together:

#
# Out-AnsiGraph.psm1
# Author:       xcud
# History:
#       v0.1 September 21, 2009 initial version
#
# PS Example> ps | select -first 5 | sort -property VM | 
#             Out-AnsiGraph ProcessName, VM
#                 AEADISRV ███ 14508032
#                  audiodg █████████ 50757632
#                  conhost █████████████ 73740288
# AppleMobileDeviceService ████████████████ 92061696
#                    btdna █████████████████████ 126443520
#
function Out-AnsiGraph($Parameter1=$null) {
	BEGIN {
		$q = new-object Collections.queue
		$max = 0; $namewidth = 0;
	}

	PROCESS {
		if($_) {
			$name = $_.($Parameter1[0]);
			$val = $_.($Parameter1[1])
			if($max -lt $val) { $max = $val}		 
			if($namewidth -lt $name.length) { 
				$namewidth = $name.length }
			$q.enqueue(@($name, $val))			
		}
	}

	END {
		$q | %{
			$graph = ""; 0..($_[1]/$max*20) | 
				%{ $graph += "█" }
			$name = "{0,$namewidth}" -f $_[0]
			"$name $graph " + $_[1]
		}

	}
}

Export-ModuleMember Out-AnsiGraph

Download the script here: http://bitbucket.org/xcud/powershell-snippets/src/tip/Out-AnsiGraph.psm1

Sep 19

MSChart in Psh

Read Chad Miller’s blog entry on using MSChart from PowerShell. This is another great visualization extension for PowerShell. To make it work:

  • Download and install Microsoft Chart Controls for Microsoft .NET Framework 3.5
  • Download LibraryChart
  • The easiest way to enable it is to import the library with a call to ‘Import-Module’. Now run one of the samples:

    If you see this error or one like it it’s an easy fix. Edit the lib and edit the input param list in the function “New-Chart” from this:

    param ([int]$width,[int]$height,[int]$left,[int]$top,$chartTitle)

    To this:

    param ([int]$width,[int]$height,[int]$left,[int]$top,[string]$chartTitle)

    Voila. Re-import the module and the error is gone. The only item on my wish list for this lib is that it attempt to infer the X and Y fields. A call like this, for example, should be able to (but can’t) infer that xField is ‘name’ and yField is ‘ws’:

    ps | Sort-Object WS | select name, ws -first 5 | out-chart

    It makes eye-candy. Check this one out. Grab the top 5 memory consuming processes and push them into a relative pie chart that auto-updates itself.

    out-chart -chartType ‘pie’ -xField ‘name’ -yField ‘WS’ -scriptBlock { Get-Process | Sort-Object -Property WS | Select-Object Name,WS -Last 5}

    Sep 15

    enable ‘svn commit’ from PowerShell

    If you’re trying to use Subversion from the PowerShell command line and you can’t get around this error message:

    PS C:\Users\Public\Source> svn commit .

    svn: Commit failed (details follow):

    svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the —message (-m) or —file (-F) options

    svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no ‘editor-cmd’ run-time configuration option was found

    Set your SVN_EDITOR preference with this command (substituting “type” for your preferred editor):

    PS C:\Users\Public\Source> set-item -path env:SVN_EDITOR -value “type”

    Aug 09

    back from vacation

    Vacation pics: http://www.flickr.com/photos/benvierck/sets/72157621985515336/

    I’m not completely back. i have not quite completed re-entry back into my daily work habits. I was a bit gobsmacked at my encounter with the ocean and our history. The vastness of the ocean which it seems to me could swallow us all up in an instant or two and not mind one bit on the one hand. The encounters with historical peoples whose very daily existence represented more adventure than I’ll know in a lifetime are on the other hand.

    Tomorrow i’ll shove this aside and do some work on the build process to make this last push to VMWord more productive and I’ll get the next build ready to go for a Monday release.

    Jul 17

    PowerShell Version Poll

    If you use PowerShell please participate in this poll.

    Jan 02

    The Developer Is In

    Starting next week I’ll be back in an office again for the first time since September. During these first three months of early R&D stage my office has been wherever my laptop happens to be. We’ve reached a new stage in development that requires more coordination. Tuesdays and Fridays from here out you can find me in my office down the hall from my partner. The nearer we get to release the more days I’ll add to my in-office schedule.

    Update … another milestone reached. We will unstealth soon.

    vmxbuilder.com

    VMWare utilities maven Robert Petruska has joined forces with Devfarm. Yesterday we debuted the new site where we’ll be distributing Robert’s VMWare Utilities as well the new software that we’ll be building together at http://vmxbuilder.com. JYoseph put together an awesome site design for us.

    For those keeping score at home (and starting to connect the dots) this is our second strategic rollout in the past month.

    Dec 28

    A Rough 30 Days

    It’s been a rough 30 days. Maybe the hardest 30 I’ve had to work through ever which is testament to how soft my life really is. Starting the first week back from vacation our house ran through the Flu twice. It infected everybody for a first pass over the course of 4 days then the same symptoms hit each and every one of us again for the next 2 days. A couple of days later the colds, sniffles, and sneezes hit. The next week ear infections and sinus infections. As a topper strep throat hit us this past week. Oh, and I ruptured an ear drum for good measure.

    While all this sickness was going on we got a tree, decorated the house, hosted 3 holiday get-togethers and attended 2 others. And … then there’s the whole matter of the startup that I SHOULD have been cranking out 12 hours a day on. Joe and I did manage to release a cool web service (see http://PingVine.com) that fills a niche and is powered on the back-end by Devfarm software. Still, while you enjoy your Christmas-to-New-Years holiday I’ll be getting a head-start on January to make it The Best Month Ever.

    Dec 26

    Twitter API 417

    Twitter’s servers have started returning HTTP error 417 for requests that come with an Expect header containing “100-continue”.  .NET automatically appends this header to every request. Before executing your WebRequest set this static property to false:

    System.Net.ServicePointManager.Expect100Continue = false;

    Now you’re forwards-compatible with the API/server change at Twitter.

    Dec 10

    Editorial Power

    Leave a comment counting to 3 if you secretly sing Britney Spears songs in the shower when you think noone’s listening.