Skip to content

Instantly share code, notes, and snippets.

View oehme's full-sized avatar

Stefan Oehme oehme

View GitHub Profile
@oehme
oehme / gist:4737130
Created February 8, 2013 06:42
Force drop user in Oracle database
DECLARE
open_count integer;
BEGIN
-- prevent any further connections
EXECUTE IMMEDIATE 'alter user @USERNAME account lock';
--kill all sessions
FOR session IN (SELECT sid, serial#
FROM v$session
WHERE username = '@USERNAME')
LOOP
@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 / Stacktrace
Created October 7, 2016 16:54
IDEA hanging during sync
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.pickClosureMethod(ClosureMetaClass.java:212)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:270)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at org.gradle.api.specs.internal.ClosureSpec.isSatisfiedBy(ClosureSpec.java:32)
at org.gradle.api.internal.collections.CollectionFilter.filter(CollectionFilter.java:48)
at org.gradle.api.internal.collections.FilteredCollection$FilteringIterator.findNext(FilteredCollection.java:101)
at org.gradle.api.internal.collections.FilteredCollection$FilteringIterator.<init>(FilteredCollection.java:95)
at org.gradle.api.internal.collections.FilteredCollection.iterator(FilteredCollection.java:130)
class ImmutableProcessor extends AbstractClassProcessor {
override doRegisterGlobals(ClassDeclaration cls, RegisterGlobalsContext context) {
context.registerClass(cls.builderClassName)
}
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) {
if(cls.extendedClass != object) cls.addError("Inheritance does not play well with immutability")
cls.final = true
@oehme
oehme / ListsAreNotCovariant.java
Created July 12, 2016 16:28
Why ignoring type safety warnings is bad
List<Foo> specialThings = Lists.newArrayList(); //Foo extends Base
Bean bean = new Bean();
// normally you would correctly get a compile error here,
//but the setter in your example does an unsafe cast that makes this line compile
bean.setStuff(specialThings);
List<Base> things = bean.getStuff();
things.add(new Bar()); // Bar extends Base
@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>