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
object SslUtils { | |
fun getBase64UrlEncodedSha256(publicKey: String): String { | |
return Base64.getUrlEncoder().encodeToString(publicKey.decodeHex()) | |
} | |
private fun String.decodeHex(): ByteArray { | |
check(length % 2 == 0) { "Must have an even length" } | |
return chunked(2) | |
.map { it.toInt(16).toByte() } |
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
ext.getChangeLog = { lastCommitsCount = 10 -> | |
return formatGitLog(getGitLogUntilCommitNumber(lastCommitsCount)) | |
} | |
ext.getReleaseChangeLog = { | |
def lastTag = getLastTag() | |
return formatGitLog(getGitLogUntilTag(lastTag)) | |
} |
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 |
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
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
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 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
// 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
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() |
NewerOlder