Skip to content

Instantly share code, notes, and snippets.

public class TestSub<T>
implements Observable.OnSubscribe<T> {
Subscriber<T> sub;
public void call(Subscriber<T> sub) {
this.sub = sub;
}
public void onNext(T data) {
sub.onNext(data);
}
...
@trevorrjohn
trevorrjohn / log.java
Last active September 24, 2015 20:17
error with layer object
E/LayerSDK: LayerClientImpl : Exception
E/LayerSDK: com.layer.sdk.exceptions.LayerException: DEVICE_PERSISTENCE_FAILURE (9001) - Uncaught Task exception
E/LayerSDK: at com.layer.sdk.internal.syncrecon.SyncRecon$a.a(SyncRecon.java:467)
E/LayerSDK: at com.layer.sdk.internal.syncrecon.SyncRecon$a.run(SyncRecon.java:599)
E/LayerSDK: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/LayerSDK: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/LayerSDK: at java.lang.Thread.run(Thread.java:856)
E/LayerSDK: Caused by: android.database.sqlite.SQLiteConstraintException: column stream_id is not unique (code 19)
E/LayerSDK: at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
E/LayerSDK: at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727)
@trevorrjohn
trevorrjohn / TimeZoneRule.java
Created August 7, 2015 14:09
JUnit TimeZoneRule for setting timeZone in test
public class TimeZoneRule implements TestRule {
private final String timeZoneId;
public TimeZoneRule(String timeZoneId) {
this.timeZoneId = timeZoneId;
}
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@trevorrjohn
trevorrjohn / .gitignore
Created August 6, 2015 01:48
Android .gitignore
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
@trevorrjohn
trevorrjohn / HexagonImageView.java
Last active March 12, 2021 01:05
Example hexagon image view
package com.playdraft.hexigonimageview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
@trevorrjohn
trevorrjohn / gen.bash
Created May 7, 2015 15:32
new android keystore
keytool -genkey -v -keystore keystore.keystore -alias alias -storepass password -keypass password -keyalg RSA -validity 36500
@trevorrjohn
trevorrjohn / builder.java
Created May 4, 2015 15:37
builder pattern mock
/*
* copied from: http://stackoverflow.com/questions/8501920/how-to-mock-a-builder-with-mockito
*/
import static org.mockito.Mockito.RETURNS_DEFAULTS;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
public class SelfReturningAnswer implements Answer<Object>{
@trevorrjohn
trevorrjohn / activity.java
Created April 28, 2015 13:47
android clear back stack of for next activity
Intent intent = new Intent(this, NextActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
@trevorrjohn
trevorrjohn / encryption_instructions.md
Last active August 29, 2015 14:19
OSX Encrypt Folder Instructions

Encrypt a File OSX

Instructions on to encrypt a file on OSX 10.9. Based of this StackOverflow post.

Requirements

  • Homebrew
  • osxfuse brew install Caskroom/cask/osxfuse
  • encfs brew install encfs
@trevorrjohn
trevorrjohn / android-intellij.groovy
Last active August 29, 2015 14:11
gradle task to fix dependency order in Android Studio
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes')
}
}
task initGradleTest << {
def imlFile = '<path to iml>.iml'