notes on electronic projects and other things

Parallel processing in PowerShell

Running arbitrary number of tasks in parallel with PowerShell, while showin overall progress.

The main disadvantage of the code I provived in previous post is that it is performed sequentially. We can speed it up by means of parallel processing, since main limiting factor is not an I/O but minifying algorithms performance.

There are a lot of ways to use parallelism in PowerShell and it wasn’t clear for me which one suits well for my task. I.e. to convert my script, which is processing a lot of small files on a local machine.

It also should:

  • provide updates in real time;
  • keep output table formatting as close to original as possible.
Ellipsis function for PowerShell

One more unintended thing arised from not yet published post.

I was looking for a way to fit a lot of lengthy paths into console screen by removing less important parts. “Ellipsis” is a standard name for such a thing. You’re dealing with it every time you’re looking at “…” in place of something too long to fit into borders.

Here is my implementation for PowerShell.

Blog minification in a fancy way with PowerShell

There is no built-in support for minification in Hugo engine, which isn’t a bad thing on its own. But I had to figure out a way to minify my files while keeping building and maintenance extremely simple.

At first point I added minify for text files. It’s a single binary (written in Go), and with a single call it can run recursively over Hugo’s public folder, minifying output files in-place, just as I needed.

But minifying images is a more tricky task. I decided to use jpegtran and optipng, but they can’t be run recursively. Some scripting is required to use them. While the task of finding all the images in a folder and applying minifiers on them is trivial and can be solved with PowerShell one-liner, it was not satisfying enough, so I end up with the thing described below in this post.

Additional motivation is to have a tool that can be adopted easily to any other processing task and will give me a fancy progress report.

Quick note about objects in PowerShell

I decided to move this note out from another post.

It’s a kind of summary on a question “Why [PSCustomObject]@{} syntax is the preferred way to create objects in PS”. After looking into stackoverflow (one, two) and some other resources (three), I decided to test and write it down for myself.

Nothing really new here. I only hope it will work as a good summary.

Update: Select-Object examples. Additional links.

Ways to measure execution time in PowerShell

Ok, back to business. No electronics at least for a few posts though.

It will be clear later why I became interested in this topic. But it is, on its’ own, worth for a post, so here it is.


The canonical way to measure how long something runs in PowerShell is to use Measure-Command cmdlet.

> Measure-Command { "do stuff" }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 7436
TotalDays         : 8,60648148148148E-09
TotalHours        : 2,06555555555556E-07
TotalMinutes      : 1,23933333333333E-05
TotalSeconds      : 0,0007436
TotalMilliseconds : 0,7436

One notable downside of this is that you see no output from a command. Time span is returned instead.

What else can we do?

Circling the square

I have some more Paint.NET shapes added to collection. Superellipses to be precise. Check the project page.

Superellipse or Lamé curve is the shape produced by generalized equation of ellipse, where we change the power factor. It approaches to rectangular shape on large values.

Also check the video below for a little bit of history of this shape in design.