Skip to content

Instantly share code, notes, and snippets.

View delacrixmorgan's full-sized avatar
💭
🙉🙈🙊

Morgan Koh delacrixmorgan

💭
🙉🙈🙊
View GitHub Profile
@delacrixmorgan
delacrixmorgan / DrawOutlineLine.kt
Created December 30, 2022 10:26
Compose UI - Outline Button with Lines
val lineThickness = 4F
Modifier
.fillMaxWidth()
.border(
width = lineThickness.dp,
color = Color.Red,
shape = drawOutlineButtonLine(OutlineButtonLine.Top, lineThickness)
)
private fun drawOutlineButtonLine(outlineButtonLine: OutlineButtonLine, lineThickness: Float): Shape {
@delacrixmorgan
delacrixmorgan / Button.kt
Last active December 30, 2022 09:17
Compose UI - Button
package com.peaks.uicomponents.compose
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
@delacrixmorgan
delacrixmorgan / NoRippleTheme.md
Created December 29, 2022 11:08
Compose UI - No Ripple Theme

By default, Android has ripple effect for all clickable objects. If you want to disable the ripple effect, you will need to wrap it in a LocalRippleTheme.

private object NoRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor() = Color.Unspecified

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f)
}

Git Cheatsheet

Fetch from Remote and Delete local branches that doesn't exist in Remote.

alias gt='git fetch -p && git branch -vv | grep "origin/.*: gone]" | awk "{print \\\$1}" | xargs git branch -D'

Flutter Cheatsheet

Create Module

flutter create --template=package module_name
@delacrixmorgan
delacrixmorgan / LocalDateTimeTest.kt
Created February 6, 2022 11:13
Get Days To Unit Test - Lost in Java Time with Android
@Test
fun `Given date and date after 30 days When comparing days apart using getDaysTo Then should return 30 days`() {
val startDate = "2020-01-01T12:34:56Z".toLocalDateTime()
val endDate = "2020-01-31T12:34:56Z".toLocalDateTime()
val expectedDifferenceInDays = 30
val differenceInDays = startDate?.getDaysTo(endDate)?.toInt()
Assert.assertEquals(
"Should be $expectedDifferenceInDays",
@delacrixmorgan
delacrixmorgan / DateExtensions.kt
Last active February 6, 2022 10:56
Transitioning Period - Lost in Java Time with Android
fun LocalDateTime.toDate(): Date = Date.from(
this.atZone(ZoneId.systemDefault())
.toInstant()
)
fun Date.toLocalDateTime(): LocalDateTime = LocalDateTime.ofInstant(
this.toInstant(),
ZoneOffset.UTC
)
@delacrixmorgan
delacrixmorgan / LocalDateTimeExtensions.kt
Last active February 6, 2022 10:56
Convenient Methods - Lost in Java Time with Android
fun LocalDateTime.getDaysTo(to: LocalDateTime?): Long =
ChronoUnit.DAYS.between(this, to)
fun LocalDateTime.getDaysBetween(to: LocalDateTime?): Long =
abs(ChronoUnit.DAYS.between(this, to))
fun LocalDateTime.nextDayOfTheWeek(dayOfWeek: DayOfWeek): LocalDateTime =
this.plusHours(1)
.with(TemporalAdjusters.next(dayOfWeek))
.atZone(ZoneId.systemDefault())
@delacrixmorgan
delacrixmorgan / LocalDateTimeExtensions.kt
Last active February 6, 2022 10:51
DateUtils getRelativeTimeSpanString - Lost in Java Time with Android
fun LocalDateTime.getRelativeTimeSpanString(now: LocalDateTime?): CharSequence? =
DateUtils.getRelativeTimeSpanString(
getEpochMilli(),
(now ?: LocalDateTime.now()).getEpochMilli(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_TIME
)
fun LocalDateTime.getEpochMilli(): Long =
atZone(ZoneId.systemDefault())
@delacrixmorgan
delacrixmorgan / FormatterCheatSheet.md
Last active February 6, 2022 10:51
Formatter Cheat Sheet - Lost in Java Time with Android
Date and Time Pattern Result
yyyy-MM-dd'T'HH:mm:ss'Z' 2020-03-04T18:46:19Z
"yyyy.MM.dd G 'at' HH:mm:ss z" 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy" Wed, Jul 4, '01
"h:mm a" 12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" 02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56 -0700