Skip to content

Instantly share code, notes, and snippets.

Kotlin K2 FIR Example. Related Post: https://handstandsam.com/2024/05/30/kotlin-k2-fir-quickstart-guide/
@joshafeinberg
joshafeinberg / dependency-analysis-config.gradle
Last active July 27, 2022 04:20
Using Version Catalogs with Dependency Analysis Plugin
ext.reversedMap = [:] as Map<String, String>
void buildReversedMap(String versionCatalogName) {
def versionCatalog = rootProject.extensions
.getByType(VersionCatalogsExtension).named(versionCatalogName)
reversedMap = versionCatalog.getDependencyAliases()
.collectEntries { alias ->
def versionCatalogAlias = "${versionCatalogName}.${alias}"
def module = versionCatalog.findDependency(alias).get().get()
def fullModuleName = "${module.getModule()}:${module.getVersionConstraint()}"
@arunkumar9t2
arunkumar9t2 / DependantModulesTask.kt
Last active July 21, 2023 15:43
Gradle task to find reverse dependencies of a module
import com.google.common.graph.Graphs
import com.google.common.graph.MutableValueGraph
import com.google.common.graph.ValueGraphBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
@handstandsam
handstandsam / print_permissions_from_androidmanifest.py
Last active December 14, 2022 10:06
Python Script to parse permissions from an AndroidManifest.xml file, and sort them alphabetically.
from xml.dom.minidom import parseString
# Documentation on Permissions in AndroidManifest.xml
# https://developer.android.com/guide/topics/manifest/manifest-intro#perms
data = '' # string data from file
with open('AndroidManifest.xml', 'r') as f:
data = f.read()
dom = parseString(data) # parse file contents to xml dom
@handstandsam
handstandsam / PokeballCompose.kt
Created January 16, 2022 20:24
Draw a Pokeball on Canvas using Jetpack Compose
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
@bmc08gt
bmc08gt / monkey.gradle
Created July 20, 2021 19:40
Gradle task to piggyback off install task allowing CLI opening of the app.
android.applicationVariants.all { variant ->
task "open${variant.name.capitalize()}" {
dependsOn "install${variant.name.capitalize()}"
doLast {
exec {
commandLine "adb shell monkey -p ${variant.applicationId} -c android.intent.category.LAUNCHER 1".split(" ")
}
}
}
@MarkusKramer
MarkusKramer / Base64.kt
Last active October 29, 2024 14:53
Kotlin Multiplatform Base64 - no extra dependencies. Based on Java's implementation.
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
@epool
epool / BuildXcFramework.kt
Last active December 5, 2023 13:11
Builds a XcFramework from a shared module in KMM.
//region XcFramework tasks
val xcFrameworkPath = "xcframework/${project.name}.xcframework"
tasks.create<Delete>("deleteXcFramework") { delete = setOf(xcFrameworkPath) }
val buildXcFramework by tasks.registering {
dependsOn("deleteXcFramework")
group = "build"
val mode = "Release"
val frameworks = arrayOf("iosArm64", "iosX64")
@antonshilov
antonshilov / TreeRenderer.kt
Last active July 1, 2024 18:49
Simple tree hierarchy rendering with Jetpack Compose
package com.example.myapplication
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.Box
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@dennisstritzke
dennisstritzke / fileEncryption.md
Last active March 6, 2023 21:00
A very short documentation on using OpenSSL keys to encrypt and decrypt files.

Procedure

  1. Create a random key.
  2. Encrypt the random key via an SSH RSA public key
  3. Send the encrypted file and encrypted key
  4. Encrypt the key
  5. Encrypt the file

Create key via

openssl genrsa -out rsa.private 4096