Skip to content

Instantly share code, notes, and snippets.

View mariogarcia's full-sized avatar

Mario Garcia mariogarcia

View GitHub Profile
@mariogarcia
mariogarcia / .ctags
Created October 2, 2013 10:24
File patterns to enable ctags on Vim
--langdef=groovy
--langmap=groovy:.groovy
--regex-groovy=/^[ \t]*[(private|public|protected) ( \t)]*[A-Za-z0-9_<>]+[ \t]+([A-Za-z0-9_]+)[ \t]*\(.*\)[ \t]*\{/\1/f,function,functions/
--regex-groovy=/^[ \t]*def[ \t]+([A-Za-z0-9_]+)[ \t]*\=[ \t]*\{/\1/f,function,functions/
--regex-groovy=/^[ \t]*private def[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/v,private,private variables/
--regex-groovy=/^[ \t]*def[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/u,public,public variables/
--regex-groovy=/^[ \t]*[abstract ( \t)]*[(private|public) ( \t)]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class,classes/
--regex-groovy=/^[ \t]*[abstract ( \t)]*[(private|public) ( \t)]*enum[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class,classes/
@mariogarcia
mariogarcia / gist:8593878
Created January 24, 2014 08:24
Some ideas about negative conditionals
Object.metaClass.not_in = {obj ->
!(delegate in obj)
}
boolean ifnot(boolean val, Closure closure) {
if (!val) {
closure.call()
}
}
@mariogarcia
mariogarcia / GradleGroovyConsole
Created February 4, 2014 08:39
Launching a Groovy Console with your Gradle classpath
task(console, dependsOn: 'classes', type: JavaExec) {
main = 'groovy.ui.Console'
classpath = sourceSets.main.runtimeClasspath
}
@mariogarcia
mariogarcia / apache-vfs.groovy
Created February 6, 2014 23:29
GroovyConsole example of Apache Commons VFS
@Grapes([
@Grab(group='org.apache.commons', module='commons-vfs2', version='2.0'),
@Grab(group='commons-httpclient', module='commons-httpclient', version='3.1')
])
import org.apache.commons.vfs2.VFS
import org.apache.commons.vfs2.FileUtil
import org.apache.commons.vfs2.FileListener
import org.apache.commons.vfs2.FileObject
import org.apache.commons.vfs2.FileSystemManager
@GrabResolver(name='grails-core', root='http://repo.grails.org/grails/core')
@Grab(group='org.grails', module='grails-datastore-gorm-mongo', version='1.0.0.BUILD-SNAPSHOT')
@Grab(group='org.slf4j', module='slf4j-simple', version='1.6.1')
import grails.persistence.*
import org.grails.datastore.gorm.mongo.config.*
MongoDatastoreConfigurer.configure("myDatabase", Book)
Book.withSession {
@mariogarcia
mariogarcia / groovy_haskell_where.groovy
Last active August 29, 2015 13:58
Groovy version of the Haskell where clause
class FnCheck {
static class Evaluation {
Closure condition
Closure execution
}
def conditions = []
def parameters = [:]
import groovyx.gpars.actor.Actors
import groovyx.gpars.actor.DefaultActor
import groovyx.gpars.actor.DynamicDispatchActor
class SupervisedException extends Exception {
SupervisedException(String message) {
super(message)
}
}
@mariogarcia
mariogarcia / gist:af88669efd1057654f51
Last active August 29, 2015 14:04
Functor, Appllicative y Monad
import groovy.transform.Immutable
// PROTOCOLO
interface Functor {
Functor fmap(Closure fn)
}
interface Applicative {
Applicative fapply(Applicative afn)
@mariogarcia
mariogarcia / Something.groovy
Last active August 29, 2015 14:04
New version of categories research
interface Fn<I,O> {
O execute(I i)
}
// applies a function to a value
// TODO while I think functions could be parametrized
// functors should not. Functions are a special case
// of functors
interface Functor<I,O> {
I getValue()
@mariogarcia
mariogarcia / BusinnessValidation.groovy
Created August 25, 2014 12:22
Thinking about business validation + functional style
interface HasUser {
User getUser()
}
interface HasBank {
Bank getBank()
}
interface Validator<T> {
Boolean validate(T validateable)