Skip to content

Instantly share code, notes, and snippets.

View alexstyl's full-sized avatar

Alex Styl alexstyl

View GitHub Profile
@alexstyl
alexstyl / SafeContent.kt
Last active May 5, 2022 07:33
A Composable that will keep push its content so that they are not drawn behind the system bars. This is useful for when you want to work on a layout without having to worry about insets.
@Composable
fun SafeContent(
systemBarsColor: Color = Color(0xFF082A3A),
content: @Composable () -> Unit
) {
Box(
modifier = Modifier
.background(systemBarsColor)
.systemBarsPadding()
.background(MaterialTheme.colors.background)
@alexstyl
alexstyl / MachineId.kt
Last active November 3, 2022 14:19
Get MacOS Machine ID
// Java version of node-machine-id. Used to identify a Mac, for software installation or licenses purposes.
// See the node project at https://github.com/automation-stack/node-machine-id
suspend fun machineId(): String {
val platformUUID = getPlatformUUID()
return DigestUtils.sha256Hex(platformUUID)
}
private fun expose(result: String): String {
val startIndex = result.substringAfter("IOPlatformUUID").substringBefore("\n")
@alexstyl
alexstyl / AutoCompleteTextComposable.kt
Created November 13, 2022 04:43
A quick and dirty way to do AutoCompleteTextViews in Jetpack Compose. Needs improvement in the UX (hide cursor when item selected) and nicer API and probably more.
var selectedOptionText by remember { mutableStateOf("") }
val options = listOf("Cupcake", "Donut", "Eclair", "Froyo", "Gingerbread")
val filtered = options
.filter { it.lowercase().contains(selectedOptionText.lowercase()) }
val expanded = selectedOptionText.isNotEmpty() && filtered.isNotEmpty()
&& options.none { it.lowercase() == selectedOptionText.lowercase() }
ExposedDropdownMenuBox(
expanded = expanded,
@alexstyl
alexstyl / MaterialColors.kt
Created May 15, 2023 10:05
All colors found in the 2014 Material Design color palette, ready to be used in Jetpack Compose.
/**
* Contains all color defined in the 2014 Material Design color palette.
*
*
*/
object MaterialColors {
val Red50 = Color(0xFFFFEBEE)
val Red100 = Color(0xFFFFCDD2)
val Red200 = Color(0xFFEF9A9A)
val Red300 = Color(0xFFE57373)
@alexstyl
alexstyl / MainActivity.kt
Created May 19, 2023 13:39 — forked from amarland/SvgDsl.kt
A (very) minimal SVG DSL for Jetpack Compose on Android (inspired by https://twitter.com/alexstyl/status/1659043650238844928).
package com.amarland.simplesvgdsl
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
<script type="text/javascript" src="https://project-reviews.vercel.app/js/iframeResizer.min.js"></script>
<iframe id="appreviews-iframe" src="https://project-reviews.vercel.app/iframe?id=1" frameBorder="0" scrolling="no" width="100%"></iframe>
<script type="text/javascript">iFrameResize({log: false, checkOrigin: false}, "#appreviews-iframe");</script>