Skip to content

Instantly share code, notes, and snippets.

View rdbartram's full-sized avatar

Ryan Bartram rdbartram

View GitHub Profile
@rdbartram
rdbartram / code-golf-PowerShell.ps1
Last active June 4, 2020 13:05
My attempts at Code-Golf.io in PowerShell
# 12 days of christmas
$i=0;while($i-lt12){$f="On the $(("First;Second;Third;Fourth;Fifth;Sixth;Seventh;Eighth;Ninth;Tenth;Eleventh;Twelfth"-split";")[$i]) day of Christmas;My true love sent to me;A Partridge in a Pear Tree.;Two Turtle Doves;Three French Hens,;Four Calling Birds,;Five Gold Rings,;Six Geese-a-Laying,;Seven Swans-a-Swimming,;Eight Maids-a-Milking,;Nine Ladies Dancing,;Ten Lords-a-Leaping,;Eleven Pipers Piping,;Twelve Drummers Drumming,"-split";";$a=$f[0,1]+$f[$(2+$i)..2];$a[-2]=$i++ ?$a[-2]+', and':$a[-2];$a+''|write-host}
# fizzbuzz
1..100|%{($_%3?$^:'Fizz')+($_%5?$^:'Buzz')??$_}|write-host
# seven segment
$n=$args;1..3|%{$l=$_;$o="";$n.ToCharArray()|%{$o+=('{"1":{"1":" ","2":" |","3":" |"},"2":{"1":" _ ","2":" _|","3":"|_ "},"3":{"1":" _ ","2":" _|","3":" _|"},"4":{"1":" ","2":"|_|","3":" |"},"5":{"1":" _ ","2":"|_ ","3":" _|"},"6":{"1":" _ ","2":"|_ ","3":"|_|"},"7":{"1":" _ ","2":" |","3":" |"},"8":{"1":" _ ","2":"|_|","3":"|_|"},"9":{"1":" _ ","2":"|_|","3":" _|"},"0":{"1":" _ ","
Describe 'Get-PodcastImage' {
BeforeAll {
. $PSScriptRoot\function-Get-PodcastImage.ps1
$TestData = (Get-Content $PSScriptRoot\ObjectMother\RSSData.json -Raw | ConvertFrom-Json) | ForEach-Object {
@{
Data = $_
ImageURL = $_.ImageURL
Exist = [int][bool]($i++ % 2) # makes odd indexes return false for exist
@rdbartram
rdbartram / devops_WorkstationInstall.ps1
Created July 3, 2018 06:06
Script to install my machine back to working state. Apps, Configs etc
$ProgressPreference = "SilentlyContinue"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Enable WinRM
Enable-PSRemoting -Force -SkipNetworkProfileCheck
# Install PowerShell
if (-not (Invoke-DscResource -Name Package -ModuleName PSDesiredStateConfiguration -Method Test -Property @{ Ensure = "Present"; Path = "$env:temp\powershell.msi"; Name = "PowerShell 6-preview-x64"; ProductID = '' })) {
Write-Verbose "Installing latest version of PowerShell" -Verbose
$LatestRelease = irm https://api.github.com/repos/powershell/powershell/releases/latest
# Import module from previous step
Import-Module -Name posh-git
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
@rdbartram
rdbartram / settings.json
Created May 14, 2018 08:18
Generic PowerShell development settings for vscode
{
"files.trimTrailingWhitespace": true,
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.alignPropertyValuePairs": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.tabSize": 4,
"[json]": {
@rdbartram
rdbartram / ConvertFrom-SQLDatabaseConnectionString.ps1
Last active November 22, 2017 09:13
Accepts SQL Connection strings and converts them to and from powershell objects for easy manipulation and use
function ConvertFrom-SQLDatabaseConnectionString {
[OutputType([PSCustomObject])]
[cmdletbinding()]
param(
[Parameter(mandatory, Valuefrompipeline)]
[string]
$ConnectionString
)
begin {
@rdbartram
rdbartram / Get-PreviousWorkday.ps1
Created July 28, 2017 11:38
Get workday x days ago
function Get-PreviousWorkday ($Days = 0) {
begin {
$date = get-date
}
process {
$i = 0
do {
$date = $date.adddays(-1)
if ($date.DayOfWeek -match '^[^s]') {
$i++