Skip to content

Instantly share code, notes, and snippets.

View geowarin's full-sized avatar

Geoffroy Warin geowarin

View GitHub Profile
@geowarin
geowarin / parseArgs.groovy
Created November 14, 2014 07:55
CliBuilder example to parse command line args with groovy
static def parseOptions(args) {
cli = new CliBuilder(usage: 'slide')
cli.t(args: 1, argName: 'type', "type ('pdf', 'deck' or 'both')", required: true)
cli.f(args: 1, argName: 'file', 'file to convert', required: true)
def options = cli.parse(args)
options || System.exit(1)
inputFile = new File(options.f)
['deck', 'pdf', 'both'].contains(options.t) || exitWithMessage('Unknown type ' + options.t)
inputFile.exists() || exitWithMessage("File not found ${inputFile} ")
@geowarin
geowarin / logger.groovy
Last active August 29, 2015 14:09
Log process output in groovy
#!/usr/bin/env groovy
@Grapes(
@Grab('log4j:log4j:1.2.17')
)
import org.apache.log4j.Level
import org.apache.log4j.Logger
abstract class DefaultAppendable implements Appendable {
@Override
@geowarin
geowarin / GebConfig.groovy
Created November 12, 2014 22:56
Groovy script which downloads all icons from iconmonstr.com with geb webdriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxProfile
driver = {
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", System.getProperty("user.home") + '/icons');
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "image/png");
def firefoxDriver = new FirefoxDriver(firefoxProfile)
@geowarin
geowarin / slides2png.groovy
Last active August 29, 2015 14:06
slides2png.groovy
#!/usr/bin/env groovy
/**
* slides2png plays a dzslides presentation using WebDriver, captures each
* slide to a PNG and generates a shell script to collate the PNGs together
* into a PDF using convert (from ImageMagick).
*
* The URL of the presentation is passed as the sole argument to the script.
* If the presentation is local, specify the absolute path prefixed with the
* file:// protocol.
package fr.xebia;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;
import org.apache.naming.resources.VirtualDirContext;
import org.junit.rules.ExternalResource;
import java.io.File;
package geowarin
import java.util.regex.Matcher
/**
*
* Date: 27/06/2014
* Time: 22:40
* @author Geoffroy Warin (http://geowarin.github.io)
*/
@geowarin
geowarin / Zipper.groovy
Last active November 15, 2016 03:19
How to zip file trees with groovy
import java.nio.file.FileSystems
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.PathMatcher
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
@geowarin
geowarin / LogRule.java
Created June 13, 2014 09:21
Junit rule that allows capturing Logs output in the Class under test during unit testing
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
@geowarin
geowarin / logback.xml
Created May 27, 2014 16:55
Spring boot default
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.boot" level="INFO"/>
<logger name="org.springframework.security" level="ERROR"/>
<logger name="org.glassfish.jersey" level="INFO"/>
</configuration>
@geowarin
geowarin / Procfile
Last active August 29, 2015 14:00
Running a jar on heroku with java 8
web: java $JAVA_OPTS -jar target/*.jar