-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
102,050 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
JakubJares/C# ecosystem intro/MySolution/ClassLibrary1/ClassLibrary1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
JakubJares/C# ecosystem intro/MySolution/ClassLibrary1/Emoji.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ClassLibrary1 | ||
{ | ||
public class Emoji | ||
{ | ||
public string Name { get; set; } // Avocado | ||
public string Glyph { get; set; } // 🥑 | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
JakubJares/C# ecosystem intro/MySolution/ClassLibrary1/EmojiMath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace ClassLibrary1 | ||
{ | ||
public class EmojiMath | ||
{ | ||
public Emoji Add(Emoji left, Emoji right) | ||
{ | ||
var emoji = new Emoji | ||
{ | ||
Name = $"{left.Name}+{right.Name}", | ||
Glyph = left.Glyph + right.Glyph, | ||
}; | ||
|
||
return emoji; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
JakubJares/C# ecosystem intro/MySolution/ConsoleApp1/ConsoleApp1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ConsoleDump" Version="0.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
36 changes: 36 additions & 0 deletions
36
JakubJares/C# ecosystem intro/MySolution/ConsoleApp1/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
| ||
using ClassLibrary1; | ||
using ConsoleDump; | ||
using System; | ||
|
||
namespace ConsoleApp1 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var math = new EmojiMath(); | ||
var avocado = new Emoji | ||
{ | ||
Name = "avocado", | ||
Glyph = "🥑", | ||
}; | ||
var unicorn = new Emoji | ||
{ | ||
Name = "unicorn", | ||
Glyph = "🦄" | ||
}; | ||
|
||
var result = math.Add(avocado, unicorn); | ||
Console.WriteLine(result); | ||
Console.WriteLine("-----------\n"); | ||
|
||
Console.WriteLine($"{result.Name} {result.Glyph}"); | ||
Console.WriteLine("-----------\n"); | ||
|
||
result.Dump(); | ||
|
||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31025.194 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{FFE5B6BE-B58A-4222-AB80-D390F19BFB09}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject1", "TestProject1\TestProject1.csproj", "{950036A2-E67D-4E29-9AE8-C05E79384D81}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{6C183BC1-BB1D-4E99-A82F-F13CD1E97A5A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FFE5B6BE-B58A-4222-AB80-D390F19BFB09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FFE5B6BE-B58A-4222-AB80-D390F19BFB09}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FFE5B6BE-B58A-4222-AB80-D390F19BFB09}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FFE5B6BE-B58A-4222-AB80-D390F19BFB09}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{950036A2-E67D-4E29-9AE8-C05E79384D81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{950036A2-E67D-4E29-9AE8-C05E79384D81}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{950036A2-E67D-4E29-9AE8-C05E79384D81}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{950036A2-E67D-4E29-9AE8-C05E79384D81}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6C183BC1-BB1D-4E99-A82F-F13CD1E97A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6C183BC1-BB1D-4E99-A82F-F13CD1E97A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6C183BC1-BB1D-4E99-A82F-F13CD1E97A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6C183BC1-BB1D-4E99-A82F-F13CD1E97A5A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B52264D0-E67C-407E-9F34-228E8929C5BB} | ||
EndGlobalSection | ||
EndGlobal |
20 changes: 20 additions & 0 deletions
20
JakubJares/C# ecosystem intro/MySolution/TestProject1/TestProject1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
JakubJares/C# ecosystem intro/MySolution/TestProject1/UnitTest1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using ClassLibrary1; | ||
using System; | ||
using Xunit; | ||
|
||
namespace TestProject1 | ||
{ | ||
public class UnitTest1 | ||
{ | ||
[Fact] | ||
public void AddingTwoEmojisAddsThemToASingleEmojiObject() | ||
{ | ||
// -- arrange | ||
var math = new EmojiMath(); | ||
var avocado = new Emoji { Name = "avocado", Glyph = "🥑", }; | ||
var unicorn = new Emoji { Name = "unicorn", Glyph = "🦄" }; | ||
|
||
var expected = new Emoji { Name = "avocado+unicorn", Glyph = "🥑🦄" }; | ||
|
||
// -- act | ||
var actual = math.Add(avocado, unicorn); | ||
|
||
// -- assert | ||
Assert.Equal(expected.Name, actual.Name); | ||
Assert.Equal(expected.Glyph, actual.Glyph); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file added
BIN
+1.52 MB
JakubJares/Make your scripts faster with Profiler/Profiler-psconfeu2022.pdf
Binary file not shown.
67 changes: 67 additions & 0 deletions
67
JakubJares/Make your scripts faster with Profiler/code/demo1/Avocado.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function Get-Avocado { | ||
Get-EmojiInternal -Emoji avocado | ||
} | ||
|
||
function Get-Unicorn { | ||
Get-EmojiInternal -Emoji unicorn | ||
} | ||
|
||
Export-ModuleMember -Function Get-Avocado, Get-Unicorn | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
function Get-EmojiInternal ($Emoji) { | ||
$ProgressPreference = 'SilentlyContinue' | ||
|
||
$uri = "https://emojipedia.org/$($Emoji.ToLowerInvariant())/" | ||
$r = Invoke-WebRequest -Method GET -Uri $uri -UseBasicParsing | ||
if (200 -ne $r.StatusCode) { | ||
throw "Error" | ||
} | ||
|
||
$match = $r.Content.ToString() -split "`n" | Select-String '<h1><span\s+class="emoji">(.*)</span>' | ||
$emoji = $match.Matches.Groups[-1].Value | ||
$emoji * 50 | ||
} |
8 changes: 8 additions & 0 deletions
8
JakubJares/Make your scripts faster with Profiler/code/demo1/Get-Icons.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Import-Module $PSScriptRoot\Avocado.psm1 -Force | ||
|
||
function Get-Icons () { | ||
Get-Avocado | ||
Get-Unicorn | ||
} | ||
|
||
Get-Icons |
9 changes: 9 additions & 0 deletions
9
JakubJares/Make your scripts faster with Profiler/code/demo1/Trace.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Import-Module Profiler | ||
|
||
$trace = Trace-Script -ScriptBlock { | ||
& "$PSScriptRoot/Get-Icons.ps1" | ||
} -ExportPath emojis.speedscope.json | ||
|
||
$trace.Top50SelfDuration | | ||
Select-Object -First 5 | | ||
Format-Table SelfPercent, SelfDuration, HitCount, File, Line, Module, Function, Text |
1 change: 1 addition & 0 deletions
1
JakubJares/Make your scripts faster with Profiler/code/demo2/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.speedscope.json |
69 changes: 69 additions & 0 deletions
69
JakubJares/Make your scripts faster with Profiler/code/demo2/Get-UserData-no-annotations.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function Get-UserData { | ||
param ( | ||
[Parameter(Mandatory)] | ||
$Path | ||
) | ||
|
||
$users = Get-Content -Path $Path -Encoding UTF8 | ConvertFrom-Json | ||
|
||
$users | Foreach-Object { | ||
$user = $_ | ||
|
||
$completeUser = [PSCustomObject]@{ | ||
Name = $_.name | ||
Age = $_.age | ||
Languages = @{} | ||
} | ||
|
||
$user.languages | ForEach-Object { | ||
$language = $_ | ||
$languageDescription = $null | ||
$languagePath = Join-Path $PSScriptRoot "$language.json" | ||
$languageDescription = (Get-Content -Path $languagePath | ConvertFrom-Json).description | ||
$completeUser.Languages[$language] = $languageDescription | ||
} | ||
|
||
$completeUser.Languages = [PSCustomObject]$completeUser.Languages | ||
|
||
Write-Log -Message "Processed user $($_.name)" -Level "Verbose" | ||
|
||
$completeUser | ||
} | ||
} | ||
|
||
$script:LogLevel = "Error" | ||
|
||
function Set-LogLevel { | ||
param( | ||
[Parameter(Mandatory)] | ||
$Level | ||
) | ||
$script:LogLevel = $Level | ||
$script:IsVerboseEnabled = (Get-LogLevelNumber $Level) -le (Get-LogLevelNumber "Verbose") | ||
# etc... | ||
} | ||
|
||
function Get-LogLevelNumber { | ||
param( | ||
[Parameter(Mandatory)] | ||
$Level | ||
) | ||
|
||
switch ($Level) { | ||
"error" { 1 } | ||
"info" { 2 } | ||
"verbose" { 3 } | ||
} | ||
} | ||
|
||
function Write-Log { | ||
param( | ||
[Parameter(Mandatory)] | ||
$Message, | ||
$Level = "Info" | ||
) | ||
|
||
if ((Get-LogLevelNumber $Level) -le (Get-LogLevelNumber $script:LogLevel)) { | ||
Write-Host $Message | ||
} | ||
} |
Oops, something went wrong.