Skip to content

Instantly share code, notes, and snippets.

View thuytrinh's full-sized avatar
💭
${null}

Thuý thuytrinh

💭
${null}
  • Frankfurt, Germany
  • 00:36 (UTC +02:00)
View GitHub Profile
const { danger, warn } = require("danger");
// No pull request is too small to include a description of why you made a change.
if (danger.github.pr.body.length < 10) {
warn("Please include a description of your PR changes.");
}
@thuytrinh
thuytrinh / OkioTest.kt
Last active September 21, 2018 13:56
A sample usage of GzipSink & GzipSource from Okio
import okio.GzipSink
import okio.GzipSource
import okio.Okio
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import java.io.File
class OkioTest {
@Test
fun `should compress file properly`() {
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* NOTE: Please remove this class if we decide to integrate with RoboSpice.
* RoboSpice does implement a DefaultNetworkStateChecker class which takes care of everything NetworkUtils does.
*/
public class NetworkUtils {
@thuytrinh
thuytrinh / GzipTest.java
Created March 21, 2015 01:39
Write/read gzip stream properly
import android.content.Context;
import android.test.InstrumentationTestCase;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
public class GistFetcherTest extends InstrumentationTestCase {
public void testFetch() throws IOException {
final InputStream mockResponseStream = getInstrumentation().getContext().getAssets().open("mock_response.json");
OkHttpClient httpClient = new OkHttpClient();
httpClient.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
return new Response.Builder()
.protocol(Protocol.HTTP_2)
public class DbField {
public final String name;
public final String type;
public final String constraint;
public DbField(String name, String type) {
this(name, type, null);
}
public DbField(String name, String type, String constraint) {
@thuytrinh
thuytrinh / ObservableProperty.java
Created January 11, 2015 09:08
A reactivex-based class to represent a mutable property of an object
import rx.Observable;
import rx.functions.Action1;
import rx.subjects.BehaviorSubject;
public class ObservableProperty<T> implements Action1<T> {
private final BehaviorSubject<T> valueSubject;
private T value;
public ObservableProperty() {
valueSubject = BehaviorSubject.create();
@thuytrinh
thuytrinh / MainThreadBus.java
Created December 27, 2014 04:15
A custom Otto bus that posts events from any thread and lets subscribers receive them on the main thread
import android.os.Handler;
import android.os.Looper;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
/**
* A custom {@link Bus} that posts events from any thread and
* lets subscribers receive them on the main thread.
*/
Observable.from(Arrays.array(1, 2, 3, 4, 5))
        .groupBy(new Func1<Integer, Boolean>() {
            @Override
            public Boolean call(Integer number) {
                return number % 2 == 0;
            }
        })
        .flatMap(new Func1<GroupedObservable<Boolean, Integer>, GroupedObservable<Boolean, Integer>>() {
            @Override
import android.database.Cursor;
import java.util.Iterator;
public class IterableCursor implements Iterable<Cursor> {
private Cursor cursor;
public IterableCursor(Cursor cursor) {
this.cursor = cursor;
this.cursor.moveToPosition(-1);