Skip to content

Instantly share code, notes, and snippets.

View oehme's full-sized avatar

Stefan Oehme oehme

View GitHub Profile
@oehme
oehme / CustomOperators.xtend
Last active August 29, 2015 14:04
Defining custom operators on Observable
def static <T> myOperator(Observable<T> observable) {
observable.lift(new MyOperator)
}
def static void main(String[] args) {
Observable.just("Foo").myOperator
//instead of
Observable.just("Foo").lift(new MyOperator)
}
@oehme
oehme / OnSubscribe.xtend
Last active August 29, 2015 14:04
Resolving ambigous situations
//Preferred OnSubscribe API
Observable.create[
onNext(9000)
onCompleted
]
.subscribe[
println(it)
]
//force the deprecated OnSubscribeFunc API by returning a Subscription
@oehme
oehme / RxJava.xtend
Created July 18, 2014 09:17
A simple RxJava exmample in XTend
Observable.from("Foo", "Bar", null)
.filter[startsWith("F")]
.subscribe(
[println(it)],
[println("error")],
[|println("done")]
)
//prints Foo and error
@oehme
oehme / JodaToJdbc4.java
Last active December 27, 2015 09:29
Joda Time to JDBC - working and fast
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
private Calendar utc() {
return (Calendar) UTC.clone();
}
//unchanged
public LocalDateTime getValue(ResultSet rs, int index) throws SQLException {
Timestamp ts = rs.getTimestamp(index, utc());
@oehme
oehme / JodaToJdbc3.java
Last active December 27, 2015 09:29
Joda Time to JDBC - fast, but with threading issues on some drivers
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
private Calendar utc() {
return UTC;
}
//unchanged
public LocalDateTime getValue(ResultSet rs, int index) throws SQLException {
Timestamp ts = rs.getTimestamp(index, utc());
@oehme
oehme / JodaToJdbc2.java
Created November 4, 2013 15:25
Joda Time to JDBC - Working, but slow
private Calendar utc() {
return Calendar.getInstance(TimeZone.getTimeZone("UTC"));
}
public LocalDateTime getValue(ResultSet rs, int index) throws SQLException {
Timestamp ts = rs.getTimestamp(index, utc());
return ts != null ? new LocalDateTime(ts.getTime(), DateTimeZone.UTC) : null;
}
public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException {
@oehme
oehme / JodaToJdbc1.java
Last active December 27, 2015 09:19
Joda Time to JDBC - fails on DST transition
public LocalDateTime getValue(ResultSet rs, int index) throws SQLException {
Timestamp ts = rs.getTimestamp(index);
return ts != null ? new LocalDateTime(ts.getTime()) : null;
}
public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException {
DateTime dt = value.toDateTime(); //uses defaul timezone
st.setTimestamp(index, new Timestamp(dt.getMillis())); //uses default timezone
}
@oehme
oehme / settings.xml
Last active December 26, 2015 16:58
Cloudbees jar signing
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.homedir>/private/${cloudbees account name}/gpg</gpg.homedir>
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
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)