Skip to content

Instantly share code, notes, and snippets.

View marcgeld's full-sized avatar

Marcus Gelderman marcgeld

View GitHub Profile
@marcgeld
marcgeld / dumpJar.groovy
Created September 21, 2017 13:24
Dump classes from a jar-file.
#!/usr/bin/env groovy
import java.util.zip.ZipFile
def printelnerr = System.err.&println
def appName = this.getClass().getName()
def cli = new CliBuilder( usage:"${appName} --basedir <path_to_dir> --intersectdir <path_to_dir> " )
cli.with {
@marcgeld
marcgeld / homebridge
Created December 10, 2017 11:07 — forked from johannrichard/homebridge
Systemd Service for homebridge (http://github.com/nfarina/homebridge)
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/lib/homebridge
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
@marcgeld
marcgeld / everyDayInAYear.groovy
Created January 22, 2018 10:02
Create calendar for a year
#!/usr/bin/env groovy
def year = 2018
Calendar.metaClass.yearMonthDay {
delegate.format("yyyy-MM-dd")
}
Calendar.metaClass.weekDay {
delegate.format("EEEE")
@marcgeld
marcgeld / httpBasicAuthEncode.groovy
Last active April 3, 2019 22:39
Encodes username and password for the basic authentication header (http/https)
#!/usr/bin/env groovy
import java.nio.charset.StandardCharsets
import org.apache.commons.cli.Option
def cli = new CliBuilder( usage:"${this.getClass().getName()} --u <username> -p <password>" )
cli.with {
u( longOpt: 'user', 'username', args: 1, required: true )
p( longOpt: 'password', 'password', args: 1, required: true )
@marcgeld
marcgeld / base64encode.groovy
Created February 9, 2018 08:51
Decode and encode the first argument in args. If no args exists use the string "password"
#!/usr/bin/env groovy
import java.nio.charset.StandardCharsets
String text = ""
if ( this.args.size() > 0 ) {
text = this.args[0]
}
else {
@marcgeld
marcgeld / lonLatDistance.groovy
Created February 10, 2018 14:14
Calculates the distance between to coordinates on the earth surface.
#! /usr/bin/env groovy
class LatLng{
/*
Latitude is written before longitude. Latitude/Longitude is written with a decimal number.
Latitude is decimal number rangeing from positive to negative (north and south of the Equator)
Longitude is decimal number rangeing from positive to negative (negative is west of Greenwich and positive is eastward of Greenwich)
Latitude is the Y axis, Longitude is the X axis.
*/
@marcgeld
marcgeld / httpsPost.groovy
Created February 12, 2018 12:23
HttpPOST xml message to URL
#!/usr/bin/env groovy
import groovy.xml.XmlUtil
import javax.net.ssl.SSLSession
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLContext
import javax.net.ssl.HttpsURLConnection
import static javax.net.ssl.HttpsURLConnection.HTTP_OK
@marcgeld
marcgeld / stringsPerf.groovy
Created February 12, 2018 15:45
Micro-benchmarking in Groovy
#!/usr/bin/env groovy
@Grab(group='com.googlecode.gbench', module='gbench', version='0.4.2-groovy-2.3')
import groovyx.gbench.BenchmarkBuilder
def charGen = { String alphabet, int n ->
new Random().with {
(1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
@marcgeld
marcgeld / pdfextractor.groovy
Created September 10, 2018 12:49
Groovy script that extracts images from a pdf file.
#! /usr/bin/env groovy
//@GrabConfig(systemClassLoader=true)
@Grab(group='ch.qos.logback', module='logback-classic', version='1.2.3')
@Grab(group='org.apache.pdfbox', module='pdfbox', version='2.0.11')
@Grab(group='commons-io', module='commons-io', version='2.6')
import org.apache.pdfbox.pdfwriter.*
import org.apache.pdfbox.pdmodel.*
import org.apache.pdfbox.pdmodel.font.*
@marcgeld
marcgeld / macos_jxa_shell.sh
Created September 17, 2018 20:41
macOS: run osxscript as shell script
#!/usr/bin/env osascript -l JavaScript
function run( argv ) {
'…Your cxode here…'
}