Skip to content

Instantly share code, notes, and snippets.

@Haoxiqiang
Haoxiqiang / KtorExtensions.kt
Created May 6, 2022 03:38
Ktor support request with gzip on the Android platform.
ktorHttpClient.post("xxxx") {
tryCompress(this, json)
}
private fun tryCompress(httpRequestBuilder: HttpRequestBuilder, json: JSONObject) {
val stringBody = tryCreateRequestBody(json = json)
if (stringBody.length > 4096) {
httpRequestBuilder.body = stringBody.gzipCompress()
httpRequestBuilder.headers[HttpHeaders.ContentEncoding] = "gzip"
} else {
@doole
doole / wine32_macos.org
Last active April 4, 2024 21:16
Use win32 binaries on macOS 10.15/11.0

macOS wine 32/64-bit Setup

Run 32-bit apps on macOS Catalina (10.15) and Big Sur (11.0).

Installation

Dependencies

First install homebrew brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.allocArrayOf
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.usePinned
import platform.Foundation.NSData
import platform.Foundation.create
import platform.posix.memcpy
public fun ByteArray.toData(): NSData = memScoped {
NSData.create(bytes = allocArrayOf(this@toData),
@krishnabhargav
krishnabhargav / kotlin-sealedclass-serialization.kt
Last active March 21, 2024 14:41
Using GSON to support serialization and deserialization of Kotlin Sealed Classes.
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
@JanStoltman
JanStoltman / ApiClientServiceImpl.kt
Last active September 21, 2020 07:53
`backgroundSuspend` method is the same as in DroidconKotlin example. All classes are brought together using Kodein dependency injection.
class ApiClientServiceImpl(
client: HttpClient, parser: JsonParser
) : BaseApiClientService(client, parser) {
override suspend fun getCategories() =
requestCatching(Category.serializer().list) {
get()
apiUrl("/api/product/live/category/list")
accessHeaders()
protocol DogBreed {
typealias Level = Int
var breedName: String { get set }
var size: Level { get set }
var health: Level { get set }
var adaptability: Level { get set }
var intelligence: Level { get set }
var dogType: DogType { get set }
@erkattak
erkattak / AndroidManifest.xml
Created June 19, 2017 18:47
Android Application Setup for use with Charles Proxy
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config">
@JadenGeller
JadenGeller / Cluster.swift
Created March 13, 2017 01:27
Class Cluster
class Number /* class cluser */ {
class Int8: Number {
var value: Swift.Int8
init(_ value: Swift.Int8) { self.value = value }
}
class Int: Number {
var value: Swift.Int
init(_ value: Swift.Int) { self.value = value }
}