Skip to content

Instantly share code, notes, and snippets.

View ProArun's full-sized avatar

Arun Kumar Aditya ProArun

View GitHub Profile
@ProArun
ProArun / day1.1
Created November 13, 2024 17:20
41. First Missing Positive
class Solution {
public int firstMissingPositive(int[] nums) {
// Solution 1
// int result = 1;
// Map<Integer,Integer> map = new HashMap<Integer,Integer>();
// for(int i = 0; i < nums.length; i++ ){
// map.put(nums[i],i);
// }
@ProArun
ProArun / AnnotatedString
Created November 12, 2024 18:05
AnnotatedString
@Composable
fun AnnotatedString(modifier: Modifier = Modifier) {
// Define tags for expanded and minified text
val tagExpanded = "expanded_text"
val tagMinified = "minified_text"
// Maintain the state of text toggling (expanded or minified)
val textToggleState = remember { mutableStateOf(Pair(tagMinified, "Read more ...")) }
@ProArun
ProArun / LazyColumnPosition
Created October 3, 2024 18:35
Save and Restore the Scroll Position of a LazyColumn Persistently
@OptIn(FlowPreview::class)
@Composable
fun LazyColumnPosition(modifier: Modifier = Modifier) {
val context = LocalContext.current
val pref by lazy {
context.getSharedPreferences("prefs", MODE_PRIVATE)
}
val scrollPosition = pref.getInt("scroll_position", 0)
@ProArun
ProArun / AnimatedContentExample
Created October 2, 2024 16:40
AnimatedContent in Jetpack Compose Example 2
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun AnimatedContentExample(modifier: Modifier = Modifier) {
var expanded by remember {
mutableStateOf(false)
}
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Card(modifier = Modifier.clickable {
@ProArun
ProArun / MainCoroutineRule.kt
Last active August 20, 2023 06:33
Coroutine unit test
class MainCoroutineRule : TestWatcher(){
//TestWatcher is class which is use to make JUnit rule.
val testDispatcher = StandardTestDispatcher()
override fun starting(discription: Description?){
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description?){
@ProArun
ProArun / QuoteManagerTest.kt
Created August 19, 2023 17:38
convert instrumentation test to jvm test
class QuoteManagerTest{
@Mock
lateinit var context: Context
@Mock
lateinit var assertManager: AssertManager
@Before
fun setup(){
@ProArun
ProArun / User.kt
Created August 19, 2023 17:21
Mocking using mockito
data class User(
val id:Int,
val name:String,
val email:String,
val password:String
)
enum class LOGIN_STATUS{
INVALID_USER,
INVALID_PASSWORD,
@ProArun
ProArun / LiveDataUtils.kt
Created August 19, 2023 16:32
Room database testing
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
fun <T> LiveData<T>.getOrAwaitValue(
time: Long = 2,
timeUnit: TimeUnit = TimeUnit.SECONDS,
afterObserve: () -> Unit = {}
@ProArun
ProArun / PasswordTest.kt
Created August 19, 2023 15:42
Unit test Example
class PasswordTest{
@Test
fun `validatePassword blank input expected required field`(){
val sut = Utils()
val result = sut.validatePassword(" ")
assertEquals("Password is required field", result)
}
@Test
fun `validatePassword 2CharInput expected validation Msg`(){
@ProArun
ProArun / QuoteManagerTest.kt
Created August 19, 2023 14:53
instrumentation test
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.gson.JsonSyntaxException
import org.junit.Assert.*
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.io.FileNotFoundException