Skip to content

Instantly share code, notes, and snippets.

View marcgeld's full-sized avatar

Marcus Gelderman marcgeld

View GitHub Profile
@marcgeld
marcgeld / arrays.groovy
Created November 23, 2016 11:48
Hackerrank: Day 7: Arrays.groovy
/*
Objective
Today, we're learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given an array of integers, print 's elements in reverse order as a single line of space-separated numbers.
Input Format
@marcgeld
marcgeld / hackerrankDictionariesMaps.groovy
Last active April 5, 2017 09:31
Groovy: Hackerrank: Day 8: Dictionaries and Maps.groovy
/*
Objective
Today, we're learning about Key-Value pair mappings using a Map or Dictionary data structure. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for is not found, print Not found instead.
Note: Your phone book should be a Dictionary/Map/HashMap data structure.
@marcgeld
marcgeld / psCollectionsHashtable.ps1
Last active June 22, 2017 19:11
Powershell Collections HashTables (Dictionaries)
# PowerShell Collections HashTables (Dictionaries)
[Hashtable] $firstTable = @{
mykey = "myvalue"
label = "value"
akey = ”cat”
someOtherKey = "dog"
intValueKey = 123
}
@marcgeld
marcgeld / psHashcodeFromByteArray.ps1
Last active June 22, 2017 19:11
Powershell: Calculate Hashcode from byteArray
# Calculate Hashcode from byteArray
function Get-HashcodeFromByteArray {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[byte[]] $byteArray = $(Throw("-byteArray is required")),
[ValidateSet("sha256","md5")]
[string]$algorithm=("sha256")
@marcgeld
marcgeld / psCompress.ps1
Last active April 11, 2023 09:11
Powershell: Compress and decompress byte array
# Compress and decompress byte array
function Get-CompressedByteArray {
[CmdletBinding()]
Param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[byte[]] $byteArray = $(Throw("-byteArray is required"))
)
Process {
@marcgeld
marcgeld / psCreateXml.ps1
Last active April 5, 2017 09:28
Powershell: Create and print xml document
# Create and print xml document
[System.Xml.XmlDocument] $xml =
@'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<a><b><c><d text="Hello" /> </c></b></a>
<a><b><c><d text=" " /> </c></b></a>
<a><b><c><d text="World" /> </c></b></a>
</root>
@marcgeld
marcgeld / psDateFormat.ps1
Last active April 5, 2017 09:28
Powershell: Date format
# Date format
Write-Host "Date: "( Get-Date -f 'yyyy-MM-dd HH:mm:ss' | Out-String )
Write-Host "Date: "( Get-Date -f 'dddd dd MMMM yyyy HH:mm' | Out-String )
@marcgeld
marcgeld / psBase64.ps1
Created April 5, 2017 09:27
Powershell: base64 encode / decode
# base64 encode / decode
$bytes = [System.Text.Encoding]::UTF8.GetBytes( "Write-Host Hello World")
$base64 = [Convert]::ToBase64String( $bytes )
Write-Host "Base64 encoded: "( $base64 )
$base64Decoded = [Convert]::FromBase64String( $base64 )
Write-Host "Base64 decoded: "( $base64Decoded )
$decodedText = [System.Text.Encoding]::UTF8.GetString( $base64Decoded )
@marcgeld
marcgeld / psGetHashKeyVal.ps1
Created April 5, 2017 11:43
Powershell: Hashtable
# Hashtable
[Hashtable] $hTable = @{
mykey = "myvalue"
}
Write-Host "Table: " ( $hTable | Format-Table | Out-String )
#Write-Host "Enumerator: " ( | Format-Table | Out-String )
@marcgeld
marcgeld / psRandomAlphaNumeric.ps1
Created April 5, 2017 13:05
Powershell: Generate a random Alphanumeric string
# Generate a random Alphanumeric string
Function Get-RandomAlphanumericString {
[CmdletBinding()]
Param (
[int] $length = 8
)
Begin{