Skip to content

Instantly share code, notes, and snippets.

View CodyEngel's full-sized avatar

Cody Engel CodyEngel

View GitHub Profile
@CodyEngel
CodyEngel / TestHandler.kt
Last active April 24, 2024 16:34 — forked from dpmedeiros/AndroidMockUtil.java
Mock main thread handler for use in Android unit tests (requires Mockito and PowerMock)
package <Whatever Package Ya Want Really>
import android.os.Handler
import io.mockk.every
import io.mockk.mockk
import java.util.concurrent.CountDownLatch
/**
* TestHandler provides a way to execute tests that require a [Handler].
*
@CodyEngel
CodyEngel / RobotBoundedInCircle.kt
Created April 18, 2020 16:08
Robot Bound In Circle via Leetcode. Beats 100% memory 🎉 and beats 6.67% on runtime 😭
class Solution {
fun isRobotBounded(instructions: String): Boolean {
val robot = Robot()
repeat(4) {
instructions.forEach { instruction ->
when (instruction) {
'G' -> robot.move()
'R' -> robot.turnRight()
'L' -> robot.turnLeft()
}
@CodyEngel
CodyEngel / CoroutineChannels.kt
Created December 4, 2018 21:16
This is an example of the different channel types with coroutines and some scenarios. Note that sendBlockingBeforeReceiverScenario will cause the program to stop executing, DON'T USE SENDBLOCKING!
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.experimental.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.experimental.channels.sendBlocking
import kotlinx.coroutines.experimental.launch
fun main(args: Array<String>) {
val channels = listOf<Channel<Int>>(
Channel(capacity = UNLIMITED),
public class AwesomeButtonActivity extends AppCompatActivity implements View.OnClickListener {
private Button awesomeButton;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
awesomeButton = new Button(this);
awesomeButton.setOnClickListener(this);
public class AwesomeButtonActivity extends AppCompatActivity {
private Button awesomeButton;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
awesomeButton = new Button(this);
awesomeButton.setOnClickListener(new AwesomeButtonClick());
public class AwesomeButtonActivity extends AppCompatActivity {
private Button awesomeButton;
private View.OnClickListener awesomeOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
awesomeButtonClicked();
}
};
public class AwesomeButtonActivity extends AppCompatActivity {
private Button awesomeButton;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
awesomeButton = new Button(this);
awesomeButton.setOnClickListener(new View.OnClickListener() {
@CodyEngel
CodyEngel / AwesomeButtonActivity_1.java
Created June 27, 2017 01:10
4 Ways To Implement OnClickListener On Android
public class AwesomeButtonActivity extends AppCompatActivity {
private Button awesomeButton;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
awesomeButton = new Button(this);
awesomeButton.setOnClickListener(new View.OnClickListener() {
@CodyEngel
CodyEngel / DisposingObserver.java
Created April 15, 2017 00:13
A companion Observer for DisposableManager.
public class DisposingObserver<T> implements Observer<T> {
@Override
@CallSuper
public void onSubscribe(Disposable d) {
DisposableManager.add(d);
}
@Override
public void onNext(T next) {}
@CodyEngel
CodyEngel / DisposableManager.java
Created April 15, 2017 00:12
A singleton wrapper for managing a CompositeDisposable.
public class DisposableManager {
private static CompositeDisposable compositeDisposable;
public static void add(Disposable disposable) {
getCompositeDisposable().add(disposable);
}
public static void dispose() {
getCompositeDisposable().dispose();