Skip to content

Instantly share code, notes, and snippets.

View elihart's full-sized avatar

Eli Hart elihart

  • Airbnb
  • San Francisco
View GitHub Profile
@elihart
elihart / gist:dd1815e2aa18656120fd
Last active August 29, 2015 14:16
RequestManager
public class TestFragment extends AirFragment {
private static final int REQUEST_MANAGER_ID = 1;
@Inject RequestManager mRequestManager;
private RequestListener mListener = new RequestListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
@elihart
elihart / gist:e85c782356373040c1c6
Created February 25, 2015 22:43
Compare upload phrases methods
require 'time'
require 'json'
require "rexml/document"
# Get the secret from monorail's encrypted databag
# (e.g. /srv/airbnb/on/config/configatron/secure.yml)
# under `api_private_translate`, `secret`.
SECRET = ARGV[0]
URL = 'https://www.airbnb.com'
@elihart
elihart / EpoxyGlidePreloader.kt
Last active October 18, 2021 14:47
Utility to set up a RecyclerView scroll listener that enables preloading support with Glide in Epoxy library usages.
package com.airbnb.epoxy
import android.content.Context
import android.graphics.Bitmap
import android.support.annotation.IdRes
import android.support.annotation.Px
import android.support.v7.widget.RecyclerView
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
@elihart
elihart / CyclicAdapter.java
Last active February 11, 2022 14:21
Cyclic Adapter: An Android RecyclerView Adapter that supports endless cyclical scrolling
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.AdapterDataObserver;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.ViewGroup;
import java.util.List;
/**
* This Adapter class wraps another Adapter in order to support cyclical scrolling.
@elihart
elihart / FileEditor.kt
Created May 10, 2019 03:23
Kotlin File extension for easily editing the contents of a file
/**
* Edit the contents of a File with a [FileEditor]. The new contents will override the old.
*
* @param lineTransform Called with each line of the file in order.
* Return the new value you would like written in the file, or null to delete the line.
* You can also call [FileEditor.insertNext] to insert a line immediately above the given line, or
* [FileEditor.insertPrevious] to insert a line immediately after the given line.
*/
fun File.edit(lineTransform: FileEditor.(line: String) -> String) {
FileEditor(this).edit(lineTransform)
@elihart
elihart / MvrxEpoxyFormExample.kt
Last active October 29, 2019 06:51
Example edit text simple form with MvRx and Epoxy
// MvRx setup
data class MyState(
val text: String? = null
)
class MyViewModel : MvRxViewModel() {
fun setText(newText: String) {
setState {
copy(text = newText)
@elihart
elihart / MvRxHelloWorld.kt
Created November 20, 2019 17:19
MvRx Hello World Example
data class MyState(val text: String = "Hello World") : MvRxState
class MyViewModel(state: MyState) : BaseMvRxViewModel<MyState>(state)
class MyFragment : MvRxFragment() {
val viewModel: MyViewModel by fragmentViewModel()
fun epoxyController() = simpleController(viewModel) { state ->
textRow {
@elihart
elihart / MvRxMockDeclarationExample.kt
Created November 20, 2019 17:25
MvRx Mock Declaration Example
class DadJokeFragment : MvRxFragment() {
val viewModel: DadJokeViewModel by fragmentViewModel()
override fun provideMocks() = mockSingleViewModel(
viewModelReference = DadJokeFragment::viewModel,
defaultState = mockDadJokeState
)
}
@elihart
elihart / MvRxDadJokeMockExample.kt
Created November 20, 2019 17:28
MvRx Mock State Example
val mockDadJokeState = DadJokeState(
jokes = Success(
value = JokesResponse(
nextPage = 3,
results = listOf(
Joke(
id = "0LuXvkq4Muc",
joke = "I'm tired of following my dreams. I'm just going to ask them where they are going and meet up with them later."
),
Joke(
@elihart
elihart / MvRxMockVariantDslExample.kt
Created November 20, 2019 17:30
MvRx Mock Variant DSL Example
override fun provideMocks() = mockSingleViewModel(
viewModelReference = DadJokeFragment::viewModel,
defaultState = mockDadJokeState
) {
state("Loading") {
copy(jokes = Loading())
}
state("Empty results") {
copy(jokes = Success(jokes.copy(results = emptyList())))