Skip to content

Instantly share code, notes, and snippets.

View shohiebsense's full-sized avatar
Thunder Breath; 99th Style

Shohieb shohiebsense

Thunder Breath; 99th Style
View GitHub Profile
import (
"context"
//"database/sql"
"fmt"
"log"
"net"
"os"
"github.com/go-sql-driver/mysql"
"golang.org/x/crypto/ssh"
@shohiebsense
shohiebsense / IsRapidRequest.kt
Created December 14, 2022 12:26
Also note that the cache is using the same simpledateformat, ended up as a string
private const val LAST_REQUEST_TIME_MILLISECONDS = "last_request_time_milliseconds"
private val getDateFormat = SimpleDateFormat("dd-hh-mm-ss")
private fun isRapidRequest(lastRequestDateTime: String): Boolean {
if (lastRequestDateTime.isBlank()) return false
val date = getDateFormat.format(Date())
val dateTimeIntArrayList = date.split("-")
val lastDatetimeIntArrayList = lastRequestDateTime.split("-")
@shohiebsense
shohiebsense / ListExtension.kt
Created July 26, 2022 10:28
Filter Using List, Filter and Update Extension
inline fun <T> ArrayList<T>.filterAndUpdateList(predicate: (T) -> Boolean) : List<T> {
return filter(predicate = predicate).also { filteredList ->
this.clear()
this.addAll(filteredList)
}
}
@shohiebsense
shohiebsense / VelocityModifierExt.kt
Created June 29, 2022 07:15
Jetpack Compose Bounce, or Elastic, or Velocity Physics Scrolling. Credit to Android Codelabs; Jetpack Compose Animation
fun Modifier.velocityBouncePhysicsList(
scrollState: ScrollState): Modifier = composed {
if(scrollState.value == 0 || scrollState.value == scrollState.maxValue){
val offsetY = remember { Animatable(0f) }
pointerInput(Unit) {
val decay = splineBasedDecay<Float>(this)
coroutineScope {
while (true) {
val pointerId = awaitPointerEventScope { awaitFirstDown().id }
@shohiebsense
shohiebsense / Dialog.kt
Last active April 14, 2022 07:51
Animated Popup Message
@ExperimentalAnimationApi
@Composable
fun EdufundBackConfirmationDialog(
componentParameter: ComponentParameter,
isDialogTypeBackConfirmation: Boolean,
title: String,
desc: String,
onYesClicked: () -> Unit,
onDismiss: () -> Unit,
testTag: String
@shohiebsense
shohiebsense / Whatever.kt
Last active February 21, 2022 14:57
Animated Pager Indicator Jetpack Compoes
@ExperimentalAnimationApi
@ExperimentalPagerApi
@Composable
fun HorizontalPagerIndicator2(
pagerState: PagerState,
modifier: Modifier = Modifier,
activeColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current),
inactiveColor: Color = activeColor.copy(ContentAlpha.disabled),
indicatorHeight: Dp = 8.dp,
@shohiebsense
shohiebsense / SomePage.kt
Created December 15, 2021 00:11
Custom Modal Bottom Sheet On Jetpack Compose
@Composable
fun SomePage(){
val animatedVisibility = produceState(initialValue = false){
delay(2000)
value = true
}
BoxWithConstraints{
@shohiebsense
shohiebsense / TextFielsState.kt
Last active August 29, 2021 00:20
Prevents Multiple Spaces And Auto Capitalization On TextField
val text = mutableListOf("")
fun onValueChanged(value: String) {
if (!value.isName()) return
val filteredValue = value.replace("\\s+".toRegex(), " ")
if (value.contains("\n")) return
text.value = value
}
@shohiebsense
shohiebsense / AndroidManifest.xml
Created July 2, 2021 09:16
CameraX for targeting SDK 30/Q, using ContentResolver instead of File.
<manifest>
<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application>
@shohiebsense
shohiebsense / Coroutines, Room and LiveData.md
Last active June 28, 2021 06:03
Working with Coroutines, Room, LiveData
  1. Using Room, use the AndroidViewMode(application)
class YourModelViewModel(val database: YourModelDatabaseDao, 
                             application: Application) : AndroidViewModel(application){

}
  1. Add the ViewModelFactory