18

PowerShell 10 Year Anniversary Code Golf Winners

 4 years ago
source link: https://thomasrayner.ca/powershell-10-year-anniversary-code-golf-winners/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PowerShell 10 Year Anniversary Code Golf Winners

For the PowerShell 10 Year Anniversary, Will Anderson (@GamerLivingWill on Twitter) and I (@MrThomasRayner on Twitter) ran a three-hole code golf competition on code-golf.com, a site developed by fellow MVP Adam Driscoll.

Here is the link to all the background info on the competition: https://github.com/ThmsRynr/PS10YearCodeGolf . Check this page out for links to the individual holes, too.

So, without further delay, let’s announce the winners!

Hole 1

The challenge was to get all the security updates installed on the local computer in the last 30 days and return the results in the form of a [Microsoft.Management.Infrastructure.CimInstance] object (or an array of them).

The winner of this hole is Simon Wåhlin. Here is their 46 character submission.

gcim(gcls *ix*|% *mC*e)|? I*n -gt((date)+-30d)

gcls *ix* gets the CimClass win32_quickfixengineering and % *mC*e gets the CimClassName property. gcim is an alias for Get-CimInstance which, as per the previous section, is getting the win32_quickfixengineering class. The results are piped into the where-object cmdlet where the property matching the pattern I*n (which happens to be InstalledOn) is greater than the current date, minus 30 days.

Hole 2

The challenge was to get the top ten file extensions in c:\windows\system32, only return 10 items and group results by extension.

The winner of this hole is Simon Wåhlin again. Here is their 42 character submission.

(ls C:\*\s*2\*.*|% E*n|group|sort c* -d)[0..9]

ls c:\*\s*2\*.* means Get-ChildItem where the path is c:<em><any directory>\<a directory matching s*2>\<files, not directories> </em>and this pattern only matches the path c:\windows\system32\<files>. This is piped into the foreach-object cmdlet to retrieve the property that matches the pattern E*n,which is the Extension property. The extensions are piped into the sort-object cmdlet, sorted by the property that matches the pattern c*, which is count, and returned in descending order. This is an array, and the items in positions 0-9 are returned.

There were shorter submissions for this hole that didn’t explicitly target c:\windows\system32 and therefore missed the challenge. You could not assume we were already on c: or running as admin, etc. Some solutions included folders in the results which also missed the challenge.

Hole 3

The challenge was to get all the active aliases that are fewer than three characters long and do not resolve to a Get- command. For this hole, even though it wasn’t in the Pester test, you had to assume that non-standard aliases might be on the system. That’s why we specifically mentioned that we didn’t want you to return aliases that resolve to Get-*, and the Pester test checked the ResolvedCommand.Name property of the aliases you returned.

To break some submissions that didn’t check what the aliases resolved to, you could just run New-Alias x Get-ChildItem to create a new alias of ‘x’ that resolves to Get-ChildItem.

The winner of this hole is EdijsPerkums. Here is their 24 character submission.

gal ?,??|? Di* -Notm Get

Get-Alias is passed an array of regex patterns, ?,?? which corresponds to one and two characters. The results are piped into the where-object cmdlet to isolate aliases whose property that matches the pattern Di* (DisplayName) doesn’t match Get.

Congratulations to all the winners! We will be in touch to get you your prizes. We hope you all had fun with this mini-competition. Don’t forget to check out all the terrific material from the PowerShell 10 Year Anniversary on Channel 9!

Written on November 21, 2016

Recommend

  • 132
    • www.promptworks.com 7 years ago
    • Cache

    Connect "Fore!": Code Golf in Javascript

    Connect "Fore!": Code Golf in JavascriptTest and expand your Javascript knowledge with this fun challenge.September 25, 2017by Peter Caisse

  • 78
    • code-golf.io 7 years ago
    • Cache

    Code-Golf

    Code Golf Code Golf is a game designed to let you show off your code-fu by solving problems in the least number of characters. Since this is your f...

  • 76
    • www.tuicool.com 6 years ago
    • Cache

    Code Golf: Sparse Arrays

    Today on Twitter, Axel Rauschmayer posted a fun little coding challenge: Code golf: check if an Array has holes. I’ll reply with two ideas of mine in a f...

  • 29
    • www.tuicool.com 5 years ago
    • Cache

    5 Year Anniversary

    gfx-rs project started with a simple idea: separate the API-specific logic of interaction with the graphic driver from a Rust application. That idea was brewing in the heads of

  • 32
    • bfontaine.net 5 years ago
    • Cache

    Introduction to Code-Golf in Clojure

    Code-Golf is the art of writing the shortest program in a given language that implements some given algorithm. It started in the 90’s in the Perl community and spread to other languages; there are now languages dedicated...

  • 36
    • code-golf.io 5 years ago
    • Cache

    Code Golf

    Code Golf Code Golf is a game designed to let you show off your code-fu by solving problems in the least number of characters. Since this is your first time he...

  • 14

    Video of Flash 10 Year Anniversary Party at Adobe in San Francisco Thursday, August 10, 2006 I have just uploaded a video of some of the Flash 10 Yea...

  • 7

    Happy anniversary, Neo4j Graph Data Science! Has it really been a year already?! We announced the Neo4j’s Graph Data Science (GDS) framework back in April 2020, and we’ve come a long way since!

  • 9

    Code a Spectrum-style Crazy Golf game | Wireframe #54 Putt the ball around irrational obstacles in our retro take on golf. Mark Vanstone has the code First released by...

  • 6

    Code Golf Code Golf is a game designed to let you show off your code-fu by solving problems in the least number of characters. Since this is your first...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK