Skip to content

Instantly share code, notes, and snippets.

View kafri8889's full-sized avatar
😭
Student

Anaf Naufalian kafri8889

😭
Student
View GitHub Profile
@kafri8889
kafri8889 / DashedDivider.kt
Created June 12, 2022 02:49
Dashed divider in Jetpack Compose
@Preview
@Composable
private fun DashedDividerPreview() {
DashedDivider(
color = Color.Black,
thickness = 1.dp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
@kafri8889
kafri8889 / DateTextField.kt
Last active July 15, 2024 13:55
Date format in TextField Jetpack Compose
@Composable
fun Screen() {
var date by remember {
mutableStateOf(
TextFieldValue(
text = "dd-MM-yyyy"
)
)
}
@Composable
fun SettingPreference(
preference: Preference,
onClick: (Any) -> Unit
) {
when (preference) {
is BasicPreference -> {
BasicPreference(
preference = preference,
onClick = onClick
@kafri8889
kafri8889 / PickerManager.kt
Last active July 22, 2022 02:41
class for picker dialog
/**
@author kafri8889
**/
class PickerManager(
private val context: FragmentActivity,
private val listener: PickerListener
) {
fun datePicker(
data: Any? = null,
@kafri8889
kafri8889 / transformationExmpl.kt
Last active August 14, 2022 00:38
Remove audio from video with ExoPlayer
// inside the composable function
val context = LocalContext.current
var exoPlayer by remember { mutableStateOf<ExoPlayer?>(null) }
val transformerListener = remember {
object : Transformer.Listener {
override fun onTransformationCompleted(inputMediaItem: MediaItem, transformationResult: TransformationResult) {
super.onTransformationCompleted(inputMediaItem, transformationResult)
@kafri8889
kafri8889 / BubbleNotification.kt
Last active December 31, 2023 12:56
BubbleNotification, similar to Snackbar, is on top with enter/exit slide animation
@Composable
fun BubbleNotificationHost(
hostState: BubbleNotificationHostState,
modifier: Modifier = Modifier,
animationSpec: FiniteAnimationSpec<IntOffset> = tween(300),
bubbleNotification: @Composable (BubbleNotificationData) -> Unit = { BubbleNotification(it) },
content: @Composable () -> Unit
) {
val currentBubbleNotificationData = hostState.currentBubbleNotificationData
@kafri8889
kafri8889 / Unre.kt
Created February 19, 2023 10:46
Undo redo feature
class Unre<T> {
private var listener: UnreListener<T>? = null
val stacks: ArrayList<UnreData<T>> = arrayListOf()
var currentStack: Int = -1
private fun modifyStack() {
val newStacks = arrayListOf<UnreData<T>>()
@kafri8889
kafri8889 / Unre.kt
Created July 27, 2023 11:04
Class for undo/redo feature (linked list)
class Unre<T> {
class UnreListNode<T>(var value: T) {
var next: UnreListNode<T>? = null
var prev: UnreListNode<T>? = null
override fun toString(): String {
return "ListNode(${value}, ${next?.toString()})"
}
}
@kafri8889
kafri8889 / python_prime_number.py
Created October 10, 2023 13:59
Cek apakah angka prima atau bukan di python
def isPrimeNumberAndPrint(n):
for i in range(2, n):
if n % i == 0:
print(n, "bukan bilangan prima, karena bisa dibagi dengan", n//i)
return
print(n, "adalah bilangan prima")
@kafri8889
kafri8889 / py_prime_number.py
Last active October 19, 2023 09:01
Check if given number is prime or not
"""
Pertama, buat function yang bernama "isPrimeNumber".
Apa itu ffunction?
Singkatnya function/method adalah suatu blok kode yang melakukan tugas tertentu (sesuai programmernya mau bikin apaan).
salahh satu kegunaan function adl bisa mengurangi boilerplate code (kode yang dipakai berulang kali tanpa perbedaan)
Flownya kayak gini:
INPUT => EKSEKUSI KODE => OUTPUT (opsional)