Skip to content

Instantly share code, notes, and snippets.

💭
null

Thuy Trinh thuytrinh

💭
null
Block or report user

Report or block thuytrinh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dangerfile.js
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 Sep 21, 2018
A sample usage of GzipSink & GzipSource from Okio
View OkioTest.kt
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`() {
View NetworkUtils.java
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 Mar 21, 2015
Write/read gzip stream properly
View GzipTest.java
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;
View GistFetcherTest.java
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)
View DbField.java
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 Jan 11, 2015
A reactivex-based class to represent a mutable property of an object
View ObservableProperty.java
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 Dec 27, 2014
A custom Otto bus that posts events from any thread and lets subscribers receive them on the main thread
View MainThreadBus.java
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.
*/
View rx.md
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
View IterableCursor.java
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);
You can’t perform that action at this time.