Skip to content

Instantly share code, notes, and snippets.

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/ [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 /
Created November 8, 2017 02:15 without O(N) subcomponents
public abstract class MonolithicActivityInjector implements AndroidInjector<Activity> {
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 /
Last active April 24, 2024 00:19 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() {
    Context context = getContext();
    while (context instanceof ContextWrapper) {
      if (context instanceof Activity) {
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 / 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.
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 /
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;
ronshapiro /
Last active August 29, 2015 14:04
An adapted version of configured as a InstrumentationTestRunner
package com.venmo.tests;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;