Skip to content

Instantly share code, notes, and snippets.


Andrey Hihlovskiy akhikhl

  • Apple GmbH
  • Berlin, Germany
View GitHub Profile
akhikhl / git-pull.gradle
Created Jun 7, 2013
Batch pull on all git-repositories found in the current folder
View git-pull.gradle
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-git:0.5.0' }
import org.ajoberstar.gradle.git.tasks.*
def onEachGitFolder(File folder, Closure closure) {
File gitServiceFolder = new File(folder, ".git")
if(gitServiceFolder.exists() && gitServiceFolder.isDirectory())
akhikhl / sources_javadoc.gradle
Created Jun 20, 2013
gradle snippet: sources and javadoc jars for every subproject
View sources_javadoc.gradle
/* Add this to the parent "build.gradle" to enable xyz-sources.jar and xyz-javadoc.jar generation
* for every java and groovy subproject of the given parent project.
* The script tolerates non-java subprojects.
subprojects {
afterEvaluate {
if(tasks.findByName("classes")) {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
akhikhl / TestLogConfig.groovy
Last active Dec 19, 2015
"Manual" configuration of multiple logback encoders and appenders.
View TestLogConfig.groovy
package testpackage
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.rolling.RollingFileAppender
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
class Main {
public void main(String[] args) {
Person p = new Person("Andrey", "Hihlovskiy", "12.07.1969");
boolean hasBirthDayToday = p.hasBirthDay(new Date());
p.say("Friends", "Hey, guys, have a cake, it's my birthday!")
while(isWorkingHours()) {;
akhikhl / ParseRtf.groovy
Created Jul 14, 2013
A happier, groovier way to parse RTF: apache_tika + XmlSlurper
View ParseRtf.groovy
package org.akhikhl.test
import org.apache.tika.metadata.Metadata
import org.apache.tika.parser.rtf.RTFParser
class ParseRtf {
def parse(String rtfText) {
// not validating, not ns-aware
XmlSlurper slurper = new XmlSlurper(false, false)
akhikhl / GroovySwitchAndClosures.groovy
Created Sep 4, 2013
switch statement and closure comprehension
View GroovySwitchAndClosures.groovy
def isGreaterThan(a, b) { a > b }
def isGreaterThan(b) {
return { a -> isGreaterThan(a, b) }
def isLessThan(a, b) { a < b }
def isLessThan(b) {
return { a -> isLessThan(a, b) }
akhikhl / jetty.groovy
Created Oct 28, 2013
groovy script for starting jetty server against the specified folder
View jetty.groovy
@Grab(group='org.eclipse.jetty', module='jetty-webapp', version='8.1.8.v20121106')
@Grab(group='org.eclipse.jetty', module='jetty-server', version='8.1.8.v20121106', transitive=false)
@Grab(group='org.eclipse.jetty', module='jetty-servlet', version='8.1.8.v20121106', transitive=false)
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*
akhikhl / jdom2_transform.groovy
Last active Jul 17, 2021
XML transformation with Groovy, JDOM2 and XPath
View jdom2_transform.groovy
* Copyright 2013 (c) Andrey Hihlovskiy
* License: MIT (
import org.jdom2.*
akhikhl / xslt_text_attr.groovy
Created Dec 27, 2013
XSLT transformation b -> bold, i -> italic, text -> normal
View xslt_text_attr.groovy
import javax.xml.transform.TransformerFactory
def input = '''<?xml version="1.0"?>
<p>This is <b>bold text</b>, <i>italic text</i> and normal text</p>
def xslt = '''<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
akhikhl / sort_map_by_values.groovy
Created Dec 27, 2013
Sorting hashmap float -> float by values
View sort_map_by_values.groovy
import java.util.Map;
rand = new Random();
float random(float minX, float maxX) {
rand.nextFloat() * (maxX - minX) + minX
// Note the HashMap's "key" is a String and "value" is an Integer
HashMap<Float,Float> hm = new HashMap<Float,Float>();