Skip to content

Instantly share code, notes, and snippets.

Matthew Adams matthewadams

Block or report user

Report or block matthewadams

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@matthewadams
matthewadams / rmdirs.groovy
Created May 2, 2013
Closure to remove an entire directory tree.
View rmdirs.groovy
rmdirs = {
it = (it instanceof File) ? it : new File(it)
if (!it.exists()) return
it.eachDir(delDir)
it.eachFile { it.delete() }
it.delete()
}
@matthewadams
matthewadams / slf4jScriptLogging.groovy
Created May 2, 2013
Convenient logback/slf4j logging closures for Groovy script authors.
View slf4jScriptLogging.groovy
@Grab(group='ch.qos.logback', module='logback-classic', version='[1.0.9,)')
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.Level
logger = LoggerFactory.getLogger("yourScript") // or whatever
logger.level = Level.INFO // or whatever
log = { level, msg, Object... args -> logger."${level.toLowerCase()}"((msg ?: "").toString(), args) }
@matthewadams
matthewadams / jdk
Last active Dec 18, 2015
Easy JVM switcher script for Mac OS X
View jdk
#!/bin/bash
if [ ! $1 ]; then
echo "Please include desired jdk version: 1.7 or 7, 1.6 or 6, ..."
exit
fi
j7="/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home"
#j6="/Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home"
j6="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
@matthewadams
matthewadams / gist:6516544
Created Sep 10, 2013
SOM Property Methods eclipse template
View gist:6516544
public ${Type} get${UpperName}() {
return ${lowerName};
}
public void set${UpperName}(${Type} ${lowerName}) {
testSet${UpperName}(${lowerName});
doSet${UpperName}(${lowerName});
}
protected void testSet${UpperName}(${Type} ${lowerName}) {
@matthewadams
matthewadams / gist:6686305
Created Sep 24, 2013
echo sha1 to stdout on Mac OS X
View gist:6686305
hash=(`openssl sha1 $1`)
echo "${hash[1]}"
@matthewadams
matthewadams / gist:6686329
Created Sep 24, 2013
compare sha1 on Mac OS X
View gist:6686329
hash=(`openssl sha1 $1`)
hash=${hash[1]}
if [ "$2" != "$hash" ]; then
echo "Mismatch: given $2, calculated $hash" > /dev/stderr
exit 1
else
echo "ok"
fi
@matthewadams
matthewadams / Spark aggregateByKey
Last active Mar 11, 2016 — forked from tmcgrath/Spark aggregateByKey
Spark aggregateByKey example
View Spark aggregateByKey
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 1.1.0
/_/
Using Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65)
Type in expressions to have them evaluated.
Type :help for more information.
@matthewadams
matthewadams / git-scrum.sh
Last active Jun 6, 2017
git log for scrum across multiple repos
View git-scrum.sh
#!/usr/bin/env bash
SCRUM_TIME=${SCRUM_TIME-"08:45:00"}
BEFORE_DAY=${BEFORE_DAY-$(date +%Y-%m-%d)}
BEFORE_TIME=${BEFORE_TIME-$SCRUM_TIME}
AFTER_DAY=${AFTER_DAY-$(python -c "from datetime import datetime, timedelta; before = datetime.strptime('$BEFORE_DAY','%Y-%m-%d').date(); monday = before.strftime('%u') == '1'; days = -3 if monday else -1; after = before + timedelta(days=days); print after;")}
AFTER_TIME=${AFTER_TIME-$BEFORE_TIME}
TZ_OFFSET=$(date +%z)
AFTER="${AFTER_DAY}T${AFTER_TIME}${TZ_OFFSET}"
BEFORE="${BEFORE_DAY}T${BEFORE_TIME}${TZ_OFFSET}"
DIR="${DIR-$PWD}"
View bash-colorized-output-functions.sh
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[1;34m'
CLEAR='\033[0;0m'
red() {
printf "${RED}$1${CLEAR}\n"
}
green() {
@matthewadams
matthewadams / _helpers.tpl
Created Feb 3, 2018
.dockercfgjson Helm template
View _helpers.tpl
{{- define "dockercfg" -}}
{{- $hostname := required "A Docker image registry hostname is required" .Values.image.registry.auth.hostname -}}
{{- $username := required "A Docker image registry username is required" .Values.image.registry.auth.username -}}
{{- $password := required "A Docker image registry password is required" .Values.image.registry.auth.password -}}
{{- $email := required "A Docker image registry email is required" .Values.image.registry.auth.email -}}
{{- $auth := printf "%s:%s" $username $password | b64enc -}}
{{- $cfg := printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" $hostname $username $password $email $auth -}}
{{- $cfg | b64enc -}}
{{- end -}}
You can’t perform that action at this time.