Skip to content

Instantly share code, notes, and snippets.

View oehme's full-sized avatar

Stefan Oehme oehme

View GitHub Profile
select (
T_BOOK.ID * T_BOOK.AUTHOR_ID,
T_BOOK.ID + T_BOOK.AUTHOR_ID * 3 + 4,
T_BOOK.TITLE || " abc" || " xy"
)
from T_BOOK
leftOuterJoin (
f select (x.ID, x.YEAR_OF_BIRTH)
from x
limit 1
QPerson p = QPerson.person;
List<Person> persons = db.from(p)
.where(
(p.firstName.loe("C").or(p.lastName.goe("T")))
.and(p.age.gt(18))
.and(p.gender.eq(Gender.FEMALE))
)
.orderBy(p.firstName.asc())
.list(p);
val p = QPerson.person
val persons = db.from(p)
.where(
(p.firstName <= "C" || p.lastName >= "T")
&& p.age > 18
&& p.gender == Gender.FEMALE
)
.orderBy(p.firstName.asc)
.list(p)
@CreateWith(typeof(GuiceSpecCreator))
@InjectWith(typeof(EnglishModule))
describe Greeter "Interface Injection"{
@Inject
Greeter injected
fact "the subject is injected by Guice"{
subject.greet should be "Hello"
}
@Immutable
class Address {
String street;
String city;
String zip;
String postOfficeBox
}
class AddressTest {
val address = Address::build[
class ExtractInterfaceProcessor extends AbstractClassProcessor {
override doRegisterGlobals(ClassDeclaration cls, RegisterGlobalsContext context) {
context.registerInterface(cls.qualifiedInterfaceName)
}
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) {
findInterface(cls.qualifiedInterfaceName) => [ iface |
cls.declaredMethods.filter [
visibility == Visibility::PUBLIC
@Active(typeof(BenchmarkProcessor))
annotation Benchmark {
}
class BenchmarkProcessor extends AbstractClassProcessor {
override doTransform(MutableClassDeclaration cls, TransformationContext context) {
new BenchmarkClassGenerator(context, cls).generate
}
}
@Benchmark
class FibonacciBenchmarkXtend24 {
List<Integer> nValues = #[5, 10, 20]
def timeDumbFibonacci() {
for (i : 1 .. iterations) {
new Fibonaccis().dumbFibonacci(n)
}
}
public class FibonacciBenchmarkJava extends SimpleBenchmark {
@Param
private int n;
public static List<Integer> nValues = ImmutableList.of(5, 10, 20 );
public void timeMemoizedFibonacci(int iterations) {
for (int i = 0; i < iterations; i++) {
new Fibonaccis().memoizedFibonacci(n);
@oehme
oehme / gist:5180927
Last active December 15, 2015 01:38
Automatic Memoization through annotation processing
@Active(typeof(MemoizeProcessor))
annotation Memoize {
}
class MemoizeProcessor implements TransformationParticipant<MutableMethodDeclaration> {
override doTransform(List<? extends MutableMethodDeclaration> methods, extension TransformationContext context) {
methods.forEach [
switch (parameters.size) {
case 0: new ParamterlessMethodMemoizer(it, context, methods.indexOf(it)).generate
case 1: new SingleParameterMethodMemoizer(it, context, methods.indexOf(it)).generate