Server vs mobile development: Where the code runs matter

When the code runs on your servers, you have much more control over the “context” in which it runs. On the mobile devices, the device OS and the user control the context. This difference leads to some subtle implications. One significant set of differences comes from the lack of control of the platform. For server-side code, one can choose from a wide array of languages. For the mobile code, however, the best choice would almost always be the one dictated by the platform - Java/Kotlin on Android and Objective-C/Swift on iOS. Further, for the server-side where one can stick to a particular version of the language. In the case of mobile, the platform controls the language version. Same goes regarding the hardware choices - one can choose to use different types of server machines specialized in handling those jobs, eg. GPUs for math-intensive computes. While for the mobile-code, one had to write a good enough fallback to support a wide-enough set the devices. Similarly, the server-side has to rarely worry about the server killing a running process while it is normal for mobile OSes to kill backgrounded processes eventually. ...

Google I/O 2018: Android Notes

Highlights All android support library code is moving to the androidx namespace. No more android.support.v4 or android. support.v7 namespaces. Android app bundle to split the app into downloadable modules Navigation library to set up navigation between different activities/fragments. Use WorkManager for background work - this is an improvement to JobScheduler Major improvements to Android Studio. Most standalone tools were deprecated in favor of adding the same functionality into Android Studio. Major improvements to Android Vitals which in Google Play to learn more about what’s going on with the Android app’s performance. Android P does more profiling to improve code locality for faster execution. Modern Android Development hierarchy viewer is replaced by ViewTree in Android Studio TraceView is replaced by Systrace in Android Studio Profiler (DDMS) is replaced by Android Profiler in Android Studio Dalvik is replaced by ART Java is replaced by Kotlin as a preferred language Layouts Absolute Layout - deprecated Linear Layout - still OK Frame Layout - still OK Grid Layout - discouraged Relative Layout - discouraged ConstraintLayout - recommended ListView, GridView, and Gallery are deprecated. RecyclerView is recommended with ListAdapter for updations. Platform Fragments (android.app.fragments) are deprecated. Support library fragments are recommended. Single activity app recommended Rather than managing activity lifecycle use Lifecycle to observe state changes Rather than keeping plain data with views, use LiveData to update views automatically. Use ViewModel to deal with screen rotation. Room is recommended in place of SQLite CursorAdapter and AsyncListUtil are discouraged. Use Paging instead with a neat, graceful offline use-case handling trick. Don’t do manual bitmap management. Use Glide, Picasso, or Lottie instead. Between TextureView and SurfaceView, use SurfaceView. Nine patches are discouraged. Use Vector Drawables. Use FusedLocationProviderClient for fetching the device location. Wi-Fi access triangulation is coming to Android P. FusedLocationProvider will eventually add support for that for indoor location tracking. MediaPlayer is discouraged, use ExoPlayer instead. A detailed hands-on presentation on ExoPlayer Performance 42% of 1-star reviews mention crashes/bugs ANR/crash rate reduces engagement - use StrictMode to catch them early Avoid IPC on the main thread, StrictMode won’t catch the violation, and you would never know what’s happening on the other side of the IPC call which can block the main thread If BroadcastReceiver#onReceive is going to take more than 10 seconds, then call goAsync for background processing and call PendingResult#onFinish() once that’s finished WakeLocks - avoid using them. All except PARTIAL_WAKE_LOCK are deprecated with Android P. Use FLAG_KEEP_SCREEN_ON for keeping the screen on in an activity Use WorkManager for background work Use AlarmManager for short-interval callback enums are not discouraged anymore. Platform code avoids it but unlike in prior Android versions, the penalty for enums is low now. A good introduction to Android’s display rendering A good introduction to Android’s text handling Text handling issues Only framework spans can be parceled, don’t mix custom spans with framework spans since only the frameworks will be part of the copied text After ~250 spans or more, SpannableStringBuilder ends up being more performant than SpannableString since the former internally uses trees. Metrics affecting spans cause measure-layout-draw calls, while appearance affecting spans cause layout-draw calls, therefore, the former is more expensive. Text measurement takes a lot of time on the UI thread, consider creating PrecomputedText on the background thread. android:autoLink = true works via RegEx and has bad performance. Consider using Linkify on the background thread. Android P also supports deep learning-based TextClassifier which is also invoked on the background thread. Testing your app for background restriction - adb shell apps set <package name> RUN_ANY_IN_BACKGROUND ignore # applies background restriction (change “ignore” to “allow” to remove restriction) Next Billion Users 28% of searches in India are voice searches 2-wheeler mode added to Google Maps Google Tez uses Ultrasound for pairing and sending money to the nearby receiver Files Go - Folder-based hierarchy won’t work for users who have never had a PC before. Therefore, shows photos based on associations like “WhatsApp Images” or “Camera”. Supports P2P file sharing for fast transfers. Design for next billion users - https://design.google/nbu Android Go 25% of devices in 2018 shipped with <= 1GB RAM (target for Android Go) Every 6 MB app size reduces the installation rate by 1% India - largest market for Go. The USA - is the second-largest market for Go. 5 seconds cold start goal Users opt for smaller apk sizes with a lower rating. The average apk size is 30 MB. Go recommends a 40MB max app size for non-game and 65MB for game apps. MLKit On-device + cloud APIs. On-device APIs are free. Firebase supports downloading models and even doing A/B testing. Experimental support to convert TensorFlow models to TensorFlow Lite models. Compiler D8 - new Dexer, now default. Enable/disable via “android.enableD8 = true/false” R8 - new optimizer, now default replacing proguard, still opt-in in 3.2. Enable via android.enableR8 = true Kotlin - talk can be here Use properties instead of default getters/setters Use data classes to generate equals, hash method, etc. Use default args instead of method overloading Use top-level functions as well as local functions (function inside functions for better encapsulation Use function extensions to make the code more readable, eg. extend String class with isDigit to be able to later write the code like “1234”.isDigit Use smart casts Use sealed classes for a superclass which should not be extendable beyond the compile-time Use string interpolation in println, eg. println(“name is ${name}”) Use val (read-only values) by default, only use var (read-write var iable) when there is a strong reason Declare lambda functions as inline to remove the cost of having an extra class Use co-routines via async instead of creating new threads Use suspend + async to convert callbacks into more readable synchronously written code

Android logo

Android: The right way to pull SQLite database

Here’s the proper way to pull an application’s SQLite database from an Android device.

Skin in the game

Book summary: Skin in the game by Nassim Nicolas Taleb

Skin in the game Skin in the game creates a diversity of beliefs and ideas, for example, restaurant businesses. Lack of it creates a monoculture, for example, journalism. Skin in the game comes with a conflict of interest. For example, a shareholder is more inclined to say positive things about the company, whose shares he holds. Even then, skin in the game is preferable over no skin in the game. A lack of skin in the game, usually, produces a monoculture of beliefs. Bureaucrats, with no skin the game, usually make the problems worse by deciding things from the top. Beware of “good” advice where you will get both the good and the adverse outcomes of that advice while the advice-giver will only get a good result. Metrics puts one’s skin in the wrong game. For example, a doctor who has to optimize for a five-year survival rate of a cancer patient might go for radiation therapy as opposed to laser surgery even though radiation therapy has worse 20-year survival rates. Pilots have more skin in the game than surgeons. If a plane has a 98% chance of surviving a flight, then all pilots would have been dead for now, while medical science can operate with a much lower survival rate since skin in the game is primarily of the patients and much lower of surgeons. An academic experiment where one is supposed to wager a bet and hypothetically believe in a specific scenario is devoid of real risk and hence devoid of skin in the game. Academia, when left unchecked, for the lack of skin in the game, evolves into a ritualistic self-referential publishing game.

How not to be wrong

Book summary: How not to be wrong by Jordan Ellenberg

The book focuses on the application of simple and profound maths to day-to-day life and how not to be deceived by mathematical traps.

Stingray City, Cayman Islands

Escaping into Caribbean with Norwegian Escape Cruise

We took a Norwegian cruise in the western Caribbean. The journey was seven-days long, three days on board, and four days at Falmouth (Jamaica), Georgetown (Cayman Islands), Costa Maya (Mexico), and Great Stirrup Cay (Bahamas). If you are a first-time cruiser, read some of my tips for first-time cruisers. Day 1 & 2 - at the sea The boarding is a bit of a mess. With 5000 passengers boarding and everyone required to assemble in the common area for the security briefing, it was complete chaos for a few hours. ...

Cruise Ship

Some tips for the first time cruisers

How to book - Search and book via a travel agent like Expedia.com or cruisecompete.com. If you have to ask something then these travel agents usually provide way better customer service than the ones employed by the cruise company. Deck - The cruise floors are called decks. Larger the number, higher the deck. Most outdoor activities (including pool, spa, nightclubs) are usually located happen on the higher decks. The lower decks are usually about indoor activities and restaurants. Bidding - If your cruise line permits, always bid for a better room within your budget. Formal Dress - Carry at least one formal dress, it can turn out to be useful for some formal events on the cruise. Diet - Popular dietary restrictions like vegetarian or vegan are not hard for them to meet most of the time. But if you have a more special requirement (like halal diet or kosher), let the cruise ship know in advance. Meals - Usually all cruise ships have a buffet restaurant and multiple dine-in restaurants. Former is quick and contains prepared food. Latter is fancier but takes its own sweet time. The buffet restaurant is usually on the higher deck and is included as a part of the cruise. Some Dine-in restaurants (high brow term: “Speciality restaurants”) are complementary, some are not. An advance reservation is good to have (but not required) for the latter. Beverages - While the standard food is free on the ship. Standard addictions like Soda (soft-drinks), carbonated water, and alcohol (hard-drinks) are not free. If you really need them, buy them in advance, buy them onboard (expensive), buy and consume them whenever ship stops at a new destination or look for a promotional package which includes them for free. Water - Carry a few empty water bottles to refill or even better a hydration pack. A hydration pack is really useful for the day trips at the intermediate stops (fancily called, “port of call”). Shore Excursions - Shore Excursions at the port of call can be booked via cruise ship or on your own. The cruise ship ones are expensive but are a safer bet. If you are adventurous then book them on your own. If you are not, just go with the cruise bookings. Guest service - If you need something from the guest service, catch them early in the morning or late at night. Every other time, I have seen a queue. I wonder if they give out some raffle tickets but I digress.

Binary vs Graded outcomes

Binary vs Graded outcomes

Some activities have binary outcomes while some have graded outcomes. Getting admission into a college is binary, either you get it or you don’t; how well you do in the college is graded. Clearing a job interview is binary, either you get selected or you don’t; how well you do the job isn’t that black and white. Getting a promotion is binary; while a pay raise is usually on a graded scale. Being single or married is binary; while the quality of life, in either case, is graded. ...

January 20, 2018 Â· 1 min #Life      Misc
Two days at Zion National Park

Two days at Zion National Park

Day 1 We did Zion Narrows on the first day. The hike consists of walking in the flowing water, which is ankle to knee-deep. Therefore, getting wetsuits and water shoes is highly recommended. The views are marvelous, and since one has to return along the same route, one can decide how far one wants to go. Total hike length is 9.4 miles, starting at the visitor center. Day 2 We did Angel’s Landing on the second day. It’s a short 5.4 mile with steep elevation gain at the end, which requires one to hold onto chains for climbing upwards. It is similar to Half Dome hike without the long, draining walk till the last dome. Those who fear heights should avoid this. For everyone else, it is an excellent and short fitness test combined with excellent views at the end. ...

Diagnosing Mac apps which won't open (error -10810)

Occasionally, my mac applications end up in a corrupt state where they won’t open. I recently encountered this with Deluge. The first step to diagnose is to open Terminal and open them in the terminal via Sh 1 2 $ open -a deluge # This name is same as the name of the app (minus the ".app" portion). LSOpenURLsWithRole() failed for the application /usr/local/Caskroom/deluge/1.3.12/Deluge.app with error -10810. Now, the error is more diagnosable but still cryptic. Deluge.app above is a directory and we can navigate to the binary located at Deluge.app/Contents/MacOS/Deluge and execute the actual binary to see a more actionable error ...