Skip to content

Instantly share code, notes, and snippets.

@phatnhse
phatnhse / inline-bytecode-no-lambda.kt
Last active July 29, 2023 00:25
inline-bytecode-no-lambda
fun main() {
print("foo ")
print("bar");
// prints: foo bar
}
@phatnhse
phatnhse / inline-bytecode-lambda.kt
Last active July 29, 2023 00:16
inline-bycode-lamda
// simplified.
fun main() {
print("foo ")
print("bar");
// prints: foo bar
}
@phatnhse
phatnhse / inline-lambda.kt
Created July 29, 2023 00:14
inline-with-lambda
fun main() {
print("foo ")
bar {
print("bar");
}
// prints: foo bar
}
inline fun bar(invoke: () -> Unit) {
invoke()
@phatnhse
phatnhse / inline-no-lambda.kt
Last active July 29, 2023 00:22
inline-without-lamda
fun main() {
print("foo ")
bar()
// prints: foo bar
}
inline fun bar() {
print("bar")
}
@phatnhse
phatnhse / row.kt
Created July 29, 2023 00:13
row-jc
@Composable
inline fun Row(
modifier: Modifier = Modifier,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
verticalAlignment: Alignment.Vertical = Alignment.Top,
content: @Composable RowScope.() -> Unit
) {
// implementation details
}
@phatnhse
phatnhse / jc-sample-custom-row.kt
Last active July 29, 2023 00:55
jc-sample-custom-row
@Composable
fun MyRow(content: @Composable () -> Unit) {
content()
}
@Composable
fun Sample() {
var button1 by remember { mutableStateOf("button 1") }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
@phatnhse
phatnhse / jc-sample-row.kt
Created July 29, 2023 00:12
jc-sample-row
@Composable
fun Sample() {
var button1 by remember { mutableStateOf("button 1") }
var button2 by remember { mutableStateOf("button 2") }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { button1 += "1" }) { Text(text = button1) }
Spacer(modifier = Modifier.height(8.dp))
@phatnhse
phatnhse / jc-sample.kt
Created July 29, 2023 00:11
recompose
@Composable
fun Sample() {
var button1 by remember { mutableStateOf("button 1") }
var button2 by remember { mutableStateOf("button 2") }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Recomposes when `button1` changes, but not when button2 changes
Button(onClick = { button1 += "1" }) { Text(text = button1) }
Spacer(modifier = Modifier.height(8.dp))
@phatnhse
phatnhse / gist:1cc19d2299c6361dea99ad68cc3f79a6
Created July 28, 2023 06:41
simple text field - adjustment - jc
@Composable
private fun SimpleTextField() {
var text by remember { mutableStateOf("") }
TextField(value = text, onValueChange = {
text = it
})
}
resource "aws_ecs_task_definition" "my_simple_task" {
family = "my-task"
container_definitions = <<DEFINITION
[
{
// other configurations
"memory": 512,
"cpu": 256
}
]