2010-03-26

PowerShell isn't perfect

Linux: du -s *

PowerShell: dir | foreach { $item = $_; dir $item -Recurse | Measure-Object length -sum | select -Property @{n="Item";e={$item}}, count, sum }


Would you like to have more readable output (ie: in MBs)?

Linux: du -sh *

PowerShell: dir | foreach { $item = $_; dir $item -Recurse | Measure-Object length -sum | select -Property @{n="Item";e={$item}}, count, @{n="MB";e="{0:N2}" -f ($_.sum/1MB)} }

2010-03-21

Visual Studio regions in XCode

One of the few features that I've liked in Visual Studio that XCode doesn't have is the ability to define regions for code folding. It's nice to have regions of code that are logically grouped that you can collapse when you're working on other parts of the same method. (Of course, regions also work across methods, but this hint won't address that.)

Fortunately, XCode allows for block folding (which the versions of Visual Studio I've used don't have), which allows you do to something like this:

//region I want to fold
{
...code...
}

This defines a statement block that you can fold. When folded it ends up looking like this:

//region I want to fold
{...}

One caveat here... don't define any variables in that block that you'll need elsewhere. The statement block defines a local scope for any variables declared. This might be want you want, but it may also cause scoping issues. The compiler will probably warn you about this, however.

2010-03-18

PowerShell Training

I've finished a training that I did at work around PowerShell... a great shell language from Microsoft.

Yes, I said it in public, I like something Microsoft did. :-)

Really, the designers of PowerShell did something revolutionary with the traditional command line, they made it object-oriented. The biggest leap forward was allowing objects to be pipelined throughout the shell. This makes the language feel very similar to ruby in the way that I use it.

Anyway, with little other comment, here's a link to my presentation, if you're curious: