Skip to content

Commit

Permalink
Random Components.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Sep 5, 2024
1 parent 4b1a131 commit a385776
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Misc/Random.Apps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Random Components

Components for dealing with randomization.

## Components

### `New-UDRandom`

Displays a card that allows for generating different types of random data. This includes:

- Password
- Number
- GUID
- Powerball Numbers

![Weather Card](https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/Misc/Random.Apps.png)
22 changes: 22 additions & 0 deletions Misc/Random.Apps/Random.Apps.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@{
RootModule = 'Random.Apps.psm1'
ModuleVersion = '1.0.0'
GUID = '36bc5153-97b0-4447-8b45-64b0cb31213d'
Author = 'Ironman Software'
CompanyName = 'Ironman Software'
Copyright = '(c) Ironman Software. All rights reserved.'
Description = 'Random tools for apps.'
FunctionsToExport = @(
'New-UDRandom'
)

PrivateData = @{
PSData = @{
Tags = @('app', 'random')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Random.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
}
}
}

118 changes: 118 additions & 0 deletions Misc/Random.Apps/Random.Apps.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
function New-UDRandomPassword {
param(
[int]$Length = 12,
[switch]$IncludeUppercase,
[switch]$IncludeLowercase,
[switch]$IncludeNumbers,
[switch]$IncludeSpecialCharacters
)

$Characters = @()
if ($IncludeUppercase) {
$Characters += 65..90 | ForEach-Object { [char]$_ }
}
if ($IncludeLowercase) {
$Characters += 97..122 | ForEach-Object { [char]$_ }
}
if ($IncludeNumbers) {
$Characters += 48..57 | ForEach-Object { [char]$_ }
}
if ($IncludeSpecialCharacters) {
$Characters += 33..47 | ForEach-Object { [char]$_ }
$Characters += 58..64 | ForEach-Object { [char]$_ }
$Characters += 91..96 | ForEach-Object { [char]$_ }
$Characters += 123..126 | ForEach-Object { [char]$_ }
}

$Password = ""
for ($i = 0; $i -lt $Length; $i++) {
$Password += $Characters | Get-Random
}

$Password
}

function New-UDRandomPowerballNumbers {
$Numbers = 1..69 | Get-Random -Count 5
$Powerball = 1..26 | Get-Random
$Numbers + $Powerball
}

function New-UDRandom {
param(
[Parameter()]
[string[]]$Tools = @("Password", "GUID", "Number", "ListItem", "Powerball")
)

New-UDForm -Content {
if ($Tools.Length -gt 1) {
New-UDSelect -Label "Tool" -Option {
$Tools | ForEach-Object {
New-UDSelectOption -Name $_ -Value $_ -Id -OnChange {
$Page:Tool = $EventData
}
}
}
}
else {
$Page:Tool = $Tools[0]
}

if ($Page:Tool -eq "Password") {
New-UDSlider -Label "Length" -Id "Length" -DefaultValue 12 -Min 4 -Max 128
New-UDCheckbox -Label "Include Uppercase" -Id "IncludeUppercase"
New-UDCheckbox -Label "Include Lowercase" -Id "IncludeLowercase"
New-UDCheckbox -Label "Include Numbers" -Id "IncludeNumbers"
New-UDCheckbox -Label "Include Special Characters" -Id "IncludeSpecialCharacters"
}
elseif ($Page:Tool -eq "Number") {
New-UDSlider -Label "Minimum" -Id "Minimum" -DefaultValue 0 -Min 0 -Max 10000
New-UDSlider -Label "Maximum" -Id "Maximum" -DefaultValue 100 -Min 0 -Max 10000
}
elseif ($Page:Tool -eq "ListItem") {
New-UDTextarea -Label "Items" -Id "Items"
}

} -OnSubmit {
if ($Page:Tool -eq "Password") {
$Page:Password = New-UDRandomPassword -Length $EventData.Length -IncludeUppercase:$EventData.IncludeUppercase -IncludeLowercaseL$EventData.IncludeLowercase -IncludeNumbers $EventData.IncludeNumbers -IncludeSpecialCharacters $EventData.IncludeSpecialCharacters
}
elseif ($Page:Tool -eq "GUID") {
$Page:Guid = New-Guid
}
elseif ($Page:Tool -eq "Number") {
$Page:Number = Get-Random -Minimum $EventData.Minimum -Maximum $EventData.Maximum
}
elseif ($Page:Tool -eq "ListItem") {
$Page:Items = $EventData.Items -split "`n"
$Page:Item = $Page:Items | Get-Random
}
elseif ($Page:Tool -eq "Powerball") {
$Page:Powerball = New-UDRandomPowerballNumbers
}
Sync-UDElement -Id "Output"
}

New-UDDynamic -Id "Output" -Content {
New-UDCard -Title 'Output' -Content {
if ($Page:Tool -eq "Password") {
New-UDTypography -Text $Page:Password
}
elseif ($Page:Tool -eq "GUID") {
New-UDTypography -Text $Page:Guid
}
elseif ($Page:Tool -eq "Number") {
New-UDTypography -Text $Page:Number
}
elseif ($Page:Tool -eq "ListItem") {
New-UDTypography -Text $Page:Item
}
elseif ($Page:Tool -eq "Powerball") {
$Page:Powerball | Select-Object -First 5 | ForEach-Object {
New-UDBadge -Text $_
}
New-UDBadge -Text $Page:Powerball[-1] -BackgroundColor "red"
}
}
}
}
9 changes: 4 additions & 5 deletions Misc/Weather.Apps/Weather.Apps.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

PrivateData = @{
PSData = @{
Tags = @('app', 'weather')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Weather.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
DisplayName = 'PowerShell Scripts'
Tags = @('app', 'weather')
LicenseUri = 'https://github.com/ironmansoftware/scripts/blob/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/Misc/Weather.Apps'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/app.png'
}
}
}
Expand Down
Binary file added images/Misc/Random.Apps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a385776

Please sign in to comment.