Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
crazy4groovy / ASCII Art.groovy
Created January 5, 2012 17:57
Convert image(s) (http or local) to colour or b/w ascii art, via Groovy!
/**
* Groovy ASCII Art. Converts an image into ASCII.
* This doesn't work under the web console due to missing AWT classes.
*
* Author : Cedric Champeau (http://twitter.com/CedricChampeau)
* Updated : Steven Olsen (http://crazy4groovy.blogspot.com)
*/
import java.awt.color.ColorSpace as CS
import java.awt.geom.AffineTransform
import javax.imageio.ImageIO
@deanriverson
deanriverson / helloGroovyFX.groovy
Created March 3, 2012 16:57
A basic GroovyFX HelloWorld program
@Grab('org.codehaus.groovyfx:groovyfx:0.1')
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
GroovyFX.start {
def sg = new SceneGraphBuilder()
sg.stage(title: "GroovyFX Hello World", visible: true) {
scene(fill: black, width: 530, height: 300) {
@deanriverson
deanriverson / build.gradle
Created March 4, 2012 17:56
Basic Gradle build file for a project using GroovyFX 0.1
apply plugin:'groovy'
javafxHome = System.env['JAVAFX_HOME']
repositories { mavenCentral() }
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.2'
compile 'org.codehaus.groovyfx:groovyfx:0.1'
compile files("${javafxHome}/rt/lib/jfxrt.jar")
@crazy4groovy
crazy4groovy / helloGroovyFX.groovy
Created April 3, 2012 15:55 — forked from deanriverson/helloGroovyFX.groovy
A basic GroovyFX HelloWorld program
@Grab('org.codehaus.groovyfx:groovyfx:0.1')
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
//source: http://pleasingsoftware.blogspot.ca/2012/03/groovyfx-first-official-release.html
//run: groovy -classpath $JAVAFX_HOME/rt/lib/jfxrt.jar helloGroovyFX.groovy
GroovyFX.start {
def sg = new SceneGraphBuilder()
@crazy4groovy
crazy4groovy / TimeAvatar.groovy
Created May 22, 2012 19:26 — forked from mike-neck/TimeAvatar.groovy
inspired by image change script git://gist.github.com/1481409.git written by Yusuke Yamamoto. see https://gist.github.com/1481409
/**
* Copyright (C) 2011 Yusuke Yamamoto
* Licensed under the Apache License, Version 2.0 (the "License");
* http://www.apache.org/licenses/LICENSE-2.0
*
*
**/
@Grab(group='quartz', module='quartz', version='1.5.2')
@Grab(group='org.twitter4j', module='twitter4j-core', version='2.2.5')
@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
@glaforge
glaforge / build.gradle
Created November 25, 2011 16:04 — forked from Dierk/build.gradle
build.gradle for setting up a new gradle-based project
apply plugin:'groovy'
apply plugin:'idea'
repositories { mavenCentral() }
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.4'
}
task makeDirs(description:'make all dirs for project setup') << {
debounce = function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
Closure bind
List.metaClass.rightShiftUnsigned = { return bind(delegate, it) }
List.metaClass.call = { return [delegate, ''] }
Closure squrt = { Double x ->
if (x < 0.0d) return []
if (x == 0.0d) return [0.0]
return [Math.pow(x, 0.5), -Math.pow(x, 0.5)]
}
@crazy4groovy
crazy4groovy / Json-to-ImmutableClassInstance.groovy
Last active October 17, 2016 20:33
Create an Immutable Class instance from JSON? Let's see!
import groovy.json.*
import groovy.transform.Immutable
enum Fruit {
Orange,
Apple
}
enum Car {
Ford('slow'),