Skip to content

Instantly share code, notes, and snippets.

View namuan's full-sized avatar
🎯
Focusing

namuan namuan

🎯
Focusing
View GitHub Profile
@namuan
namuan / gist:6329179
Last active December 21, 2015 15:49
Push JMeter reports to elastic search
Start elastic search
./bin/elasticsearch -f
Start logstash
Logstash configuration to process JMeter data
$ cat dlogs.conf
input {
stdin {
@namuan
namuan / spark.groovy
Created August 27, 2013 10:29
Groovy micro web framework
@GrabExclude(group='org.eclipse.jetty.orbit', module='javax.servlet', version='3.0.0.v201112011016')
@Grapes([
@Grab('org.eclipse.jetty.aggregate:jetty-server:8.1.2.v20120308'),
@Grab('org.eclipse.jetty.aggregate:jetty-servlet:8.1.2.v20120308'),
@Grab(group='javax.servlet', module='javax.servlet-api', version='3.0.1'),
@Grab(group='org.eclipse.jetty', module='jetty-server', version='9.0.4.v20130625'),
@Grab(group='com.sparkjava', module='spark-core', version='1.0')
])
@namuan
namuan / mixins.groovy
Created August 27, 2013 10:30
Mixins and Category in groovy
class Foo {
def fooMethod(String message) {
println "fooMethod: ${message}"
}
}
class Bar {
def barMethod(String message) {
println "barMethod: ${message}"
@namuan
namuan / switchMaps.groovy
Created August 27, 2013 10:31
Replace switch-case/if-else block with maps
def sum(a, b) {
println "sum"
a + b
}
def sub(a, b) {
println "sub"
a - b
}
@namuan
namuan / build.gradle
Last active December 23, 2015 02:59 — forked from Dierk/build.gradle
apply plugin:'groovy'
apply plugin:'idea'
apply plugin:'application'
apply plugin: 'shadow'
buildscript {
repositories {
maven {
name 'Shadow'
url 'http://dl.bintray.com/content/johnrengelman/gradle-plugins'
@namuan
namuan / groovyClosureUtils.groovy
Created September 18, 2013 12:41
Groovy return () if (condition)
def doSomething() {
"Doing something"
}
def ret(Closure c) {
[if: { condition ->
if (condition) c()
}]
}
@namuan
namuan / groovyFindAnnotation
Created October 25, 2013 14:04
Find annotation of groovy class fields
ApiCampaign a = new ApiCampaign()
a.properties.each { property ->
a.class.declaredFields.find { field ->
if (field.name == property.key && SupportedApiVersion in field.declaredAnnotations*.annotationType()) {
def parameter = field.getAnnotation(SupportedApiVersion)
println "Property with name " + property.key + " with parameter " + parameter.atLeast()
}
@GrabExclude(group='org.eclipse.jetty.orbit', module='javax.servlet', version='3.0.0.v201112011016')
@Grapes([
@Grab(group='dbunit', module='dbunit', version='2.2'),
@Grab(group='mysql', module='mysql-connector-java', version='5.1.26')
])
@GrabConfig(systemClassLoader=true)
import java.io.FileOutputStream
@namuan
namuan / convertNumberToWords.groovy
Created January 15, 2014 10:48
Convert number to words
@Grapes(
@Grab(group='com.ibm.icu', module='icu4j', version='52.1')
)
import com.ibm.icu.text.*
import java.util.Locale
import com.ibm.icu.text.RuleBasedNumberFormat
public String spellOut(num) {
NumberFormat formatter = new RuleBasedNumberFormat(RuleBasedNumberFormat.SPELLOUT)
@namuan
namuan / change grails version
Created April 29, 2014 16:08
Change grails version using gvm and overriding cd command
cd() {
if [[ -e application.properties ]];
then
$(cat application.properties | grep app.grails.version | awk -F= '{print "gvm use grails " $2}')
fi
}