Skip to content

Instantly share code, notes, and snippets.

View mcquinne's full-sized avatar

Evan McQuinn mcquinne

  • CIRES + NCEI
  • Denver, CO
View GitHub Profile
@mcquinne
mcquinne / skyrockets.groovy
Last active August 29, 2015 14:00
afternoon delight!
#!/usr/bin/env groovy
def rocketParts = [
' /\\',
'/ \\',
' ||',
' ||',
' ||',
' ||',
' ||',
@mcquinne
mcquinne / gist:6382095
Created August 29, 2013 19:03
Add a "print<PropertyName>" rule to Gradle projects to easily print project property values
/**
* Put in an init script, e.g.: $HOME/.gradle/init.d/printProperties.gradle
* Then call from a gradle project, e.g.: gradle printVersion
*/
allprojects { Project project ->
tasks.addRule( "print<PropertyName> - print the value of a property in this and any subprojects" ) { String taskName ->
if ( taskName.startsWith( "print" ) ) {
def propName = (taskName - 'print')
propName = propName[0].toLowerCase() + propName[1..-1]
task( taskName ) << { println "${propName}: ${project.properties[propName]}" }
@mcquinne
mcquinne / updateRemotes.sh
Created June 12, 2017 23:08
Update the URLs for a given remote name in all git repos under the PWD
#!/bin/bash
if [[ $# -ne 3 ]]; then
echo "Finds and replaces patterns in remote URLs for all git repos under the PWD"
echo " Usage:"
echo " $0 remote_name old_pattern new_pattern"
echo " Example:"
echo " $0 origin myoldorg myneworg"
echo " Would find git repos under the PWD with 'myoldorg' in their URLs for"
echo " their origin remotes, and replace 'myoldorg' with 'myneworg' in each URL"
@mcquinne
mcquinne / md5.groovy
Created May 10, 2012 20:46 — forked from ikarius/md5.groovy
Generate MD5 hash of a file while being as Groovy as possible.
def generateMD5( File file ) {
def digest = java.security.MessageDigest.getInstance("MD5")
file.eachByte( 4096 ) { buffer, length ->
digest.update( buffer, 0, length )
}
new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
}
@mcquinne
mcquinne / roundToMultiple.groovy
Created April 30, 2012 18:10
Round a number to a multiple of another number, optionally altering the rounding technique used.
import static java.math.RoundingMode.*
import java.math.RoundingMode
/*
To round to a multiple:
1) normalize the input by dividing it by the multiple value.
2) round it to the nearest integer using the desired rounding technique
3) multiply that integer by the multiple value to produce the result
NOTES:
@mcquinne
mcquinne / GStringJsonSerializer.groovy
Last active May 2, 2022 20:35
Spring Jackson JSON serializer for Groovy GStrings
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
@Component