Code Monkey home page Code Monkey logo

tiny-powershell-projects's Introduction

Tiny PowerShell Projects

This is the code repository for Tiny PowerShell Projects.

I ported it from the Manning Publications book, Tiny Python Projects, by Ken Youens-Clark:

One of the many cool aspects of this not only the approach to learning PowerShell this way, additionally, you can head over to the Python repo and see how it is done in that language. Could be you are here because you're a Pythonista, and want to see how PoShers do it.

Either way, it's the same puzzles implemented in both languages, and you can use the tests provided, to do Test Driven Development and prove these and your solutions work, as you make changes.

The approach

There is a directory for each chapter of the book. There is a README to describe each exercise. Each directory contains a test.ps1 program you can use with Invoke-Pester to check that you have written the program correctly.

In addition, each directory has two PowerShell scripts, one called AllTest.ps1, and the other solution1.ps1.

AllTest

AllTest.ps1 does something very beneficial. It looks in that chapters directory for all files that match the wildcard solution*.ps1, and one by one copies it to a ps1 that is expected in the test.ps1, and the last step, it calls Invoke-Pester.

This allows you to keep the original solution supplied, and you can then create as many solutions as you'd like to test different ways to solve the puzzle. This lets you experiment with different ways to use a regex, arrays, hash tables or other approaches, in order to figure out better ways to handle this. The different solutions can sit side by side with the others and the test.ps1 can be automatically run against all.

Testing is Integral

The testing step is integral to writing and solving these challenges.

Using a "test-driven development" mentality, where you write tests before you write code, is very much recommended.

The tests should define what it means for a program to be correct, and then you write programs to satisfy the tests.

All the tests have been written for you, and you should write your own functions and tests. Practice is key.

You should run the test suite after every change to your program to ensure you are making progress!

Chapters

  • Chapter 1: How to write and test a PowerShell program How to create a PowerShell program that prints a string and takes a parameter. [source code]

  • Chapter 2: Crow's Nest How to write a PowerShell program that accepts a single, positional argument and creates a newly formatted output string. [source code]

  • Chapter 3: Picnic Writing a PowerShell program that accepts multiple string arguments and formats the results depending on the number of items. [source code]

  • Chapter 4: Jump The Five Writing a PowerShell program to encode the numerals in a given text using an algorithm called "Jump The Five." Use of a dictionary as a lookup table, characters not in the dictionary remain unchanged. Introduction to encoding/decoding text, basic idea of encryption. [source code]

  • Chapter 5: Howler Writing a PowerShell program that can process input text either from the command line or from a file.The output prints either to STDOUT or to a file. Learning about how to read/write the contents of a file. [source code]

  • Chapter 6: Word Count Writing a PowerShell program to emulate a word count program. Validates and processes multiple file inputs as well as STDIN and creates output of the counts of lines, words, and characters for each file. [source code]

  • Chapter 7: Gashlycrumb Writing a PowerShell program that processes an input file to build a lookup table (dictionary) that is used with multiple positional arguments to translate to the values from the file. [source code]

  • Chapter 8: Apples and Bananas Writing a PowerShell program to find and replace elements in a string. [source code]

  • Chapter 9: Abuse Writing a PowerShell program to generate Shakespearean insults by randomly combining some number of adjectives with a randomly chosen noun. Learning about randomness, seeds, and testing. [source code]

  • Chapter 10: Telephone Using probabilistic and deterministic approaches to randomly mutate a string. [source code]

  • Chapter 11: Bottles of Beer Writing a PowerShell program to produce the verse to the "99 Bottles of Beer" song from a given starting point. Learning to count down, format strings, algorithm design. A focus on writing a function and unit test, exploring ways to incorporate our function to generate the verses from for loops. [source code]

  • Chapter 12: Ransom Writing a PowerShell program that will randomly capitalize letters in a given piece of text for the nefarious purpose of creating a ransom note. [source code]

  • Chapter 13: Twelve Days of Christmas Writing a PowerShell program to create the verses for "The Twelve Days of Christmas" from a given day. Learning how to write a function and the test for it, then using the function in a list to generate the output. [source code]

  • Chapter 14: The Rhymer Writing a PowerShell program that can split off any initial consonants from a word and append a list of prefixes to create new rhyming "words." Exploration of regular expressions to handle words with no initial consonants, with one or more leading consonants, and nothing but consonants. [source code]

  • Chapter 15: The Kentucky Friar In this chapter we delve further into regular expressions, first learning how to split a string using a regex so we can separate things that look like "words" from non-words like punctuation and whitespace. Then we try to identify the word "you" (case-insensitive) to turn into "y'all" and any 2-syllable words ending in "-ing" so we can replace the final "g" with an apostrophe so that "cooking" becomes "cookin'" but "swing" would remain "swing." We then apply this to an entire body of text to Kentucky fry the words with amusing results. [source code]

  • Chapter 16: The Scrambler Writing a PowerShell program to find each "word" in a body of text and then scramble the letters such that the first and last letters remain in place, then reconstructing the text for output. Using regular expressions to split text, using Sort-Object { Get-Random }. [source code]

tiny-powershell-projects's People

Contributors

dfinke avatar grant-steinfeld avatar markus-hanisch avatar secretgeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiny-powershell-projects's Issues

Dockerfile broken

The following command in the Dockerfile is failing https://github.com/dfinke/Tiny-PowerShell-Projects/blob/master/Dockerfile#L64
Log from Binder:

Step 19/24 : RUN dotnet tool install -g Microsoft.dotnet-interactive --version 1.0.140401 --add-source "https://dotnet.myget.org/F/dotnet-try/api/v3/index.json"
 ---> [Warning] Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
 ---> Running in cddd4eabb666
/usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error : Unable to load the service index for source https://dotnet.myget.org/F/dotnet-try/api/v3/index.json. [/tmp/g1pulogo.tty/restore.csproj]
/usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error :   The SSL connection could not be established, see inner exception. [/tmp/g1pulogo.tty/restore.csproj]
/usr/share/dotnet/sdk/3.1.301/NuGet.targets(128,5): error :   The remote certificate is invalid according to the validation procedure. [/tmp/g1pulogo.tty/restore.csproj]
�[91mThe tool package could not be restored.
Tool 'microsoft.dotnet-interactive' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
�[0mRemoving intermediate container cddd4eabb666
The command '/bin/bash -o pipefail -c dotnet tool install -g Microsoft.dotnet-interactive --version 1.0.140401 --add-source "https://dotnet.myget.org/F/dotnet-try/api/v3/index.json"' returned a non-zero code: 1Built image, launching...
Failed to connect to event stream

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.