Skip to content

Instantly share code, notes, and snippets.

View rahulsainani's full-sized avatar

Rahul Sainani rahulsainani

View GitHub Profile
@objcode
objcode / Stars.kt
Last active December 9, 2021 10:00
A quick animation exploration drawing a star field using Compose
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@DavidIbrahim
DavidIbrahim / DashedBorder.kt
Last active April 17, 2024 13:32
dashedBorder modifier for android compose
import androidx.compose.foundation.BorderStroke
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@marcellogalhardo
marcellogalhardo / LifecycleCollect.kt
Last active June 3, 2021 08:46
Utility functions to collect coroutines Flow respecting Android's Lifecycle.
package dev.marcellogalhardo.lifecycle
import android.app.Activity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
@objcode
objcode / Permissions.kt
Last active February 21, 2023 23:01
Quick demo of compose permissions using activity result API. Uses Flow instead of State to make it reusable outside of Compose.
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@emmaguy
emmaguy / textcolor-stats.kts
Created February 17, 2020 12:41
Look at all Android layout files and collate what value is set for 'android:textColor' and count the usages of each
val textColorsUsed = mutableMapOf<String, Int>()
File("../").walkTopDown().forEach { file ->
if (file.isFile && file.extension == "xml" && file.path.contains("res/layout")) {
val builder: DocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
val xmlInput = InputSource(StringReader(file.readText()))
val doc: Document = builder.parse(xmlInput)
val androidViews = XPathFactory.newInstance()
.newXPath()
@objcode
objcode / ConcurrencyHelpers.kt
Last active January 15, 2024 05:17
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@RBusarow
RBusarow / TestCoroutineExtension.kt
Last active November 20, 2023 19:03
A JUnit 4 Rule and JUnit 5 Extension for utilizing TestCoroutineDispatcher and TestCoroutineScope from kotlinx.coroutines-test
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext
@raulraja
raulraja / di.kt
Last active October 30, 2021 16:30
Simple Kotlin DI
package com.fortyseven.fptraining
import arrow.core.Either
import arrow.core.right
import arrow.effects.IO
import arrow.effects.extensions.io.fx.fx
data class Account(val balance: Int)
data class AccountEntity(val balance: Int)
@mrk-han
mrk-han / emulator-install-using-avdmanager.md
Last active May 1, 2024 21:12
Installing and creating Emulators with AVDMANAGER (For Continuous Integration Server or Local Use)

Install and Create Emulators using AVDMANAGER and SDKMANAGER

TL;DR

For an emulator that mimics a Pixel 5 Device with Google APIs and ARM architecture (for an M1/M2 Macbook):

  1. List All System Images Available for Download: sdkmanager --list | grep system-images

  2. Download Image: sdkmanager --install "system-images;android-30;google_atd;arm64-v8a"

@paramsen
paramsen / build.groovy
Last active January 17, 2024 08:17
Generate Android version code from git count in Gradle (build.gradle)
// Generate a minor version code from git commit count (for prod builds)
static def generateVersionCode() {
def result = "git rev-list HEAD --count".execute().text.trim() //unix
if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() //windows
if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
return result.toInteger()
}
def majorVersion = 1