Skip to content

Instantly share code, notes, and snippets.

View tahakorkem's full-sized avatar
🔥

Taha Körkem tahakorkem

🔥
View GitHub Profile
@tahakorkem
tahakorkem / Async.kt
Last active July 19, 2023 13:08
Extension functions of parallel iteration over collections in Kotlin (map and forEach equivalents)
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
suspend fun <T> Collection<T>.forEachAsync(action: suspend (T) -> Unit) =
coroutineScope {
map { item ->
async { action(item) }
}.awaitAll()
}
@tahakorkem
tahakorkem / spinner.html
Last active July 18, 2023 16:56
Progress spinner using Tailwind CSS
<!-- stroke width = 3 -->
<svg class="animate-spin h-6 w-6 text-[CHANGE_THIS_COLOR]" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10.5" stroke="currentColor" stroke-width="3"></circle>
<path fill="currentColor"
d="M3,19.9c-1.9-2.2-3-5-3-7.9C0,5.4,5.4,0,12,0v3c-5,0-9,4-9,9c0,2.2,0.8,4.3,2.2,6L3,19.9z"/>
</svg>
<!-- stroke width = 3.5 -->
<svg class="animate-spin h-6 w-6 text-[CHANGE_THIS_COLOR]" xmlns="http://www.w3.org/2000/svg" fill="none"
@tahakorkem
tahakorkem / 1_indeterminate-progress.html
Last active June 9, 2023 16:26
Indeterminate progress bar using Bootstrap
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar"></div>
</div>
@tahakorkem
tahakorkem / 1_Lazy.ts
Last active June 3, 2023 12:54
Lazy Loading Design Pattern in TypeScript
export class Lazy<T> {
private _value?: T
constructor(private initializer: () => T) {
}
get value(): T {
if (this._value == undefined) {
this._value = this.initializer()
}
@tahakorkem
tahakorkem / 1_LatLngSerializer.kt
Last active May 28, 2023 13:57
KotlinX Serialization custom serializer for LatLng
class LatLngSerializer : KSerializer<LatLng> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("LatLng") {
element<Double>("latitude")
element<Double>("longitude")
}
override fun serialize(encoder: Encoder, value: LatLng) {
encoder.encodeStructure(descriptor) {
encodeDoubleElement(descriptor, 0, value.latitude)
encodeDoubleElement(descriptor, 1, value.longitude)