Skip to content

Instantly share code, notes, and snippets.

View marcgeld's full-sized avatar

Marcus Gelderman marcgeld

View GitHub Profile
@marcgeld
marcgeld / .bash_profile
Last active May 25, 2019 16:53
macOS bash_profile
export PATH="/usr/local/sbin:$PATH"
export PATH=$PATH:$M2_HOME/bin
export GROOVY_HOME=/usr/local/opt/groovy/libexec
export GOPATH="${HOME}/.go:${HOME}/devmap/go"
export PATH="$PATH:${GOPATH}/bin"
function setjdk() {
@marcgeld
marcgeld / pdfImages2MultipageTIFF.groovy
Created April 21, 2019 21:49
Extract images from a pdf file to multipage TIFF (Tesseract-ocr accepts multipage TIFF, but not a pdf file with images as input)
#!/usr/bin/env groovy
// Java 9 or later (…for the TIFF ImageIO Plugin)
@Grab(group='ch.qos.logback', module='logback-classic', version='1.2.3')
@Grab(group='org.apache.pdfbox', module='pdfbox', version='2.0.15')
@Grab(group='commons-io', module='commons-io', version='2.6')
import org.apache.pdfbox.pdfwriter.*
import org.apache.pdfbox.pdmodel.*
@marcgeld
marcgeld / springboot.groovy
Created April 16, 2019 21:44
A very simple Spring Boot Application in groovy
#!/usr/bin/env groovy
package myapp
@Grab('org.springframework:spring-context:5.1.6.RELEASE')
@Grab('org.springframework:spring-web:5.1.6.RELEASE')
@Grab('org.springframework.boot:spring-boot:2.1.4.RELEASE')
@Grab('org.springframework.boot:spring-boot-starter:2.1.4.RELEASE')
@Grab('org.springframework.boot:spring-boot-starter-webflux:2.1.4.RELEASE')
@marcgeld
marcgeld / ikeaTradfriFWCheck.groovy
Last active April 14, 2019 21:15
Pretty Print JSON (IKEA Tradfri FW Check)
#!/usr/bin/env groovy
import static groovy.json.JsonOutput.prettyPrint
println prettyPrint( new URL ("http://fw.ota.homesmart.ikea.net/feed/version_info.json").getText() )
@marcgeld
marcgeld / booleanToString.groovy
Last active April 3, 2019 22:39
boolean to string conversion (Java/Groovy)
#!/usr/bin/env groovy
Boolean TRUE = true
Boolean FALSE = false
println "Boolean true => string: '${Boolean.toString(TRUE)}'"
println "Boolean false => string: '${Boolean.toString(FALSE)}'"
println "String 'true' => string: '${Boolean.parseBoolean("true")}'"
println "String 'TRUE' => string: '${Boolean.parseBoolean("TRUE")}'"
@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 / collectionUInt8Extension.swift
Last active April 3, 2019 22:33
make a hex String from a UInt8 collection
// Array of [UInt8] to hex String extension
// let arr = [0x03, 0x00, 0x02, 0x05, 0x11, 0x25, 0xa0, 0xfe, 0xe5] as [UInt8]
// let hex = arr.hexValueString (hex is the result)
extension Collection where Element == UInt8 {
var hexValueString: String {
return map{ String(format: "0x%02x", $0) }.joined(separator: ", ")
}
}
@marcgeld
marcgeld / httpsPost.groovy
Last active March 27, 2019 15:34
Post to httpbin.org/post
#!/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 / calculate-payroll.scpt
Created September 18, 2018 20:23 — forked from reinvented/calculate-payroll.scpt
JXA Scripting of Numbers.app, using AJAX to calculate payroll deductions from a remote PHP script
Numbers = Application('Numbers');
Numbers.includeStandardAdditions = true
var table = Numbers.documents[0].sheets[0].tables[0]
var selectedRow = table.selectionRange().cells[0];
var hoursCellRow = selectedRow.row().address();
var weekEndingCell = table.ranges["B" + hoursCellRow + ":B" + hoursCellRow].cells[0];
var nameCell = table.ranges["C" + hoursCellRow + ":C" + hoursCellRow].cells[0];
@marcgeld
marcgeld / vasttrafikmail.scpt
Created September 17, 2018 20:51
jxa: Find and filter emails in macOS Mail.app from info@vasttrafik.se. Create json output with extracted information.
//debugger;
'use strict';
var mailboxName = 'your.email@here.com'
var mail = new Application("Mail")
var account = mail.accounts.whose({ name: { _contains: mailboxName } }, {ignoring: 'case'})
var mailbox = account.mailboxes.whose({ name: { _contains: 'INBOX' } }, {ignoring: 'case'})
// var messages = mail.selection();