Skip to content

Instantly share code, notes, and snippets.

View adam-hurwitz's full-sized avatar

Adam Hurwitz adam-hurwitz

View GitHub Profile
@adam-hurwitz
adam-hurwitz / Rocket-Pool-Dashboard-Query
Last active December 22, 2021 18:40
Rocket Pool Dashboard Query
query stakerCheckpointData {
stakerBalanceCheckpoints(where: {stakerId: "SOME_WALLET_ADDRESS"} orderBy: blockTime orderDirection: desc){
ethBalance
rETHBalance
totalETHRewards
block
blockTime
}
}
@adam-hurwitz
adam-hurwitz / EditTextUtils.java
Last active January 29, 2021 01:11
ODG - EditText Utils
// Handle input length
private void handleInputLength(){
editTextViewName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 6){animateMethod();}
@adam-hurwitz
adam-hurwitz / AvoidConcurrentModificationException.kt
Last active January 11, 2021 20:43
ODG - Kotlin: Avoiding ConcurrentModificationException
val integers = arrayListOf(1, 2, 3)
// Filter using streams.
val newIntegers = integers.filter { it != 2 }
// Use removeIf()
integers.removeIf { it == 2 }
// Use an iterator directly.
val iterator = integers.iterator()
@adam-hurwitz
adam-hurwitz / activity_main.xml
Created January 2, 2021 16:32
ODG - Android NavHost Fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
@adam-hurwitz
adam-hurwitz / someLayout.md
Last active December 18, 2020 20:15
ODG - Android Data Binding Samples

Strings

  • Static: android:text="@string/sell_recommend_views_label"

  • Concat resources: android:text="@{'Hello ' + user.firstName}"

  • Concat resource and var (Include %1s formatting in String resource): android:text='@{String.format(@string/string_name, uxContent.reduceByPrice)}'

  • Formatted: android:text='@{@string/some_string(uxContent.someVal, uxContent.someVal)}'

@adam-hurwitz
adam-hurwitz / 1. Pull the APK from the phone
Last active December 4, 2020 19:27
ODG - Android Security: Decompile App
adb shell pm list package | grep lyft
adb shell pm path me.lyft.android
// Access the terminal of the phone.
adb shell
// Copy the APK to the phone's SD card.
cp /data/app/me.lyft.android-1/base.apk /mnt/sdcard
@adam-hurwitz
adam-hurwitz / build.gradle
Last active October 4, 2020 05:36
Android Model-View-Intent with Unit Tests - Libraries in build.gradle (App)
buildscript {
dependencies {
...
classpath "de.mannodermaus.gradle.plugins:android-junit5:X.X.X"
}
}
@adam-hurwitz
adam-hurwitz / build.gradle
Last active October 4, 2020 05:36
Android Model-View-Intent with Unit Tests - Libraries in build.gradle (Module)
apply plugin: 'de.mannodermaus.android-junit5'
dependencies {
...
testImplementation "org.junit.jupiter:junit-jupiter-api:X.X.X"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:X.X.X"
testImplementation "org.junit.jupiter:junit-jupiter-params:X.X.X"
testImplementation "io.mockk:mockk:X.X.X"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:X.X.X"
testImplementation "org.assertj:assertj-core:X.X.X"
@adam-hurwitz
adam-hurwitz / FeedViewTest.kt
Last active October 4, 2020 01:32
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Verify and Confirm
...
private lateinit var test: FeedViewTestCase
...
@ParameterizedTest
@MethodSource("FeedViewTestCaseStream")
fun `FeedView`(feedViewTestCase: FeedViewTestCase) = testCoroutineDispatcher.runBlockingTest {
test = feedViewTestCase
mockComponents(test)
val viewModel = FeedViewModel(...)
@adam-hurwitz
adam-hurwitz / FeedViewTest.kt
Last active October 4, 2020 09:16
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Init Intent and Render State
private lateinit var test: FeedViewTestCase
private val intent = FeedViewIntent()
@ParameterizedTest
@MethodSource("FeedViewTestCaseStream")
fun `FeedView`(feedViewTestCase: FeedViewTestCase) = testCoroutineDispatcher.runBlockingTest {
test = feedViewTestCase
mockComponents(test)
val viewModel = FeedViewModel(...)
viewModel.bindIntents(object : FeedView {