Skip to content

Instantly share code, notes, and snippets.

View bagus2x's full-sized avatar
🎯
Focusing

tubagus saifulloh bagus2x

🎯
Focusing
View GitHub Profile
@bagus2x
bagus2x / README.md
Last active April 11, 2024 12:34
README.md

Hi 👋, I'm Tubagus

A passionate frontend developer from Indonesia

bagus2x

Connect with me:

Languages and Tools:

@bagus2x
bagus2x / rest-client.ts
Last active December 6, 2023 08:42
Useful rest client interceptor with next-auth 5 and nextjs fetch.
import { auth } from '@pengode/auth'
const getBearer = async () => {
const session = await auth()
if (!session?.user.accessToken) return
return `Bearer ${session.user.accessToken}`
}
@bagus2x
bagus2x / null.go
Created April 28, 2023 15:59
Golang nullable with generic
type Null[T any] struct {
Value T
Valid bool
Set bool
}
func (n *Null[T]) UnmarshalJSON(data []byte) error {
n.Set = true
if string(data) == "null" {
@bagus2x
bagus2x / TwitterDatePicker.kt
Created March 22, 2023 18:16
Jetpack compose twitter date picker (dob). Jetpack Compose scrollable date picker.
package bagus2x.sosmed.presentation.common.components
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.pager.VerticalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.MaterialTheme
@bagus2x
bagus2x / ExoPlayerState.kt
Created March 19, 2023 06:46
Observe exoplayer state / Player.Listener in jetpack compose
class ExoPlayerState(
context: Context,
private val scope: CoroutineScope
) : ExoPlayer by ExoPlayer.Builder(context).build(), Player.Listener {
@get:JvmName("playing")
var isPlaying by mutableStateOf(false)
private set
var duration by mutableStateOf(0.seconds)
private set
var currentPosition by mutableStateOf(0.seconds)
@bagus2x
bagus2x / GradientMessageInstagram.kt
Last active April 2, 2023 13:14
Gradient background in LazyColumn items. Instagram message style in jetpack compose
@Composable
fun NotificationScreen(
navController: NavController,
viewModel: NotificationViewModel = hiltViewModel()
) {
val videos by viewModel.videos.collectAsStateWithLifecycle()
val listState = rememberLazyListState()
BoxWithConstraints {
val density = LocalDensity.current
@bagus2x
bagus2x / CommentListScreen.kt
Created February 25, 2023 01:10
Display nested comment system with LazyColumn Jetpack Compose
fun CommentListScreen() {
val comments by produceDummyComments(10000)
Box {
LazyColumn(
modifier = Modifier
.systemBarsPadding()
.fillMaxSize(),
) {
commentList(comments)
}
@bagus2x
bagus2x / materialized_path_generator.sql
Created January 25, 2023 20:57
a postgres function to generate materialized path (ltree)
create or replace function create_path(parent_id_param bigint) returns ltree
language plpgsql
as
$$
declare parent_path ltree;
declare current_id BIGINT;
BEGIN
SELECT currval('"comment_id_seq"') into current_id;
IF parent_id_param is NOT NULL THEN
@bagus2x
bagus2x / RatingBar.kt
Created October 11, 2022 03:46
Rating Bar Jetpack Compose with onClick Handler
@Composable
fun RatingBar(
rating: Float,
onChange: (Int, Float) -> Unit,
max: Int
) {
Row {
val value = rating * max
val fullStar = value.toInt()
var fractionStar = value - fullStar
@bagus2x
bagus2x / Calendar.kt
Last active April 4, 2023 17:19
custom calendar with jetpack compose & java.time
private val DaysInMonthCell = GridCells.Fixed(count = 7)
@Composable
fun Calendar(
modifier: Modifier = Modifier,
localDateTime: LocalDateTime
) {
val firstDate = remember(localDateTime) {
with(localDateTime) {
val firstOfMonth = withDayOfMonth(1)