Skip to content

Commit

Permalink
Add Jakub Jares sources (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Jun 25, 2022
1 parent 8102edc commit 2937661
Show file tree
Hide file tree
Showing 35 changed files with 102,050 additions and 0 deletions.
454 changes: 454 additions & 0 deletions JakubJares/C# ecosystem intro/MySolution/.gitignore

Large diffs are not rendered by default.

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>
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; } // 🥑
}
}
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;
}
}
}
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 JakubJares/C# ecosystem intro/MySolution/ConsoleApp1/Program.cs
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();
}
}
}
37 changes: 37 additions & 0 deletions JakubJares/C# ecosystem intro/MySolution/MySolution.sln
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
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 JakubJares/C# ecosystem intro/MySolution/TestProject1/UnitTest1.cs
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 added JakubJares/C# ecosystem intro/code.zip
Binary file not shown.
Binary file not shown.
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
}
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.speedscope.json
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
}
}
Loading

0 comments on commit 2937661

Please sign in to comment.