Skip to content

Instantly share code, notes, and snippets.

@ronshapiro
ronshapiro / main.ts
Last active October 29, 2023 12:24
Typescript rewriting constructor properties
class F {
constructor(protected a: string) {
console.log("F.a", a);
console.log("F.this.a", this.a);
}
b() {
console.log("F.b.this.a", this.a);
}
}

Most Dagger errors are in the format:

src/main/java/dagger/playground/Playground.java:20: [Dagger/DuplicateBindings] dagger.playground.E is bound multiple times:
  A a();
    ^
      @Provides dagger.playground.E dagger.playground.Mod.first()
      @Provides dagger.playground.E dagger.playground.Mod.second()
  
      dagger.playground.E is injected at
@ronshapiro
ronshapiro / MonolithicActivityInjector.java
Created November 8, 2017 02:15
dagger.android without O(N) subcomponents
@Subcomponent
public abstract class MonolithicActivityInjector implements AndroidInjector<Activity> {
@Override
public final void inject(Activity activity) {
if (activity instanceof RedActivity) {
inject((RedActivity) activity);
} else if (activity instanceof BlueActivity) {
inject((BlueActivity) activity);
} else if (activity instanceof YellowActivity) {
inject((YellowActivity) activity);
@ronshapiro
ronshapiro / dagger-android-view.md
Last active April 24, 2024 00:19
dagger.android for views in ~10 minutes

1. You can implement View.getActivity() like this:

public interface ViewWithActivity {
  // Using android-gradle-plugin 3.0, which has the desugar step for default methods on interfaces
  default Activity getActivity() {
    // https://android.googlesource.com/platform/frameworks/support/+/03e0f3daf3c97ee95cd78b2f07bc9c1be05d43db/v7/mediarouter/src/android/support/v7/app/MediaRouteButton.java#276
    Context context = getContext();
    while (context instanceof ContextWrapper) {
      if (context instanceof Activity) {
@ronshapiro
ronshapiro / ReusableInjection.kt
Created October 2, 2017 14:26 — forked from ZacSweers/ReusableInjection.kt
Reusable injections
class Parent {
// Somewhere in here, a lot of external service modules are included and contribute their `Service` impls to this multibinding
@Inject lateinit var services: Map<String, Provider<Service>>
fun showChild() {
addChildController(serviceKey = "barServiceKey") // Key into the services map
}
}
@ronshapiro
ronshapiro / android_local_variables.xml
Created November 22, 2015 02:41
Sometimes I wish you could define inline resource values in Android XML that are scoped within their XML subtree.
<LinearLayout
android:variable:dimen:textSize="18sp">
<TextView
android:variable:dimen:paddingStartEnd="16dp"
android:variable:dimen:paddingTopBottom="16dp"
android:paddingStart="@local/paddingStartEnd"
android:paddingEnd="@local/paddingStartEnd"
android:paddingTop="@local/paddingTopBottom"
android:paddingBottom="@local/paddingTopBottom"
@ronshapiro
ronshapiro / build.gradle
Created June 29, 2015 16:25
GIT_SHA in crashlytics version
def VERSION_NAME = "1.0.0"
def GIT_SHA = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
android {
defaultConfig {
versionName VERSION_NAME
}
buildTypes {
debug {
@ronshapiro
ronshapiro / iOS_Android_Vocab_Cheat_Sheet.md
Last active February 1, 2023 07:54
iOS <> Android Vocab Cheat Sheet

iOS <> Android Vocab Cheat Sheet

A couple months ago while at Venmo, @chrismaddern and I discussed the lack of a bidirectional dictionary/vocab list of parallel terms in Android and iOS. It's important to know what your teammates are refering when they talk about code, even if you're not engaged with it every day. This is a beginning attempt to finally break down that knowledge gap. The goal is to allow developers of one framework to understand the basics of the other and should someone want to make the switch, this can be a resource in helping learn the new framework.

If there's a topic that you think would be interesting to discuss, tweet at me and we'll get include it in this list. I'll be updating this post with links to all future posts.

Disclaimer: I'm an Android developer and have done minimal iOS/Objective-C programming. If there is anything incorrect, reach out and I'll fix it as soon as possible. I'm assuming iOS developer are

package com.venmo.views;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@ronshapiro
ronshapiro / VenmoTestRunner.java
Last active August 29, 2015 14:04
An adapted version of https://code.google.com/p/android-test-kit/wiki/DisablingAnimations configured as a InstrumentationTestRunner
package com.venmo.tests;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner;