Skip to content

Instantly share code, notes, and snippets.

View melix's full-sized avatar

Cédric Champeau melix

View GitHub Profile
data Foo a b = Foo a b
mkFoo a b = Foo a (2*b)
instance (Show a, Show b) => Show (Foo a b) where
show (Foo a b) = "I am (" ++ show (a,b) ++ ")"
@melix
melix / hodorlang.groovy
Last active August 29, 2015 14:01
The Hodor DSL
import org.codehaus.groovy.control.CompilerConfiguration
/*
* Copyright 2003-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@melix
melix / README.adoc
Last active July 7, 2021 07:37
An automated solver for 2048

Automated solver for 2048

This is a script which runs a "bot" that tries to solve the incredibly addictive 2048 game. It makes use of Groovy and browser automation with Geb.

How to

  • First step, if you don’t have it, you need to install Groovy.

  • Second step is to install the Google Chrome WebDriver (just unzip the appropriate file to a local directory)

  • Next, edit the script to set the path to the Chrome Driver

  • then execute the script: groovy solver2048.groovy

@melix
melix / convert.groovy
Created July 17, 2013 12:57
Convert Confluence HTML export into asciidoc
@Grab('net.sourceforge.htmlcleaner:htmlcleaner:2.4')
import org.htmlcleaner.*
def src = new File('html').toPath()
def dst = new File('asciidoc').toPath()
def cleaner = new HtmlCleaner()
def props = cleaner.properties
props.translateSpecialEntities = false
def serializer = new SimpleHtmlSerializer(props)
@ldaley
ldaley / gist:5429603
Last active March 5, 2018 14:59
Groovy @DelegatesTo and type tokens.
Handler<T> handler(@DelegatesTo.Target(asType = true) Class<T> type, @DelegatesTo Closure<?> configurer) {
return new Handler() {
void handle(T object) {
configurer.delegate = object
configure.call(delegate)
}
}
}
@timyates
timyates / match.groovy
Created June 27, 2012 09:17
match/when implemented with Groovy's GEP-3
// No commas
def a = 'tim'
def nocom = match( a ) {
when 'dave' 'Hi Dave'
when 'tim' 'Hi Tim'
otherwise 'none of the above'
}
assert nocom == 'Hi Tim'
// Commas
@melix
melix / add_local_ast.groovy
Created March 1, 2012 16:42
Add local AST transformation to a method
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.CompilationCustomizer
import org.codehaus.groovy.control.CompilePhase
import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.transform.sc.StaticCompileTransformation
def config = new CompilerConfiguration()