This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.trello.rxlifecycle2.LifecycleProvider | |
import io.reactivex.Observable | |
import io.reactivex.disposables.CompositeDisposable | |
import io.reactivex.disposables.Disposable | |
fun Disposable.disposeWith(compositeDisposable: CompositeDisposable) { | |
compositeDisposable.add(this) | |
} | |
fun <E> Disposable.disposeUntil(e: E, lifecycleProvider: LifecycleProvider<E>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws InterruptedException { | |
Observable<String> observable = Observable.create(new ObservableOnSubscribe<Integer>() { | |
@Override public void subscribe(ObservableEmitter<Integer> e) throws Exception { | |
System.out.println("emit" + Thread.currentThread().getName()); | |
e.onNext(12); | |
e.onNext(3232); | |
} | |
}) | |
.compose(integerStringObservableTransformer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For Java developers all excited by and jealous of Kotlin's sealed classes. | |
* Do this when you wish you could put parameters on an enum. | |
*/ | |
public class PoorMan { | |
private interface Event { | |
<T> T dispatch(EventHandler<T> handler); | |
} | |
interface EventHandler<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.Animator; | |
import android.animation.AnimatorListenerAdapter; | |
import android.view.View; | |
import com.example.harshitbangar.ribswithoutdagger.ScreenStackImpl; | |
import static android.view.View.GONE; | |
import static android.view.View.VISIBLE; | |
public class CrossfadeTransition implements Transition { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GC is a background thread and JVM doesn't have a spec for it to be daemon or not. | |
// https://stackoverflow.com/questions/5553783/java-garbage-collection-thread-priority | |
public class WeakReferenceCaller { | |
public static void main(String[] args) throws InterruptedException { | |
MyObject myObject = new MyObject(); | |
Thread thread = new Thread(new WeakReferenceRunnable(myObject)); | |
thread.start(); | |
myObject = null; | |
System.out.println(myObject); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import javax.annotation.Nonnull; | |
import javax.annotation.Nullable; | |
public class EmailDummy { | |
@Nonnull | |
public final String From; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an array with n objects colored red, white or blue, | |
// sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. | |
// Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. | |
// Note: Using library sort function is not allowed. | |
// Example : | |
// Input : [0 1 2 0 1 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a sorted linked list, delete all duplicates such that each element appear only once. | |
// For example, | |
// Given 1->1->2, return 1->2. | |
// Given 1->1->2->3->3, return 1->2->3. | |
/** | |
* Definition for singly-linked list. | |
* class ListNode { | |
* public int val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InsertionSort { | |
public int[] sort(int[] input) { | |
int[] output = new int[input.length]; | |
for (int i=0; i<input.length; i++) { | |
int indexToInsert = 0; | |
for (int j=0; j<=i; j++) { | |
if (input[i] < output[j]) { | |
indexToInsert=j; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Arbit { | |
public static void main(String[] args) { | |
Arbit arbit = new Arbit(); | |
Container container = new Container(); | |
container.a = 7; | |
container.b = 6; | |
arbit.change(container); | |
int d = 5; | |
arbit.changeInt(d); | |
System.out.println(container); |