Skip to content

Instantly share code, notes, and snippets.

View surajsau's full-sized avatar
🙇‍♂️
よろしくお願いします!

Suraj Kumar Sau surajsau

🙇‍♂️
よろしくお願いします!
View GitHub Profile
@surajsau
surajsau / PinnableSample.kt
Created February 20, 2023 13:11
PinnableItem in Compose 1.4.0
@Composable
fun PinnableItemSample(modifier: Modifier = Modifier) {
LazyColumn(
modifier = modifier
.background(color = Color.LightGray)
) {
items(5, key = { it + 1 }) {
ListItem(
modifier = Modifier.fillMaxWidth().padding(all = 16.dp),
item = it + 1
Box(
modifier = Modifier
.offset {
// [1]
IntOffset(
x = (roll * 0.9).dp.roundToPx(),
y = -(pitch * 0.9).dp.roundToPx()
)
}
// [2]
@surajsau
surajsau / ParallaxScreen.kt
Last active April 16, 2024 13:53
Parallax effect with Jetpack Compose
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@surajsau
surajsau / OAuthInterceptor.kt
Created April 8, 2022 10:47
HERE Platform Request OAuth 2.0 Token API's HeaderInterceptor
/*
Reference link: https://developer.here.com/documentation/identity-access-management/dev_guide/topics/sdk.html
*/
class OAuthInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val timeStampInMillis = System.currentTimeMillis()
val request = chain.request()
@surajsau
surajsau / A Note.kt
Last active December 2, 2021 13:21
Google Translate Draw with Jetpack Compose
This is a sample note since first file isn't being recognised in Medium.
@surajsau
surajsau / DragDropList.kt
Last active January 14, 2024 13:05
Drag-n-Drop implementation in Jetpack Compose
@Composable
fun DragDropList(
items: List<ReorderItem>,
onMove: (Int, Int) -> Unit,
modifier: Modifier = Modifier
) {
val scope = rememberCoroutineScope()
var overscrollJob by remember { mutableStateOf<Job?>(null) }
@surajsau
surajsau / CheckOverscroll.kt
Last active August 31, 2021 11:37
Reorderable list in Jetpack Compose
fun checkForOverScroll(): Float {
return initiallyDraggedElement?.let {
val startOffset = it.offset + draggedDistance
val endOffset = it.offsetEnd + draggedDistance
val viewPortStart = lazyListState.layoutInfo.viewportStartOffset
val viewPortEnd = lazyListState.layoutInfo.viewportEndOffset
when {
draggedDistance > 0 -> (endOffset - viewPortEnd).takeIf { diff -> diff > 0 }
draggedDistance < 0 -> (startOffset - viewPortStart).takeIf { diff -> diff < 0 }
@surajsau
surajsau / timestamp_copy.js
Created June 26, 2021 11:42
[Bookmarklet] Copy youtube link at the current timestamp
javascript: (
function (){
var e = document.createElement('input');
let ts = document.getElementsByClassName('time-first')[0].innerHTML;
let parts = ts.split(':');
var inSeconds = 0;
if (parts.length == 3) {
inSeconds = (+parts[0]) * 3600 + (+parts[1]) * 60 + (+parts[2]);
@surajsau
surajsau / launch-web-page.sh
Created April 28, 2021 12:48
Tiny script to launch httpd to test links with custom URL scheme (ref: https://gist.github.com/thedoritos/91b086e46ea6da7c943b8fe4e910a22c)
#!/bin/bash
# public/index.html
#
# <!DOCTYPE html>
# <html>
# <head>
# <title>URL Schemes</title>
# <meta charset="UTF-8">
# <meta name="viewport" content="width=device-width, initial-scale=1">
@surajsau
surajsau / deeplink.kts
Created April 25, 2021 06:24
Sample deeplink script using ki