Skip to content

Instantly share code, notes, and snippets.

View marcgeld's full-sized avatar

Marcus Gelderman marcgeld

View GitHub Profile
@marcgeld
marcgeld / ikeaTradfriCall.groovy
Last active August 4, 2017 11:21
Connect to IKEA Trådfri Gateway Device via CoAP and DTLS
#!/usr/bin/env groovy
// Keywords are:
// CoAP - Constrained Application Protocol (Internet Application Protocol for constrained devices.)
// DTLS - Datagram Transport Layer Security (Encryption for Datagram (UDP))
// IKEA Trådfri - (http://www.ikea.com/us/en/catalog/products/90353361/)
@Grapes([
@GrabConfig(systemClassLoader = true),
@Grab(group='net.straylightlabs', module='hola', version='0.2.2'),
@marcgeld
marcgeld / scanner.groovy
Last active June 13, 2017 20:03
Groovy scanner
#!/usr/bin/env groovy
print "enter number: "
System.in.eachLine() { line ->
n = line.trim().toInteger()
(1..10).each{
int res = n * it
println "${n} x ${it} = ${res}"
}
@marcgeld
marcgeld / regexJava.groovy
Created June 13, 2017 08:12
Groovy: regex & Base64
#!/usr/bin/env groovy
import java.util.Base64
import java.util.Base64.Decoder
import java.util.Base64.Encoder
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.nio.charset.StandardCharsets;
final Decoder decoder = Base64.getDecoder()
@marcgeld
marcgeld / mavenPwdDecode.groovy
Created June 8, 2017 07:12
Decodes maven passwords in configuration
#!/usr/bin/env groovy
// for logging: #!/usr/bin/env JAVA_OPTS=-Dgroovy.grape.report.downloads=true groovy
@Grab(group='commons-codec', module='commons-codec', version='1.10')
@Grab(group='org.sonatype.plexus', module='plexus-cipher', version='1.7')
import java.nio.file.Paths
import org.apache.commons.codec.binary.Base64
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher
@marcgeld
marcgeld / CompileLoad.ps1
Created May 23, 2017 11:35
Compile and load in Powershell
[string] $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
[string] $fileName = $($MyInvocation.MyCommand).ToString().Replace(".ps1", ".dll")
[string] $dllPath = Join-Path $scriptPath $fileName
Write-Host "Dll fileName: $($fileName)"
Write-Host "Dll scriptPath: $($scriptPath)"
Write-Host "Dll Path: $($dllPath)"
@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{
@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 / 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 / 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 / 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>