Miguel de Icaza, head of Mono, tweeted:

migueldeicazaIn 2007 @toshok used JSON instead of XML for XAML. It is wrist friendly, and programmer friendly:http://bit.ly/2fjEpN

The post, titled, why xaml when you can json? shows this snippet and has createFromJSON code.

JSON and XAML

var json = {
  Canvas: {
    name: "Toplevel Canvas",    children: {
      TextBlock: {
        Text: "Hello World"
      }
    }
  }
}

and it converts that to the following xaml:

<Canvas xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” x:Name=”Toplevel Canvas”><TextBlock Text=”Hello World”/></Canvas>

PowerBoots and PowerShell

image

{ 0 comments }

David Langworthy, the Microsoft architect who owns The “Oslo” Modeling Language Specification, has these “Modeling in Text” videos HERE that walk through the specific process of creating a domain-specific language.

Intellipad

image

Working from his example we’ll compile grammar and transform the DSL into Xaml using PowerShell to read and create PS Custom Objects.

  • I ‘embedded’ the DSL (lines 1-6)
  • The DSL Grammar (lines 9-26)
  • Called the M tool chain
    • line 28 the M Compiler
    • line 29 the MGrammar Executor

Then

  • Read the Xaml file produced
    • Converted it to an XmlDocument, line 31
    • Looped through the entities in the graph
  • And generated PowerShell Custom Objects

Finally

From DSL => DynamicParser => Custom Objects => WPF data bound control

image

Using the M tool chain in this ways has it’s advantages in several scenarios. This script can easily be streamlined by checking file dates and bypass the m and mgx steps.

In future posts we’ll see if we can interact with the MGrammar namespace and work with Oslo in a deeper way.

{ 0 comments }

DSLs and DSVs (Domain Specific Languages and Vocabularies) can be super helpful and are not complicated to build.

Example

The mean return to a portfolio is the weighted average return of the stocks making up the portfolio.

Let’s say a portfolio consists of 30% GOOG shares with a mean daily return of 0.14% and 70% MSFT shares, mean daily return of 0.03%.

The mean daily return is:

(0.3 * .14) + (0.7 * 0.03) = 0.063

Another portfolio of 50% GOOG and 50% MSFT gives

(0.5 * .14) + (0.5 * 0.03) = 0.085

The PowerShell DSV

I’d like to represent the portfolio like the following, legal PowerShell syntax.

image

 

Let’s build up the Domain Specific Vocabulary

Lines 1-3 enable the DSV to work and prints:

image

image

 

Adding lines 4-8 will output the snippet below. Note line 7 uses “&”, the PowerShell call operator, to evaluate the script block.

image

image 

 

Transform the Data into objects

Let’s transform the data into objects with properties so it prints the following table, with the added plus of addressable properties.

image

image
 
 

Calculate the Weighted Average

Adding a hash table lookup in lines 4-7 and the properties MeanDailyReturn and WeightedAverage in lines 18-24.

Lines 20 and 23 look up the MeanDailyReturn by stock name using dot notation.

image

image

In an upcoming post

The transformation of the DSV into objects and properties is finished. In an upcoming post we’ll add some more detail and play with the output.

{ 0 comments }

Neal Ford, in his book “The Productive Programmer”, says

The very things that make casual users more productive can hamper power users

He adds

You can get more done at the command line for most development chores than you can through a graphical interface

He was on a project that required opening and updating several spreadsheets on a regular basis. He took a few minutes and wrote a Ruby script to do it.

Even though it didn’t take long to open the files by hand, the little time it took was still a waste of time, so I automated it

The PowerShell Version

Open-XLWB

 
image

DailyLogs

 
image

Result

image

image

For ISE

In the PowerShell Integrated Scripting environment you can launch DailyLogs from the command pane.

Note

Software development has lots of obvious automation targets: builds, continuous integration and documentation. There are less obvious but no less valuable ways to automate development chores

PowerShell is an automation platform, automation platform, automation platform (quote from Jeffrey Snover). Let the automating begin.

Downloads

Place the two scripts in a folder that is in your path.

{ 0 comments }

The Data - People.csv

image

Use Import-Csv and type the data with Select

image 

Create the Excel Pivot Table

$people | .\Out-ExcelPivotTable

 

image

The easiest way to get a Pivot Table.

Out-ExcelPivotTable inspects the piped data, sets up the numeric properties as data fields and string properties as row fields (nested).

 

 

$people | .\Out-ExcelPivotTable name dept salary

 

image

Same data.

You control what goes in the different pivot fields. Row (name), Column (dept) and Data (salary).

 

 

 

$people | .\Out-ExcelPivotTable -values YearsEmployeed

 

image

You control the pivot data field with the –values parameter letting  Out-ExcelPivotTable do the rest.

Name is nested in Department.

 

 

 

 

ToDo

  • Set up Out-ExcelPivotTable parameters to take arrays
  • Formatting of value fields
  • Naming of Row and Column Labels
  • Enable Types of aggregates for Value field
  • Improve data layout performance

I have only tried this on the latest version of Excel.

Download It

{ 1 comment }

Thanks to Oising at Nivot Ink for replying to my tweet. The easy way, download the PreviewConfig Tool HERE.

Couple clicks

image

And you’re previewing PowerShell files, in Windows Explorer

image

{ 0 comments }

Even has a concierge.

image

{ 0 comments }

image

The Code

{ 0 comments }

PowerShell meet WPF via PowerBoots

by Doug Finke on June 18, 2009

in PowerBoots, PowerShell, WPF

Joel "Jaykul" Bennett released a new version PowerShell PowerBoots on CodePlex.

PowerBoots is inspired by Ruby Shoes a graphics toolkit. I blogged about Ruby Shoes and the start of a PowerShell version doing some simple work using WinForms.

PowerBoots goes deep, check it out:

  • Asynchronous UIs and event handling
  • WPF graphical user interfaces
  • Support for Control Templates and Styles, DataTemplates, and Attached Dependency Properties
  • Generate graphical widgets that automatically update in the background, and interact with them from the console

Example

I put this together so I can see the services and processes running on my box.

image 

 

image

Click the Services radio button Get-Services cmdlet is executed. The $targetProperty is set to Status for display.

Select a server and it’s status is displayed.

 

 

 

 

 

image

Click the Processes radio button and the ps alias is run. The $targetProperty is set to Company property which is displayed.

Selected a process and the Company Name is displayed.

 

 

 

Download the Code Sample

{ 0 comments }

One of the organizers, GoF author Ralph Johnson, posts on it. He points to the wiki Pattern Language for Parallel Programming ver2.0 book Patterns for Parallel Programming and papers presented.

Some of the pattern categories

  • Computational Patterns
  • Concurrent Execution Patterns
  • Implementation Strategy Patterns
  • Parallel Algorithm Strategy Patterns
  • Structural Patterns

{ 0 comments }