Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jan Rabe kibotu

🎯
Focusing
View GitHub Profile
@kibotu
kibotu / README.md
Created January 26, 2023 08:14
gradle supply chain attack checksum check
View README.md
View SectionItemDecoration.kt
import android.graphics.Canvas
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
/**
* Created with Android Studio
* User: Sergey Petrov s.a.petrov.spb@gmail.com
@kibotu
kibotu / build-json-generator.gradle
Last active July 18, 2022 12:32
Generating build time variables into app/asset folder. Newly support for configuration caching.
View build-json-generator.gradle
/**
* Task to generate build.json and puts it into assets/meta folder within the app.
*/
preBuild.dependsOn tasks.register("generateBuildJson") {
// note: file can't be named 'build.json' otherwise it will not be bundled into the app.
outputs.file(project.rootProject.file('app/src/main/assets/meta.json'))
// need to remember configuration variables for later task execution
@kibotu
kibotu / LruBitmapCache.kt
Last active June 3, 2022 17:59
LruBitmapCache
View LruBitmapCache.kt
import android.graphics.Bitmap
import androidx.collection.LruCache
val runtimeMemoryChunkInBytes: Int
get() = (Runtime.getRuntime().maxMemory() / 8).toInt()
/**
* https://developer.android.com/topic/performance/graphics/cache-bitmap
*/
class LruBitmapCache : LruCache<String, Bitmap>(runtimeMemoryChunkInBytes) {
@kibotu
kibotu / ParallaxScreen.kt
Created June 1, 2022 08:41 — forked from surajsau/ParallaxScreen.kt
Parallax effect with Jetpack Compose
View ParallaxScreen.kt
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@kibotu
kibotu / gource_me.sh
Last active May 25, 2022 14:43
gource & ffmpeg
View gource_me.sh
#!/bin/bash
# https://github.com/acaudwell/Gource
# brew install gource
# brew install ffmpeg
cd "/Users/user/Documents/repositories/my-favorite-project"
gource \
@kibotu
kibotu / extract_app_version.sh
Last active February 2, 2023 12:18
extract_app_version.sh
View extract_app_version.sh
#!/bin/bash
if [ -f "version-properties.gradle" ]; then
APP_VERSION_RAW=$(grep "appVersion *=" version-properties.gradle)
else
echo "Could not detect version-properties.grade file, aborting..."
exit 1
fi
APP_VERSION=$(echo "$APP_VERSION_RAW" | sed 's/[ \"]//g' | awk -F '[=]' '{print $2}')
View WeakReferenceDelegate.kt
import java.lang.ref.WeakReference
import kotlin.reflect.KProperty
inline fun <reified T> weak() = WeakReferenceDelegate<T>()
inline fun <reified T> weak(value: T) = WeakReferenceDelegate(value)
/**
* e.g. var x by weak<Context?>(activity)
@kibotu
kibotu / Context+Extensions.kt
Last active March 21, 2022 14:40
Jetpack Compose get activity in Composable from LocalContext.
View Context+Extensions.kt
// val activity = LocalContext.current.findActivity()
tailrec fun Context.findActivity(): AppCompatActivity? = when (this) {
is AppCompatActivity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}
@kibotu
kibotu / build.gradle
Last active March 29, 2022 15:52
Deploy aab to Huawei AppGallery.
View build.gradle
// based on https://github.com/ferPrieto/steps-app-gallery-deploy/blob/main/step.sh
import groovy.json.JsonSlurper
ext {
def properties = project.gradle.startParameter.projectProperties
println(properties)
// https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agcapi-getstarted-0000001111845114
// IMPORTANT: when creating api key: 'N/A' as Project