Skip to content

Instantly share code, notes, and snippets.

@mostlylikeable
mostlylikeable / gist:6311607
Created August 22, 2013 19:20
rm to Trash function
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
@mostlylikeable
mostlylikeable / gist:7749878
Last active December 30, 2015 00:29
ssh util
import com.jcraft.jsch.Channel
import com.jcraft.jsch.ChannelSftp
import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session
import java.util.concurrent.TimeUnit
class Ssh {
JSch jsch = new JSch()
@mostlylikeable
mostlylikeable / groovy_suppress_auto_timestamp.groovy
Last active August 29, 2015 14:05
Suppress auto-timestamping in Groovy
def withAutoTimestampSuppression(entity, closure) {
toggleAutoTimestamp(entity, false)
try {
def result = closure()
return result
} finally {
toggleAutoTimestamp(entity, true)
}
}
@mostlylikeable
mostlylikeable / render_gsp_template.groovy
Created September 4, 2014 20:07
Render gsp template from file, delegating to script
import org.springframework.core.io.ByteArrayResource
def s = new File('/Users/ben/Documents/foo/index.gsp').withReader { reader ->
return reader.text
}
def resource = new ByteArrayResource(s.bytes)
def renderer = ctx.groovyPagesTemplateEngine
def template = renderer.createTemplate(resource, false)
@mostlylikeable
mostlylikeable / rm.sh
Created October 16, 2014 18:08
rm.sh
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
@mostlylikeable
mostlylikeable / vertx_debug.gradle
Created November 14, 2014 03:00
debug vertx app via gradle task
task runVertx(type: Exec, dependsOn: ['compileGroovy']) {
if (System.getProperty('debug')) {
environment 'VERTX_OPTS', '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
}
ext.vertxClasspath = (sourceSets.main.runtimeClasspath.filter { !it.path.contains('groovy') }).asPath
def configFile = 'etc/conf.json'
commandLine 'vertx', 'run', 'src/MyVertxModule.groovy', '-conf', configFile, '-cp', "src/:$vertxClasspath"
}
@mostlylikeable
mostlylikeable / kafka_consumer_test.groovy
Created April 16, 2015 16:15
Kafka Consumer Test - implements kafka examples for testing
@Grab("org.apache.kafka:kafka_2.10:0.8.1")
@GrabExclude("com.sun.jmx:jmxri")
@GrabExclude("javax.jms:jms")
@GrabExclude("com.sun.jdmk:jmxtools")
@GrabExclude("junit:junit")
import kafka.consumer.ConsumerConfig;
import kafka.consumer.ConsumerIterator;
import kafka.consumer.KafkaStream;
import kafka.javaapi.consumer.ConsumerConnector;
@mostlylikeable
mostlylikeable / embedded_spock_tests.groovy
Last active October 22, 2021 17:34
Programmatically run spock tests
package foo
@Grab('org.spockframework:spock-core:1.0-groovy-2.3')
import org.junit.runner.*
import spock.lang.Specification
import spock.util.EmbeddedSpecRunner
/*
@mostlylikeable
mostlylikeable / string_to_enum.groovy
Created June 4, 2015 20:01
Playing with reusable ways to convert String to Enum
import org.codehaus.groovy.runtime.StringGroovyMethods
use(EnumUtils1) {
println Foo.ONE.toString()
println "THREE" as Foo
println "123" as int
println "Three" as Foo
println "T" as Foo
}
@mostlylikeable
mostlylikeable / gradle_debug.groovy
Last active August 10, 2016 15:02
gradle debug on different port
// grails -debug -DFOO=bar -Djava.awt.headless=true -Dapp.context=/ run-app
run {
if (project.hasProperty('debug') && project.property('debug') == 'true') {
def debugPort = project.hasProperty('debug.port') ? project.property('debug.port') : 5005
def suspend = project.hasProperty('debug.suspend') ? project.property('debug.suspend') : 'y'
jvmArgs '-Xdebug', "-Xrunjdwp:transport=dt_socket,server=y,suspend=${suspend},address=${debugPort}"
}
}