Skip to content

Instantly share code, notes, and snippets.

View sheldonhull's full-sized avatar
👋
Hi! Who keeps their github status up to date? You get a 🌮 just for reading this

sheldonhull sheldonhull

👋
Hi! Who keeps their github status up to date? You get a 🌮 just for reading this
View GitHub Profile
@sheldonhull
sheldonhull / aws-for-each-region.ps1
Last active February 13, 2021 00:26
[aws-powershell-cheatsheet] Quick snippets and tips for working with AWS SDK specifically in PowerShell #powershell #aws
# How To Loop Through Regions
$RegionExclusions = @(
'eu-south-1'
'ap-east-1'
'us-isob-east-1'
'us-iso-east-1'
'af-south-1'
'me-south-1'
)
(Get-AWSRegion -ErrorAction SilentlyContinue).Region | Where-Object { $_ -notin $RegionExclusions } | ForEach-Object {
@sheldonhull
sheldonhull / psteams-adaptive-cards.ps1
Created January 23, 2021 01:37
[powershell-cheatsheet] quick snippets and cheats to get moving quickly #powershell
‎‎​
@sheldonhull
sheldonhull / README.md
Last active February 12, 2021 00:19
[Dbatools Restoring Directory] Use dbatools on PowerShell 4.0 system to allow restoring a directory #dbatools #powershell

Overview

Normally, you'd just install dbatools and go, or at least use the GitHub installer script. However, if you have to deal with an older system that might be on PowerShell 4 for example, missing things like PowerShellGet, I found this useful to work through the problem and have handy for a future issue.

The key is that several features and modules aren't available in this older version.

Post fix, if you run into this more than a rare while, update your SQL Servers!

Restoring

@sheldonhull
sheldonhull / README.md
Last active January 22, 2021 01:34
[Install S5Cmd With PowerShell 4.0 Support] How to install s5cmd without all the magical tools like PowerShell Get #powershell #s3 #aws

Get S5Cmd

Older versions of PowerShell (4.0) and the older AWSTools don't have the required ability to sync down a folder from a key prefix. This also performs much more quickly for a quick sync of files like backups to a local directory for initiating restores against.

In testing down by the tool creator, they showed this could saturate a network for an EC2 with full download speed and be up to 40x faster than using CLI with the benefit of being a small self-contained Go binary as well.

Once the download of the tooling is complete you can run a copy from s3 down to a local directory by doing something similar to this, assuming you have rights to the bucket. If you don't have rights, you'll want to set environment variables for the access key and secret key such as:

@sheldonhull
sheldonhull / aws-s3-lifecycle-policy-creation.ps1
Last active February 2, 2021 23:43
[AWS SDK PowerShell creating an S3 Lifecycle Policy] Supporting blog post www.sheldonhull.com/blog/create-an-s3-lifecycle-policy-with-powershell #blog #powershell #aws
Import-Module AWS.Tools.S3
Set-AWSCredential -ProfileName foo
$Region = 'eu-west-1'
$TargetBucket = 'my-big-bucket'
$Prefix = @(
'keyprefix1'
'keyprefix2'
'keyprefix3'
)
$Rules = @()
@sheldonhull
sheldonhull / azure-pipelines.renovate.yml
Last active June 30, 2021 20:17
[renovate configuration json] How to configure json for renovate automerge with GitHub for pull request workflow #devops
---
name: renovate-$(Build.Reason)-$(SourceBranchName)-$(Date:yyyyMMdd)-$(Rev:.r)
pool:
name: Azure Pipelines
vmImage: ubuntu-latest
trigger: none
schedules:
- cron: 0 07 * * Mon,Wed,Fri # Build every Monday, Wednesday, and Friday at 7am
displayName: MonWedFri7am # friendly name given to a specific schedule
@sheldonhull
sheldonhull / gist-testing.md
Created January 13, 2021 04:48
Testing Hugo Parsing of Gist Content

H2

This is a section

H3

This is another section with profound thoughts

@sheldonhull
sheldonhull / README.asciidoc
Last active January 5, 2021 19:55
[Algos - Puzzles] Team Formation - Beginning of challenge, not submitted in time and couldn't find problem statement to finish later #go

Follow-Up on Team Formation Challenge

I’m new to algorithm based challenges and only started picking them up this last week or so, as my background has been focused on set based/database work and "DevOps" work related to AWS, automation, experiments with serverless and so on.

Hopefully as you look through this keep this in mind, as I did a little limited prep with a language that I’m still learning during the holidays.

This is what I was working on until I ran out of time and wasn’t able to finish up and work on the selection fixes, so figured I’d demonstrate it at least.

I also did a blog post Experiments With Go Arrays and Slices on what I learned about how Go handles arrays and slices (and was featured in SQLServerCentral newsletter for this 🎉).

@sheldonhull
sheldonhull / counting_valleys.go
Last active December 27, 2020 20:36
[Algos - Counting Valleys] How to count valleys #hackerrank #go #golang #algorithms #puzzles
// my submission for Counting Valley on Hackerrank
// https://www.hackerrank.com/challenges/counting-valleys/submissions/code/193156571
package algo
import (
// "bufio"
// "fmt"
// "io"
// "os"
// "strconv"
@sheldonhull
sheldonhull / sock_merchant.go
Last active December 27, 2020 01:42
[Algos - Sock Merchant] Return matching pairs of socks #algorithms #go #puzzles #golang
// Hackerrank submission for https://www.hackerrank.com/challenges/sock-merchant/submissions/code/193045923
// Complete the sockMerchant function below.
func sockMerchant(n int, ar []int) int {
// possiblePairs := int(math.Floor(float64(n) / 2))
sort.Slice(ar, func(i, j int) bool { return ar[i] < ar[j] })
// sort.Sort(byValue(ar))
var currentPairMatched int = 0
// size := len(ar)