For when coffee isn’t enough to bring a smile to your face

Image for post
Image for post
Photo by Ben White on Unsplash

As I was looking for some useful coding quotes, I discovered many funny ones. Enjoy reading them — I thought these should be compiled together.

Most are from other sources (as per linked), with the exception of a handful that are my own.

I have separated them down into:

1. The Programming Life 
2. Software Engineering
3. Languages and Logic
4. Platform, Tools, and Administration
5. General

The Programming Life

  1. “Programmer: A machine that turns coffee into code.” (source)
  2. “Computers are fast; programmers keep it slow.” (source)
  3. “When I wrote this code, only God and I understood what I did. Now only God knows.” …


Learning Kotlin Programming

Visualize Kotlin Flow’s s Buffer, Conflate and CollectLatest Easily

Image for post
Image for post
Photo by freestocks on Unsplash

In Kotlin Flow documentation, it share the 3 types of buffers, i.e. Buffer, Conflate, and CollectLatest. They allow the Kotlin Flow to emit elements before the previous one is completely processed, enabling parallelism.

The three buffers operation behave slightly differently. It took me a while to comprehend their differences. Then I realize if I analog them to one fashion adoption, then it’s simple and easy to remember too.

Buffer … the take-all customer


Learning Kotlin Programming

Making learning Kotlin Channels Pipeline easier with diagram

Image for post
Image for post
Photo by Samuel Sianipar on Unsplash

The Kotlin Documentation describing the Channel Pipeline by applying it to a Prime Number generator algorithm.

The code as below, concise and

import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking {
var cur = numbersFrom(2)
repeat(10) {
val prime = cur.receive()
println(prime)
cur = filter(cur, prime)
}
coroutineContext.cancelChildren() // cancel all children to end
}
fun CoroutineScope.numbersFrom(start: Int) = produce<Int> {
var x = start
while (true) send(x++) // infinite stream of integers from start
}
fun CoroutineScope.filter(
numbers: ReceiveChannel<Int>, prime: Int
) = produce<Int> { for (x in numbers) if (x % prime != 0) send(x) }


Sharing Mobile Development

Welcome new writer to contribute to the publication

Image for post
Image for post
Image by Gerd Altmann from Pixabay

The Mobile App Development Publication started back in June 2020, with the intention of having a single publication that shares mobile development across platforms (iOS, Android and others), as noted in the below article.

About slightly more than half a year by, it has grown from its infancy to more than 1000 followers today. My sincere appreciation to all following this publication, which makes the existence of the publication meaningful.

THANK YOU!

As of today, it has 333 articles within, with the home page below having Featured Articles, Latest, Trending, Android App Development, and iOS App Development. …


Learning Kotlin Programming

Sequence is still better than Kotlin Flow sometimes

Image for post
Image for post
Photo by Austrian National Library on Unsplash

Kotlin Flow is one of the newest gadgets in the Kotlin language. It behave like Sequence like processing a stream of information, but with much powerful capability as shared in the below article.

Nonetheless, sequence is still a good collection feature and better than flow sometimes. Below are a few scenarios where sequence is preferred.

By itself, sequence is lighter weight than flow

Flow is developed around coroutine to have its ability to perform things asynchronously, threading, parallel processing, etc.

This does come with extra cost. If we run the below with Sequence

val sequence = (1..100000000).asSequence()
val startTime = System.currentTimeMillis()
fun main() = runBlocking {
val result = sequence
.map { it * 3 }
.filter { it % 2 == 0 }
println("Start")
result
.reduce { ac, it -> ac + it }
.run { println(this) }
println("Done in ${System.currentTimeMillis() …


Learning Kotlin Programming

Do we still need Sequence, after we have Flow?

Image for post
Image for post
Photo by Johann Walter Bantz on Unsplash

Sometime back, I’m curious how is List different from Sequence. I explored into it, and notice Sequence is Lazy and List is Slow. Each have their advantage.

With Kotlin Flow now in place, it behaves like a Sequence.

runBlocking {
(1..3).asSequence()
.map { println("sequence mapping $it"); it * 2 }
.first { it > 2 }
.let { println("sequence $it") }

(1..3).asFlow()
.map { println("flow mapping $it"); it * 2 }
.first { it > 2 }
.let { println("flow result $it") }
}


Learning Kotlin Programming

A rationale on when to use try-catch or catch operator

Image for post
Image for post
Photo by Andy Hall on Unsplash

In the Kotlin Asynchronously Flow documentation, it shows that one can use imperative way (try-catch-finally) and declarative way (catch and onCompletion operator) to handle exception.

However, it states below.

We do not advocate for any particular approach and believe that both options are valid and should be selected according to your own preferences and code style

While the above gives one flexibility, below are my proposal with rationale given.

Perfer declarative exception handler over imperative

Shown below is a simple way of imperative way of catching exception

fun main() = runBlocking<Unit> {
try {

(1..3).asFlow().collect { value ->
check(value <= 1) { "Crash on $value" }
println("Got $value")
}
} catch (e: Throwable) {
println("Caught $e")
} finally {
println("Done")
}…


Learning Android Development

The extra steps to install Charles CA Cert on Android 11

Image for post
Image for post
Photo by NeONBRAND on Unsplash

I have written step by step on setting up Charles Proxy for both iOS Simulator and Android Emulator as below

Beginning Android 11 (SDK API 30), a new security feature has been added for one to install the CA Certification before one can clearly see the data in Charles.

So to get Charles working, just follow the step as the above blog until the part where you install the certification from the chrome browser.

The certification will not be installed automatically, but instead just downloaded. If you click on the downloaded file, you’ll see as below


Learning Android Development

Android App doesn’t just confine to a single application

Image for post
Image for post
Photo by 贝莉儿 DANIST on Unsplash

Most of the time, when we develop an Android App, we build Activity and Fragment. At times to set up the essential dependencies that are used across Activities, we have the Application to store them. When the application is killed, the entire app is completed it’s work.

What if we want something the still work after the application is down? There’s Service.

A Service is an application component that can perform long-running operations in the background

In actual fact, a service is not always run in the background. There are 3 types of services, i.e. background, foreground, and bound.

Here I just look at the background services. In particular the 3 types of services, and in terms of the lifecycle. …


Learning Android Kotlin

Thought there won’t be null crashes if you are not using !! on Kotlin?

Image for post
Image for post
Photo by Ivan Vranić on Unsplash

One of the nice bit of Kotlin compared to Java is its ability to handle nullability. If we have a possible null code, Android Studio will error out during compile time. It is indicated clearly as shown below.

About

Elye

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store