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
@Joxebus
Joxebus / home.groovy
Last active November 15, 2021 17:58
Cómo crear un Groovy Servlet (Groovlet)
def method = request.method
if (!session) {
session = request.getSession(true)
}
if (!session.groovlet) { // Podemos tener variables guardadas en session
session.groovlet = 'Groovlets rock!'
}
@Joxebus
Joxebus / SampleDataTypes.groovy
Created August 12, 2020 06:54
Samples for Desveloper Channel
def name = '"Desveloper"'
def map = [:] // java.util.LinkedHashMap
def elements = [1, // java.lang.Integer
11111111111, // java.lang.Long
11111111111111111111, // java.math.BigInteger
0.1, // java.math.BigDecimal
0..5, // groovy.lang.IntRange
'x'..'p', // groovy.lang.ObjectRange
"Normal String", // java.lang.String
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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"
}
}