Skip to content

Instantly share code, notes, and snippets.

View mertceyhan's full-sized avatar
🎯
Focusing

Cafer Mert Ceyhan mertceyhan

🎯
Focusing
View GitHub Profile
@mertceyhan
mertceyhan / TypewriterTextEffect.kt
Created May 8, 2023 13:54
TypewriterTextEffect: A customizable Jetpack Compose function that reveals text with a typewriter-like effect, one chunk at a time
/**
* A composable function that displays a text with a typewriter-like effect, revealing characters in chunks.
*
* @param text The input text to be displayed with the typewriter effect.
* @param minDelayInMillis The minimum delay in milliseconds between revealing character chunks, defaults to 10ms.
* @param maxDelayInMillis The maximum delay in milliseconds between revealing character chunks, defaults to 50ms.
* @param minCharacterChunk The minimum number of characters to reveal at once, defaults to 1.
* @param maxCharacterChunk The maximum number of characters to reveal at once, defaults to 5.
* @param onEffectCompleted A callback function invoked when the entire text has been revealed.
* @param displayTextComposable A composable function that receives the text to display with the typewriter effect.
@mertceyhan
mertceyhan / Screen.kt
Created December 4, 2022 23:40
A base screen composable to send screen view event.
/**
* Add this into AndroidManifest.xml to disable the automatic screen views tracker.
*
* <meta-data
* android:name="google_analytics_automatic_screen_reporting_enabled"
* android:value="false" />
* */
@Composable
fun Screen(
@ExperimentalPagerApi
@Composable
fun WormHorizontalPagerIndicator(
pagerState: PagerState,
modifier: Modifier = Modifier,
activeColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current),
inactiveColor: Color = activeColor.copy(ContentAlpha.disabled),
indicatorWidth: Dp = 8.dp,
activeIndicatorWidth: Dp = 25.dp,
indicatorHeight: Dp = indicatorWidth,
@ExperimentalMaterialApi
@Composable
fun OverlayBottomSheetScaffold(
sheetContent: @Composable ColumnScope.() -> Unit,
scaffoldState: BottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
sheetPeekHeight: Dp = 0.dp,
maxOverlayAlpha: Float = 0.7f,
overlayColor: Color = Color.Black,
cancelable: Boolean = true,
content: @Composable (PaddingValues) -> Unit,
@mertceyhan
mertceyhan / Anagram.kt
Created February 1, 2022 22:35
Answer of classic anagram question with Kotlin
object Anagram {
fun isAnagram(firstText: String, secondText: String): Boolean {
return firstText.sumOf { it.code } == secondText.sumOf { it.code }
}
}
@mertceyhan
mertceyhan / FizzBuzz.kt
Created January 31, 2022 21:31
Answer of classic fizzbuzz question with Kotlin
object FizzBuzz {
fun print() {
for (i in 1..100) {
if ((i.rem(3) == 0) and (i.rem(5) == 0)) {
println("FizzBuzz")
} else if (i.rem(3) == 0) {
println("Fizz")
} else if (i.rem(5) == 0) {
@mertceyhan
mertceyhan / PalindromeDetector.kt
Created January 31, 2022 21:20
Answer of classic palindrome question with Kotlin
object PalindromeDetector {
fun isPalindrome(text: String): Boolean {
val content = text.toCharArray()
val reversedContent = content.reversedArray()
return content.concatToString() == reversedContent.concatToString()
}
}
@mertceyhan
mertceyhan / BubbleSort.kt
Created January 13, 2022 20:48
Bubble Sort in Kotlin
object BubbleSort {
fun sort(array: Array<Int>) {
for (i in array.indices) {
for (j in 0 until array.size - i - 1) {
if (array[j] > array[j + 1]) {
swap(array, firstIndex = j, secondIndex = j + 1)
}
}
}
@mertceyhan
mertceyhan / build.gradle.kts
Last active November 5, 2021 21:14
A logger for Gradle local unit test runner command
// Project level build.gradle file
subprojects {
tasks.withType(Test::class.java) {
testLogging {
showCauses = false
showExceptions = false
showStackTraces = false
showStandardStreams = false
abstract class OnOneOffClickListener(private var defaultInterval: Int,
private val onOneClick: (View) -> Unit) : View.OnClickListener {
private var lastTimeClicked: Long = 0
override fun onClick(view: View) {
if ((SystemClock.elapsedRealtime() - lastTimeClicked) >= (defaultInterval)) {
lastTimeClicked = SystemClock.elapsedRealtime()
onOneClick(view)
}