Skip to content

Instantly share code, notes, and snippets.

View marcgeld's full-sized avatar

Marcus Gelderman marcgeld

View GitHub Profile
@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 / 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 / numberToNumbers.scpt
Last active December 7, 2022 16:19
A jxa script to create a spreadsheet in Apple numbers
let numbers = Application('Numbers')
numbers.includeStandardAdditions = true
numbers.activate()
delay(1)
SystemEvents = Application('System Events')
Notes = SystemEvents.processes['Numbers']
let jsonStr = "[{\"datum\":\"26 januari 2018 16:28\",\"biljett\":\"Enkelbiljett\",\"pris\":\"39,00\",\"moms\":\"2,21\",\"total\":\"39,00\"},{\"datum\":\"24 januari 2018 17:09\",\"biljett\":\"Enkelbiljett\",\"pris\":\"39,00\",\"moms\":\"2,21\",\"total\":\"39,00\"},{\"datum\":\"20 januari 2018 16:14\",\"biljett\":\"Enkelbiljett\",\"pris\":\"47,00\",\"moms\":\"2,66\",\"total\":\"47,00\"},{\"datum\":\"14 januari 2018 02:17\",\"biljett\":\"Enkelbiljett\",\"pris\":\"27,00\",\"moms\":\"1,53\",\"total\":\"27,00\"},{\"datum\":\"13 januari 2018 18:06\",\"biljett\":\"Enkelbiljett\",\"pris\":\"27,00\",\"moms\":\"1,53\",\"total\":\"27,00\"},{\"datum\":\"22 december 2017 14:22\",\"biljett\":\"Enkelbiljett\",\"pris\":\"46,00\",\"moms\":\"2,60\",\"total\":\"46,00\"},{\"datum\":\"21 december 2017 17:20\",\"biljett\":\"Enkelbiljett\",\"pr
@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 [email protected]. Create json output with extracted information.
//debugger;
'use strict';
var mailboxName = '[email protected]'
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();
@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…'
}
@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 / 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 / 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 / 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.
*/