Skip to content

Instantly share code, notes, and snippets.

@mostlylikeable
mostlylikeable / test_sftp_connection.groovy
Created September 27, 2018 15:25
test sftp connection
@Grab(group='com.jcraft', module='jsch', version='0.1.46')
import com.jcraft.jsch.*
java.util.Properties config = new java.util.Properties()
config.StrictHostKeyChecking = "no"
JSch ssh = new JSch()
Session session = ssh.getSession(user, host, port)
session.config = config
// match html class
class=\"(footer|.+ footer)( |\")
@mostlylikeable
mostlylikeable / AtomicCyclicCounter.groovy
Created February 14, 2018 14:34
AtomicCyclicCounter
import java.util.concurrent.atomic.AtomicInteger
/**
* A cyclic counter that is backed by an {@code AtomicInteger}.
*
* This counter will return integers starting at {@code start} up to {@code max}, then starting over (cycling).
*/
class AtomicCyclicCounter {
int max
int start = 1
@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}"
}
}
@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 / 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 / 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 / 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 / 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 / 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)