This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kotlin K2 FIR Example. Related Post: https://handstandsam.com/2024/05/30/kotlin-k2-fir-quickstart-guide/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
import google.generativeai as genai | |
import google.ai.generativelanguage as glm | |
API_KEY="..." | |
genai.configure(api_key=API_KEY) | |
model = genai.GenerativeModel('gemini-pro') | |
prompt = "I want to record a song in the next 30 minutes. I am a good guitar player, and okay singer. Can you come up with a simple song and chord progression? Please provide me with the bpm of the song, and be sure to include the following sections: verse, chorus, verse, chorus, bridge, chorus. This song should be about 3 minutes in length. Ideally it will use power chords on guitar or common major and minor chords on a guitar that is tuned in standard." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun runCmd( | |
cwd: File, | |
cmd: String | |
) = runCatching { | |
println("In cwd ${cwd.path}, Running cmd $cmd") | |
ProcessBuilder("\\s".toRegex().split(cmd)) | |
.directory(cwd) | |
.redirectOutput(ProcessBuilder.Redirect.PIPE) | |
.redirectError(ProcessBuilder.Redirect.PIPE) | |
.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val outputFile = File("output.txt") | |
if(outputFile.exists() { | |
outputFile.delete() | |
} | |
afterEvaluate { | |
project.tasks.forEach { task -> | |
buildString { | |
appendLine("---------------") | |
appendLine("${task.name}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.os.RemoteException | |
import com.android.installreferrer.api.InstallReferrerClient | |
import com.android.installreferrer.api.InstallReferrerStateListener | |
import com.android.installreferrer.api.ReferrerDetails | |
import kotlinx.coroutines.CompletableDeferred | |
/** | |
* https://developer.android.com/google/play/installreferrer/library | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JVM Implementation from KotlinX Coroutines | |
* https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/src/channels/Actor.kt#L31-L124 | |
*/ | |
@ObsoleteCoroutinesApi | |
public fun <E> CoroutineScope.actor( | |
context: CoroutineContext = EmptyCoroutineContext, | |
capacity: Int = 0, // todo: Maybe Channel.DEFAULT here? | |
start: CoroutineStart = CoroutineStart.DEFAULT, | |
onCompletion: CompletionHandler? = null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun DropdownComposable(items: List<String> = listOf("A", "B", "C"), onClick: (String) -> Unit) { | |
var expanded by remember { mutableStateOf(false) } | |
var selectedIndex by remember { mutableStateOf(0) } | |
Box( | |
modifier = Modifier | |
.wrapContentSize(Alignment.TopStart) | |
) { | |
Text( | |
text = state.value.eventName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleRegistry | |
import androidx.savedstate.SavedStateRegistry | |
import androidx.savedstate.SavedStateRegistryController | |
import androidx.savedstate.SavedStateRegistryOwner | |
internal class MyLifecycleOwner : SavedStateRegistryOwner { | |
private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this) | |
private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this) |
NewerOlder