Skip to content

Instantly share code, notes, and snippets.

// Elixir ideas https://quickleft.com/blog/pattern-matching-elixir/
class Functions {
@When('!list')
int length(List list) { 0 }
@When('[heal | tail] = list')
int length(List list) { 1 + length(tail) }
@chiquitinxx
chiquitinxx / MyTodo.groovy
Created May 31, 2016 21:52
Grooscript components and grails 3
package component
import todo.Todo
class MyTodo {
List<Todo> todos
String newTodoTyped
static renderAfter = ['gotTodos', 'newTaskAdded']
@chiquitinxx
chiquitinxx / gist:1851d1bdb5a71980bab6
Last active December 14, 2015 23:28
Groovy components coming in grails 3 plugin
//Define your component in a groovy class
package foo.bar
class Counter {
static renderAfter = ['inc', 'dec']
static style = 'button { background-color: red; }'
int value = 0
void inc() {
value++
@chiquitinxx
chiquitinxx / gist:780922395b08fcf6b19e
Last active August 29, 2015 14:22
Create #groovylang code that run in groovy, java and javascript environments
GrooscriptObservable.fromList(["one", "two", "three"])
.take(2)
.subscribe({arg -> println(arg)})
//In groovy and converted code in js, you get in console:
//one
//two
import org.grooscript.asts.GsNative
@chiquitinxx
chiquitinxx / gist:b661f27c647c3cfe5d38
Last active August 29, 2015 14:22
Rest API from client side with trait and jQuery
import org.grooscript.asts.GsNative
trait JQueryRestApi {
static String url
static String resource
void add(Closure onSuccess, Closure onError) {
ajaxCall('POST', "${url}/${resource}", onSuccess, onError)
}
@chiquitinxx
chiquitinxx / gist:1eb901bcf81a4e068681
Created June 7, 2015 18:19
Groov'ing google maps api
GoogleMap.init {
options.zoom = 6
options.center = ltlg(40.4379543,-3.6795367 )
putStyle([
[stylers: [ [ visibility: 'simplified' ],[ gamma: 0.5 ],[ weight: 0.5 ] ] ],
[featureType: 'water', stylers: [ [color: '#b77fd7'] ] ]
])
mark(position: ltlg(40.4379543,-3.6795367),
title: 'grooscript',
icon: "img/gs.png"
@chiquitinxx
chiquitinxx / gist:2a89987fe4e611803a7b
Last active August 29, 2015 14:22
Create a Rest API fake in Groovy, using javascript npm modules (faker and json-server)
import org.grooscript.asts.GsNative
class Faker {
private _faker
@GsNative
private faker() {/*
if (!this._faker) {
this._faker = require('faker');
}
@chiquitinxx
chiquitinxx / gist:f60c28da6b3ac22520b1
Created March 29, 2015 13:58
Create ios app with grooscript and react native
def AwesomeProject = React.createClass(
render: {
def groovyView = new GroovyView()
groovyView.data(style: styles.container) {
image style: styles.image, source: [uri: 'http://grooscript.org/img/groovy.png']
text style: styles.welcome, "Hello #ios from #groovylang"
text style: styles.welcome, "With @grooscript"
text style: styles.welcome, "and @reactjs native"
}
})
@chiquitinxx
chiquitinxx / gist:ef2d33ce9d1a810ba216
Created March 11, 2015 20:24
Using RxJs from grooscript with @basescript
//Grooscript version of https://github.com/Reactive-Extensions/RxJS/tree/master/examples/autocomplete
import groovy.transform.BaseScript
import org.grooscript.asts.GsNative
import static org.grooscript.GrooScript.toJavascript
@BaseScript
ReactiveScript baseScript
def keyUp = observeEvent(textInput, 'keyup')
@chiquitinxx
chiquitinxx / gist:b01d0696cfabcc34527b
Created March 4, 2015 19:39
Using RxJs from grooscript
//Grooscript version of https://github.com/Reactive-Extensions/RxJS/tree/master/examples/autocomplete
import org.grooscript.asts.GsNative
import static org.grooscript.GrooScript.toJavascript
import static rxjs.ReactiveResolver.reactive
reactive {
def searchWikipedia = { term ->
$.ajax(url: 'http://en.wikipedia.org/w/api.php',
dataType: 'jsonp',
data: toJavascript([