Skip to content

Instantly share code, notes, and snippets.

View gmk57's full-sized avatar

George Kropotkin gmk57

View GitHub Profile
@gildor
gildor / OkHttpDownloader.kt
Last active June 19, 2021 07:35
Simple non-blocking extension function for OkHttp Call that wraps request to Kotlin Coroutine and saves response to File
import kotlinx.coroutines.experimental.*
import okhttp3.*
import okio.Buffer
import okio.Okio
import java.io.File
import java.io.IOException
/**
* Custom coroutine dispatcher for blocking calls
*/
@fabiomsr
fabiomsr / ByteArray.kt
Last active April 24, 2024 08:41
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])