Skip to content

Instantly share code, notes, and snippets.

View zvozin's full-sized avatar

Alex Zuzin zvozin

View GitHub Profile
@zvozin
zvozin / build.gradle
Last active November 11, 2021 14:20
Relevant parts of build.gradle required to get QueryDSL going over Hibernate with Kotlin and IDEA
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version")
{
"lender": "4,851.05",
"owner": "3,655.51",
"total": "8,506.56",
"details": {
"lender": {
"itemized": [
{
"total": "83.25",
"range": "$35,000.00..$50,000.00",
@zvozin
zvozin / Spark20Example.java
Last active December 19, 2018 11:31
Bare-bones usage of the Spark 2 Dataset API from Java 8
package com.example;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder;
import scala.runtime.AbstractFunction1;
import java.util.Arrays;
import java.util.function.Function;
@zvozin
zvozin / BufferActor.scala
Last active December 17, 2015 09:19
Time-and-space bounded Scalaz-based actor. Buffers elements of type A until either buffer size has been reached, or the time bound has elapsed.
import scalaz.concurrent.Actor
import collection.mutable.ArrayBuffer
import java.util.Timer
/**
* Usage:
*
* <code>
* val buffer = BufferActor[String](onFlush = _ foreach (println(_), onError = println(_))
* buffer ! "Now we're talking!"
@zvozin
zvozin / steps-of-scala-objects-1.scala
Created June 25, 2011 06:03
Scala Object definition
object ShinyNewObject{
val lovelyProperty = "Property we share"
val notSoLovelyProperty = 3.14
def weCanHazDoStuff(stuff: String) = doingCoolStuffHere(stuff)
}
public void doWithFields(Class<?> clazz) {
ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback()
{
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
System.out.println(field);
}
});
}
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
public static <T> Collection<T> toStringFiltered(List<T> aListOfTs) {
return Collections2.filter(aListOfTs, new Predicate<T>()
{
public boolean apply(T from) {
return from.toString().isEmpty();
}
});
}
public static <T> Collection<String> toString(List<T> aListOfTs) {
return Collections2.transform(aListOfTs, new Function<T, String>()
{
public String apply(T from) {
return from.toString();
}
});
}
aListOfTs.map(_.toString)