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
@shohiebsense
shohiebsense / AndroidManifest.xml
Created June 9, 2021 13:06
Creating Foreground Service, persistently,even if the app is terminated. Using Dagger.
<manifest>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:allowBackup="true"
android:name=".WhateverApplication">
<service android:name=".services.TrackerService"
android:foregroundServiceType="location"
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 / hosts
Last active October 28, 2021 02:22
Hosts Backup File For Escaping The Trench
This file has been truncated, but you can view the full file.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
@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
}