Skip to content

Commit

Permalink
✨ Port of PowerShell Intro Training into PSKoans (#241)
Browse files Browse the repository at this point in the history
* documented koan order

* Documented all proposed changes

* Update koanOrder.md

* FunExamples and WhatIsDotNet

- Created FunExamples Koan
- Created WhatIsDotNet Koan.
- Having issues abstracting answers for WhatIsDotNet

* Added OOP and edited other Koans

- Added OOP Koans
- Renamed Koans to match naming conventions
- Changed AnswerFunction modules to use same template for returning answers
- Tested all "drafted" items under koanOrder.md

* AboutCmdletVerbs

- Created AboutcmdletVerbs Koans module.
- Added function help to AboutOOPAnswers and AboutDotNetAnswers
- Updated koanORder

* Forgot to update koanOrder status

- Updated status for AboutCmdletVerbs

* Drafted AboutGetMember

- Drafted AboutGetMember
- Expanded scope of IntroTraining

* Drafted AboutBooleans

- Drafted AboutBooleans
- Changed AboutStrings to use Foundation version rather than IntroTraining

* Drafted AboutInts

- Drafted AboutInts
- Reordered Koans
- Next step is AboutBinary

* Drafted AboutBinary

- Drafted AboutBinary
- Made small edits to AboutInts following on from testing

* Final draft

- Reordered koans
- Final draft

* Removed conflicting files

- Removed conflicting files:

PSKoans\Koans\Foundations\AboutTheStockChallenge.Koans.ps1

PSKoans\Koans\Testing Grounds\TestingHashtables.Koans.ps1

- Need to merge PR1.
- Then change AboutTheStockChallenge to position 116

* Updated StockChallenge position

- Updated StockChallenge position after PR1 merged.

* Added line ends

- Added line ends to new Koans for CI compatibility

* AboutBinary update 01

Updated in-line with PR#241 into PSKoans.

* AboutBinary update 02

Updated in-line with PR#241 into PSKoans.

* Apply suggestions from code review

Applied suggestions from PR#241 review

Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>

* AboutBinary update 03

Updated in-line with PR#241 into PSKoans.

* New Line edits

Changed VS Code to append line ends on save to all files.

* AboutBinary update 04

- Related to PR#241
- Increased indentation of Bit Conversion block
- Removed excess E.G. comments

* Apply suggestions from code review

Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>

* Update AboutBinary 05

- Related to PR#241
- Removed references to nibbles
- Merged nibble and int blocks into one

* Update AboutBinary 06

- Relates to PR #241
- Fixed spelling mistakes

* Update AboutBooleans 01

- Related to PR #241
- Minor changes in-line with PR Owner requests

* Update AboutBooleans 02

- Relates to PR #241
- Intended comment block for describe booleans

* Update AboutCmdletVerbs 01

- Relates to PR #241
- Intended ```It``` blocks and remove "End of" comments
- Removed abstraction of answers
- Doubled underscores

* Update AboutCmdletVerbs 02

- Relates to PR #241
- Added reference to functions
- Added reference to Get-Verb
- Intended code examples
- Remove answer module
- Reframed Koans

* Update AboutDotNet 01

- Related to PR #241
- Deleted AboutDotNet
- Amended koanOrder.md

* Update AboutDotNet 02

- Related to PR #241
- Removed AboutDotNetAnswers module as AboutDotNet Koan has been deleted

* Update AboutExamples 01

- Related to PR #241
- Removed AboutExamples 01
- Turned Cats/GUI example into Advice JSON
- Decided not to port over rickroll example
- Amended koanOrder

* Update AboutExamples 02

- Related to PR #241
- Reformatted advice JSON files

* Update AboutGetMember 01

- Related to PR #241
- Changed comment block title
- Changed Get-Service references to Get-Process to make this Joan cross-platform

*WIP*:
- Added check at end of each It block to make sure user enters unique cmdlets
- Removed answer abstraction

* Update AboutGetMember 02

- Related to PR #241
- Reformatted Koans
- Fixed error with unique count; forget to check the count property rather than whole object
- Removed AboutGetMember answer module
- Need to fix "Describe" not being picked up when checking Karma
- Added line endings to AboutOOPAnswers to hopefully fix CI/CD issues

* Update AboutCmdletVerbs 03

- Related to PR #241
- Made minor text changes as per PR review

* Update line-ends

Hopefully added enough line-ends for CI/CD. Maybe my VS Code is being weird...

* Update AboutCmdletVerbs 04

- Related to PR #241
- More minor changes

* Update AboutCmdletVerbs 05

- Related to PR #241
- Minor changes

* Update AboutCmdletVerbs 06

- Related to PR #241
- Removed 1 line

* Update AboutGetMember

- Related to PR #241
- Minor changes to formatting

* Update AboutInts 01

- Related to PR #241
- Deleted AboutINTs file
- Replaced with Numbers advise file

* Update AboutNumbers 02

- Related to PR #241
- Recreated AboutNumbers but this time with more basic information
- Removed Numbers advise as replaced with AboutNumbers

* Update AboutNumbes 03

- Related to PR #241
- Minor UX changes
- Updated readme to contain md links

* Update KoanOrder 01

- Testing GitHub relative links in markdown

* Update KoanOrder 02

- Updated relative links to remove leading ../

* Update KoanOrder 03

- Renamed all intro koans to uppercase K for relative links to work, might need to redo in GitHub GUI
- Replaced spaces in markdown to %20, but best practice would be to remove all spaces from file paths

* Rename AboutBinary.koans.ps1 to AboutBinary.Koans.ps1

* Rename AboutBooleans.koans.ps1 to AboutBooleans.Koans.ps1

* Rename AboutCmdletVerbs.koans.ps1 to AboutCmdletVerbs.Koans.ps1

* Rename AboutGetMember.koans.ps1 to AboutGetMember.Koans.ps1

* Rename AboutNumbers.koans.ps1 to AboutNumbers.Koans.ps1

* Rename AboutOOP.koans.ps1 to AboutOOP.Koans.ps1

* Update KoanOrder 04

- Renamed broken links

* Update AboutOOP

- Related to PR #241
- Moved OOP and Answers to drafts
- Created advise file for OOP

* Update AboutOOP 2

- Related to PR #241
- Renamed IntroTraining to Introduction
- Moved AboutAssertions and AboutStrings into Introduction folder
- Renamed all references to IntroTraining in koanorder.md
- Updated OOPIntrodution.Advice.Json inline with PR comments

* Update AboutOOP 3

- Related to PR #241
- Made small changes to advice file

* Deleted AboutAsserts

- Related to PR #3
- Removed conflicting file to allow for merge

* Update AboutAsserts

- Related to PR #241
- Removed double space

* Rename AboutOOP.Koans.ps1 to AboutOOP.ps1

- Renamed to avoid CI failure due to koan not having int position
  • Loading branch information
benjaminlukeclark authored and vexx32 committed Oct 1, 2019
1 parent 34ebf38 commit b1fbf7e
Show file tree
Hide file tree
Showing 25 changed files with 1,116 additions and 12 deletions.
26 changes: 26 additions & 0 deletions PSKoans/Data/Advice/Fun/FunWithCats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Title": "Fun with Cat Facts",
"Content": [
"PowerShell doesn't have to all be about Server administration, ops, or automation.",
"\n",
"It can also be fun!",
"\n",
"We've provided some fun examples below just to give you a taste of what PowerShell can do",
"Cats",
"\n",
" The below code snippit will query a RESTAPI on the internet that provides some fun facts about cats. It then uses the SpeechSynthesizer to tell you these facts! Feel free to run it on your machine:",
"\n",
"function Get-CatFact {",
"\n",
"\tAdd-Type -AssemblyName System.Speech",
"\t$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer",
"\t$URI = 'http://www.catfact.info/api/v1/facts.json?per_page=200'",
"\t$Random = Get-Random -Maximum 200",
"\t$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri $URI)).Facts[$Random]",
"\t$SpeechSynth.Speak('did you know?')",
"\t$SpeechSynth.Speak($CatFact.details)",
"}",
"\n",
"Get-CatFact"
]
}
37 changes: 37 additions & 0 deletions PSKoans/Data/Advice/Fun/FunWithGUIs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Title": "Fun with GUIs",
"Content": [
"PowerShell doesn't have to all be about Server administration, ops, or automation.",
"It can also be fun!",
"\n",
"We've provided some fun examples below just to give you a taste of what PowerShell can do",
"\n",
"GUIs",
"\n",
"\tThe below code snippit will make a blue GUI. When you're more experienced you may",
"\twant to start making GUIs for your scripts. This is just a quick example.",
"\n",
"\tCopy the below into PowerShell ISE to create the GUI!",
"\n",
"# Import Assemblies ",
"[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')",
"[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')",
"\n",
"\n",
"# Create a new form object and assign it to the variable GUIExample",
"$GUIExample = New-Object System.Windows.Forms.Form",
"\n",
"# Define the background image and then set the form to be the same height/width as the image",
"$BackgroundImage = [System.Drawing.Image]",
"$GUIExample.BackColor = 'Blue'",
"$GUIExample.Width = 200",
"$GUIExample.Height = 400",
"\n",
"# Make the GUI the topmost window and give it focus (make it the selected window)",
"$GUIExample.TopMost = $True",
"$GUIExample.Add_Shown({$GUIExample.Activate()})",
"\n",
"# Show the GUI",
"[void]$GUIExample.ShowDialog()"
]
}
33 changes: 33 additions & 0 deletions PSKoans/Data/Advice/OOP/OOPIntroduction.Advice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Title": "Object-Orientated Programming (OOP) Introduction",
"Content": [

"PowerShell is an object-oriented shell, but what does this mean? Everything is an object!",
"\n",
"Objects are a way for us to build programs to scale, and OOP is standard in software development. There are three fundamentals you need to know:",
"\n",
"\t1. Objects have defined types, which are like blueprints",
"\t2. Objects store data in properties",
"\t3. Objects have methods which can be called to perform an action",
"\n",
"If you've already completed the Get-Member topic, then you'll know we can use this cmdlet to discover what blueprint an object is using, what properties it has, and what methods it may execute. For example, we may take a string and pass it into Get-Member in order to get the below result:",
"\n",
"\t\tTypeName: System.String",
"\n",
"\tName MemberType Definition",
"\t---- ---------- ----------",
"\tClone Method System.Object Clone(), System.Object ICloneable.Clone()",
"\tLength Property int Length {get;}",
"\n",
"Which shows us the object type (System.String), as well as some properties and methods.",
"\n",
"For more information please see the below articles on OOP concepts:",
"\n",
"\t Abstraction: https://stackify.com/oop-concept-abstraction/",
"\t Encapsulation: https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/",
"\t Inheritance: https://stackify.com/oop-concept-inheritance/",
"\t Polymorphism: https://stackify.com/oop-concept-polymorphism/",
"\n",
"The .NET Core API browser may also be useful given that .NET is the foundation on which PowerShell is built: https://docs.microsoft.com/en-us/dotnet/api/?view=netcore-3.0"
]
}
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutArrays.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 105)]
[Koan(Position = 113)]
param()
<#
Arrays and Iterable Collections
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 106)]
[Koan(Position = 112)]
param()
<#
Assignment and Arithmetic Operators
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutComparison.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 107)]
[Koan(Position = 114)]
param()
<#
Comparison Operators
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutConditionals.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 110)]
[Koan(Position = 120)]
param()
<#
Conditionals and Branching
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 103)]
[Koan(Position = 121)]
param()
<#
Functions & Script Blocks (I)
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutHashtables.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 112)]
[Koan(Position = 130)]
param()
<#
Hashtables
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutLoopsAndPipelines.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 113)]
[Koan(Position = 131)]
param()
<#
The Pipeline & Loops
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutOrderOfOperations.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 104)]
[Koan(Position = 122)]
param()
<#
Order of Operations
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutStringOperators.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 109)]
[Koan(Position = 115)]
param()
<#
String Operators
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutTypeOperators.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 111)]
[Koan(Position = 129)]
param()
<#
Type Operators
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Foundations/AboutVariables.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 102)]
[Koan(Position = 111)]
param()
<#
Variables
Expand Down
155 changes: 155 additions & 0 deletions PSKoans/Koans/Introduction/AboutBinary.Koans.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using module PSKoans
[Koan(Position = 109)]
param()
<#
Binary
Binary is a base 2 number system, and only uses two numbers: 0 and 1.
Binary is the basis of all computing and computational storage. It's simple & straightforward,
and directly represents the underlying hardware states, which can only be on (1) or off (0).
It's useful to know binary when working with PowerShell to understand how integers are represented,
which is our next Koan. It's also extremely useful knowledge if you plan on delving deeper into computing;
the knowledge is applicable to networking, programming, data science, databases, and essentially every
other area of computing.
What is represents is a base 2 number.
For example, the below binary represents a "byte" of data, which contains 8 "bits".
Each bit will be either 1 or 0, as mentioned earlier.
So:
2^7 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
-----+-----+-----+-----+-----+-----+-----+-----
0 0 0 0 0 0 0 1
Or:
00000001
Is actually 1
And 00000011
Is three. As both 1 and 2 are on, and 1 + 2 is equal to 3.
#>

Describe "Binary conversion" {

It "Bit conversion" {
<#
When converting from bit to a boolean try and guess what each would be
#>

# What would 0 be if converted to be boolean?
# Replace __ with either $true or $false
$____ -as [int] | Should -Be 0

# What would 1 be if converted to be boolean?
# Replace __ with either $true or $false
$__ -as [int] | Should -Be 1
}

It "Binary to integer conversion" {
<#
Convert the following binary representations into integers
#>

# Replace __ with the decimal value of 1111
# E.G. __ becomes 1234
$Binary = "1111"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 1000
$Binary = "1000"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 0010
$Binary = "0010"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 1001
$Binary = "1001"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11111111
$Binary = "11111111"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 10101010
$Binary = "10101010"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11001100
$Binary = "11001100"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11110001
$Binary = "11110001"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))


}

It "Integer to Binary conversion" {
<#
Convert the following integers into their binary representation
#>

# Replace __ with the binary value of 7
# E.G. "__" becomes "0100"
$Binary = "__"
$Value = 7
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 12
$Binary = "__"
$Value = 12
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 2
$Binary = "__"
$Value = 2
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 14
$Binary = "__"
$Value = 7
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 103
# E.G. "__" becomes "01001110"
$Binary = "__"
$Value = 103
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 250
$Binary = "__"
$Value = 250
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 74
$Binary = "__"
$Value = 74
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 32
$Binary = "__"
$Value = 32
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

}

}
50 changes: 50 additions & 0 deletions PSKoans/Koans/Introduction/AboutBooleans.Koans.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using module PSKoans
[Koan(Position = 108)]
param()
<#
Booleans
Booleans in PowerShell are either True or False, 1 or 0, on or off.
They allow us to represent a logical, binary, state of being.
"Can I stop this service?" The answer is yes or no.
Therefore, the CanStop property for a System.ServiceProcess.ServiceController object
is a Boolean, shorthanded to bool. As the only possible respone we expect to the question
"Can i stop this service?" is a yes or no answer.
Check for yourself by running the following code:
Get-Service | Get-Member
Then scroll down till you see the "CanStop" property:
CanStop Property bool CanStop {get;}
There are two possible values for a boolean: $true or $false
#>

Describe "Booleans" {
<#
Using only booleans, so $True or $False, answer the following questions
#>
It "True or False" {

# Replace the blanks with $true or $false
$____ | Should -Be (1 -gt 2) -Because '1 is not greater than 2'

$____ | Should -Be (1 -lt 2) -Because "1 is greater than two"

$____ | Should -Be (10 -lt 20) -Because "10 is less than 20"

$____ | Should -Be (10 -gt 20) -Because "10 is less than 20"

$____ | Should -Be (3 -eq 3) -Because "3 is equal to 3"

$____ | Should -Be (100 -lt 1) -Because "100 is less than one"

}
}

0 comments on commit b1fbf7e

Please sign in to comment.