Ternary: Reducing code

I like my scripts to be readable and terse.  They’re scripts after all and I want to get the most done with the least amount of code.  There’s a lot to be said for having a readable script but I only value that when I intend to keep the script around for awhile.  PowerShell does…

1

C# Lambda Type Inference

One of the limitations of C# type inference is that you cannot use it to infer the type of a lambda expression.  For example, the following code will not compile var f = () => 4; Normally this is not too much of an issue because you can just explicitly declare the type of the…

1

Filtering get-psdrive to all Local Drives

Recently I needed to filter the return of get-psdrive to return all of my local hard drives.  I didn’t want to accidentally start operating on floppies, CDROM’s and more importantly, network drives.  There are a couple of ways to do this but I found the most straight forward is to combine the WMI data with…

2

Types of Immutability

By definition, an immutable object in computer science is one that is not able to change.  Parallel coding is becoming more necessary as the number of cores in a processor are increasing but not the overall speed.  As such immutability is will become more important because it is an important asset of multithreaded programming.  Immutable…

3

Getting my Fortune

Fortune is a Unix command that gets a random message from a set of databases and displays it on the screen.  These messages have a wide variety but tend to be funny, quirky or famous quotes (most are indeed geeky).  Nearly all unix systems have a version of Fortune.  Windows doesn’t have any version by…

1

ViEmu and Suites

ViEmu is a Visual Studio Package which adds Vim keybinding support into Visual Studio.  For former VI users this is huge benefit as I can use all of my cryptic key combinations inside of Visual Studio. For those unfamiliar, Vi is one of the original editors for the Unix operating systems.  Vim (VI iMproved) is…

1

Calling Extension Methods on Null Objects

One of the gotchas for Extension Methods is that it’s legal to call them on Null References.  This isn’t really surprising when you think about the feature.  Boiled down to a fundamental level, extension methods are just syntactic sugar for calling a static method and automatically passing the first parameter [1].  However it can catch…

1

Tuples in PowerShell

Tuples in computer science are usually light weight record objects with simple name value pairs.  In scripting languages it is very handy to create them on the fly.  For quite some time I was using associative arrays in PowerShell to do just that.  PS>$a = @{Name=”MyName”;Value=”MyValue”} It has essentially everything you would need from a…

6

Piping elements of a String

Quick script that will allow you to pipe each char in a String into the PowerShell pipeline.  function PipeStringChar() { param ( [string]$toPipe ) for ( $i = 0; $i -lt $toPipe.Length; $i++ ) { write-output $toPipe[$i] } } Alternatively you can do this by using the ToCharArray method.  However this will create a new…

0

Type Inference and IEnumerable

This is somewhat of a follow up on a previous post I did on the difference between IEnumerable(Of T) and the IEnumerable interfaces.  I’ve seen several people type in the following code and wonder if there was a fundamental bug in the type inference code. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)…

2