Skip to content

Instantly share code, notes, and snippets.

View shalom-aviv's full-sized avatar

Andrei shalom-aviv

  • Independed developer
View GitHub Profile
@aartikov
aartikov / App.kt
Created January 10, 2023 21:45
Decompose DI
class App : Application(), KoinProvider {
override lateinit var koin: Koin
private set
override fun onCreate() {
super.onCreate()
koin = createKoin()
}
import Foundation
import CoreImage
/**
Based on: https://gist.github.com/SheffieldKevin/566dc048dd6f36716bcd
Updated for Swift 5.5 (Xcode 13)
*/
class ImageDiff {
func compare(leftImage: CGImage, rightImage: CGImage) throws -> Int {
@syarihu
syarihu / ClickableOnceForJetpackCompose.kt
Last active April 11, 2024 13:26
Double tap prevention for jetpack compose
import androidx.compose.foundation.clickable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import kotlinx.coroutines.delay
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active May 10, 2024 15:05
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@humblehacker
humblehacker / CVPixelBufferDeepCopy.swift
Last active February 13, 2022 20:35
Creates a deep copy of a CVPixelBuffer. Compatible with Swift 2.3.
extension CVPixelBuffer
{
/// Deep copy a CVPixelBuffer:
/// http://stackoverflow.com/questions/38335365/pulling-data-from-a-cmsamplebuffer-in-order-to-create-a-deep-copy
func copy() -> CVPixelBuffer
{
precondition(CFGetTypeID(self) == CVPixelBufferGetTypeID(), "copy() cannot be called on a non-CVPixelBuffer")
var _copy: CVPixelBuffer?