Skip to content

Instantly share code, notes, and snippets.

View limkhashing's full-sized avatar
:octocat:
When there is a challenge, there is an opportunity

Lim Kha Shing limkhashing

:octocat:
When there is a challenge, there is an opportunity
View GitHub Profile

General Mobile code style & Best Practices

Mobile Code Style & Best Practices

COMMON

Avoid Heavily Nested Code. Break into steps and Return Early Nested code are harder to read and as a result you often forget to handle certain edge cases. Nested code also makes your code march to the right hand side of the editor, which make hard to read code even harder to read on a small screen.

@limkhashing
limkhashing / android_staging.yml
Last active November 22, 2023 19:35
GitHub Actions Android workflow and upload debug apk to Firebase App Distribution
name: Android Staging CI/CD
on:
pull_request:
types: [synchronize, opened, reopened, ready_for_review]
branches: [development, base-*, feature/*, chore/*, fix/*, bug/*, initiative/*, hotfix/*, dependabot/*]
paths-ignore:
- '.idea/**'
- '.gitattributes'
- '.github/**.json'
@limkhashing
limkhashing / android_production.yml
Last active November 22, 2023 19:36
GitHub Actions Android workflow with creating GitHub tagging and release
name: Android Production CI/CD
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
types: [synchronize, opened, reopened, ready_for_review]
branches: [master, development]
https://www.briansnotes.io/books/
https://github.com/limkhashing/My-Notes
name: "CodeQL"
run-name: "CodeQL scan on ${{ github.head_ref || github.ref_name }}"
# For CodeQL scan, below are the optimal ways to do it
# 1. Perform scan on weekly basis for master/main branch. Preferably on Monday
# 2. Perform scan on each PR to master/main branch.
# 3. If necessary, we can do scan for each push event in master/main branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
@limkhashing
limkhashing / clean-cache.yml
Created October 29, 2023 18:34
Cleanup caches by a branch
name: Cleanup caches by a branch
on:
pull_request:
types:
- closed
jobs:
clean-cache-on-last-closed-pr-in-a-branch:
runs-on: ubuntu-latest
steps:
@limkhashing
limkhashing / gradle-submit-dependency.yml
Last active October 29, 2023 18:35
Gradle submit dependency graph
name: Gradle submit dependency graph
on:
push:
branches: [master]
env:
# Keystore Password
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "gradle" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
@limkhashing
limkhashing / ObserveEvents.kt
Last active February 15, 2026 10:58
Kotlin Coroutines StateFlow "State way" for One-off event. Observe from Screen
/**
* Safely collects one-time events from a Flow while respecting lifecycle.
* Events are consumed exactly once and not re-triggered on recomposition.
*
* This is the recommended pattern for handling navigation events, snackbars,
* and other side effects that should only happen once.
*
* Uses Dispatchers.Main.immediate to ensure events are processed immediately
* without an additional dispatch, which is important for navigation events.
*
@limkhashing
limkhashing / Writing comments for your code.md
Last active January 4, 2024 18:30
The Right Way to Document Your Code

The Right Way to Document Your Code

  1. Readable code means we just read the code like a book, without process alot of logic behind our brain.

    • And rather understand rightaway what a piece of code does
  2. Boolean expression should always keep in positive expression to minimize cognitive load

  3. Comment the why, not the what.

    • Don't add comment explaining what the code did, all you're doing is adding noise to the code
    • Comments should be used only to explain the intent behind code that cannot be refactored to explain itself.
  • Mostly used for providing additional context, i.e. answering the WHY not the WHAT.