This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.room.TypeConverter | |
import java.time.Instant | |
import java.time.LocalDateTime | |
import java.time.ZoneId | |
import java.time.ZoneOffset | |
class Converters { | |
@TypeConverter | |
fun fromLocalDatetime(value: LocalDateTime?): Long? { | |
return value?.atZone(ZoneId.of(ZoneOffset.systemDefault().id))?.toInstant()?.toEpochMilli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.convertToDouble(): Double { | |
val newValue: String = this.replace(",", ".") | |
var withoutExtraDots = "" | |
var indexOfFirstDot: Int? = null | |
var index = 0 | |
for (c in newValue) { | |
if (index == 0 && c == '.') return 0.0 | |
if (indexOfFirstDot == null && c == '.') indexOfFirstDot = index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val PREFS_SEQUENTIAL_REQUEST = "sequential-request-preferences" | |
private const val KEY_LAST_URL = "lastUrl" | |
private const val KEY_LAST_REQUEST_TIME = "lastRequestTime" | |
class SequentialRequestInterceptor(context: Context) : Interceptor { | |
private val preferences = | |
context.getSharedPreferences(PREFS_SEQUENTIAL_REQUEST, Context.MODE_PRIVATE) | |
override fun intercept(chain: Interceptor.Chain): Response { | |
val baseRequest = chain.request() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// O(n) | |
class Solution { | |
fun reverse(x: Int): Int { | |
var reversed = 0 | |
var number = x | |
while (number != 0) { | |
val remainder = number % 10 | |
reversed = reversed * 10 + remainder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.michaelbull.result.Result | |
import com.github.michaelbull.result.onFailure | |
import com.github.michaelbull.result.onSuccess | |
import com.mutkuensert.androidphase.Phase | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | |
import kotlinx.coroutines.flow.asStateFlow | |
import kotlinx.coroutines.launch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.RoundingMode | |
import java.text.DecimalFormat | |
import java.text.DecimalFormatSymbols | |
fun Double.withDecimalDigits(number: Int = 1): Double { | |
var diesisForDecimals = "" | |
repeat(number) { | |
diesisForDecimals += "#" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.paging.ExperimentalPagingApi | |
import androidx.paging.LoadType | |
import androidx.paging.PagingState | |
import androidx.paging.RemoteMediator | |
import com.github.michaelbull.result.Result | |
import com.github.michaelbull.result.get | |
import com.github.michaelbull.result.onFailure | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.withContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.clipString( | |
firstIndex: Int, | |
lastIndex: Int, | |
includeOneChar: Boolean = true | |
): String { | |
var word = "" | |
if (lastIndex >= length) throw IndexOutOfBoundsException() | |
if (firstIndex == lastIndex) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val activityManager = (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) | |
val memoryInfo = ActivityManager.MemoryInfo() | |
activityManager.getMemoryInfo(memoryInfo) | |
val totalMemory = memoryInfo.totalMem |
OlderNewer