Posts

The Very Basics of Android: Tasks, Activities, and the Backstack

Image
Welcome to The Very Basics of Android ! This series is aimed at folks just starting out on Android, and the goal is by the end of the series, you should be familiar enough with common Android topics to be able to go on to other intro materials. To start, this first article will discuss the terminology we use when talking about the UI of the app: Tasks, Activities, and the Backstack. Go onto your Android phone, and click on the small square button at the bottom of the screen. This screen represents all of the tasks running that you have opened! Here's what it looks like on my screen: As you can see, I most recently opened Duolingo and second most recently opened the calculator app, so I have a Duolingo task as well as a calculator task. Each one of these tasks is just a stack of "webpages", called the backstack . Each one of these "webpages" we call an activity . Here's my artist's rendition of what this looks like: When browsing a webpage, you are clicki...

Reading "The Design of Everyday Things"

Life so far It's been a tough 2022 so far. I'm burned out at work, my grandpa is ill, my old car broke down, etc. Hence the general lack of motivation to write anything. I feel like this year will be learning year for me, where I get my ass handed to me by life, and I come out of it battered but more mature. In this vein of learning, I've been trying to institute a few changes in my life to help alleviate some of the things that are going on in my life. Basically, try to stay in control of my life as much as I can. A few basic ones: Work exactly 8 hours a day and push back on deadlines that would require working more than 8 hours a day. Write every so often. In my blog, in my random notebooks. Keep in contact with family. Keep my girlfriend in the loop about my stresses and struggles (she's a psych major!) Always be learning something new. Let's hope everything works out! *knock on wood* Reading "The Design of Everyday Things" In terms of my goal to always...

Thinking about fuzzy logic and implementing black boxes

Today, Google did a doodle about Dr. Lotfi Zadeh who published a paper that proposed fuzzy logic. It feels like it's been forever since I studied anything that has to do with machine learning so I decided why not, let me learn a bit about this. It turns out, fuzzy logic is actually really applicable to my job (which involves no machine learning at all) not because I need to implement a bunch of ambiguous things on the app (although dealing with ambiguity is a big part of the job) but it proposes a really neat way to think about constructing a black box. First, my understanding of a fuzzy system. It is effectively a black box, with rules that you can configure. You feed in your raw data on one end, it goes through the "fuzzifier", the "inference engine", the "defuzzifier" and some new data emerges from the other end. The core of this box is the inference engine. Basically, this part of the system holds the rules that you and your product folks come up w...

Scary Spookvember: Regex!

Image
This is the first blog post in a new series of blog posts that involves me learning and blogging about things that scare developers. I came up with this idea basically right after Halloween ended, so unfortunately this has to be the Scary Spookvember series now instead of Spooktober, which would've made more sense 🤦. This first article is about Regex. Many developers think of it as like a template that can match strings, but actually, Regex is a simple programming language! To show this, let's take a look at a simple Regex that matches a simple lowercase UUID, such as e81dd3ba-44bb-11ec-81d3-0242ac130003 . The Regex that I found on stack overflow is: \b([0-9a-f]){8}-([0-9a-f]){4}-([0-9a-f]){4}-([0-9a-f]){4}-([0-9a-f]){12}\b At first glance, this looks quite confusing and scary, but once we reformat it a bit, things begin to start taking shape: \b # match the beginning or end of a word ( [0-9a-f] # match any character from 0-9 or a-f ) {8} # loop 8 times - # match the...

Link Prediction Using Friends Common ++

Image
Imagine the following scenario: You are provided a list of people in a conference, and you can see all of their Facebook friends. You want to know which people probably know each other. How can you do that in a way that is efficient?  Idea 0: If they are FB friends, then they are probably real life friends Right off the bat, you know that if somebody at the conference is Facebook friends with another person at the conference, then they're very likely to know each other. This is pretty quick to compute. You just build a map of conference goers to Facebook Friends, then go through all their Facebook Friends and check if they are a conference goer. However, now that we know who probably directly knows each other based on their Facebook friends, how can we figure out who might know each other at the conference but have not added each other on Facebook? Idea 1: Count the number of common Facebook friends One easy way to do this would be to say, for any two people, the more Facebook frie...

Supporting RTL languages on Android, Bidi (Bidirectional) text

Recently I've found myself spending a lot of time trying to make sure things look nice on both LTR as well as RTL locales, so that folks with UIs in Arabic, Hebrew, Persian, or Urdu can also have an A+ experience on Android. I ran into an annoying problem where international phone numbers, such as +9708675309 would show up in the app as 9708675309+. The issue was that in RTL languages, numbers should be LTR, so the phone number portion was displayed correctly, but unfortunately the + was displayed on the right side of the phone number. After a good amount of Googling, the fix is actually really simple. Just place the Left-to-Right Isolate Unicode mark on the left of the text you want to be LTR, and then place the Pop Directional Isolate Unicode mark on the right of the text, so that it doesn't make the entire rest of the text LTR. It looked sort of like this in Kotlin: "\u2066+9708675309\u2069" and it worked like a charm!

A list of useful RxJava things!

Over the past year I've learned a bunch of useful tricks for RxJava, and I'm gonna post them here as I remember them or use them. Hopefully this'll grow to a large list/cheatsheet! Here is a way to take the first element multiple flowables that may emit the same data (but loaded from disk or memory or network) and then emit the first one that returns. Concat checks flowable1 first, and then flowable2. I got this from this blog post from Dan Lew . Flowable .concat(flowable1, flowable2) .firstElement() Dan uses it for loading data first from memory, then from disk, and finally from network, so there's a lot of other stuff you can add to it too. He demonstrates how you can use a side effect to create a flowable that saves to network requests to disk and memory whenever you load it from remote: val cache: Flowable<Data> = ... val network: Flowable<Data> = ... val networkWithCaching: Flowable<Data> = network .doOnNext { data -> add...