Skip to content

Instantly share code, notes, and snippets.

View Joxebus's full-sized avatar
:octocat:
Working from home

Omar Bautista Joxebus

:octocat:
Working from home
View GitHub Profile
def sayHello = { name ->
println "Hello $name"
}
sayHello("Omar")
@Joxebus
Joxebus / ThisIsAnExample.groovy
Created November 12, 2018 23:54
Example controller groovy for Spring Boot
// app.groovy
@RestController
class ThisIsAnExample {
@RequestMapping('/')
String sayHello(){
"Hello World from Spring Boot + Groovy"
}
}
@Joxebus
Joxebus / ThisIsAnExample.groovy
Created November 12, 2018 23:56
Example controller with parameters in groovy for Spring Boot
// app.groovy
@RestController
class ThisIsAnExample {
@RequestMapping('/{name}')
String sayHello(@RequestParam(value = "name",
required = false) String name){
"Hello ${name ?: 'World'} from Spring Boot + Groovy"
}
}
@Joxebus
Joxebus / ant_builder_example.groovy
Last active April 17, 2019 21:59
Ant Builder Groovy Shell Script Example
#!/usr/bin/env groovy
version = '2.2.0'
release = '2.11-2.2.0'
url = "http://apache.claz.org/kafka/${version}/kafka_${release}.tgz"
tempDir = "/tmp/groovy_workshop"
destDir = "/Users/obautista/Documents/workspace-public/GroovyWorkshopExamples/src/main/resources/download"
def ant = new AntBuilder()
@Joxebus
Joxebus / rename_git_branch.sh
Created April 18, 2019 20:47
Rename Branch
git branch -m new-name # If you are on the branch you want to rename
git branch -m old-name new-name # If you are on a different branch
git push origin :old-name new-name # Delete the old-name remote branch and push the new-name local branch.
git push origin -u new-name # Reset the upstream branch for the new-name local branch.
@Joxebus
Joxebus / ajax_grails_3_example.html
Last active April 30, 2019 17:01
This is an example of how to define an ajax call with Grails 3
<script type="text/javascript">
$(document).ready(function(){
$("#yourId").change(function () {
$.ajax({
url: "${g.createLink(controller:'yourContrller',action:'yourAjaxAction')}",
dataType: 'json',
data: {},
success: function (data) {
alert(data)
},
@Joxebus
Joxebus / methodMissing-sample-1.groovy
Last active February 27, 2020 18:46
Method Missing 1
def methodMissing(String name, args) {
Closure closure = actions[name]
if(closure) {
closure.call(args)
} else {
throw new MissingMethodException(name, ActionExecutor.class, args)
}
}
@Joxebus
Joxebus / 1_method_missing_sample.groovy
Last active January 31, 2021 07:24
This is a sample of the Method Missing implementation for dynamic invoke closures
class MySampleClass {
Map props = [:]
def propertyMissing(String propertyName, String value) {
props[propertyName] = value
}
def propertyMissing(String propertyName) {
props[propertyName]
@Joxebus
Joxebus / copy_files.groovy
Created April 22, 2020 01:00
This is a bash script written in Groovy to copy files
#!/usr/bin/env groovy
String source = args[0]
String target = args[1]
println "Copy file [$source] into [$target]"
File sourceFile = new File(source)
new File(target).bytes = sourceFile.bytes
@Joxebus
Joxebus / cli_usage.groovy
Last active April 24, 2020 03:37
Script to generate a random password with Groovy
// Give execution permission
⇒ chmod +x random_password.groovy
// Show help
⇒ ./random_password.groovy -h
usage: random_password -[has]
-a,--alphabet <arg> A set of characters to generate the password
-h,--help Usage Information
-s,--size <arg> Size of the output password