Skip to content

Instantly share code, notes, and snippets.

View konstantin-gorbunov's full-sized avatar

Kostiantyn Gorbunov konstantin-gorbunov

View GitHub Profile
tclementdev /
Last active June 13, 2024 21:59
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

evgeniyd / UBINullableSortDescriptor.swift
Last active July 16, 2018 16:59
NSSortDescriptor subclass to sort objects w/ nullable key. These objects appears (unsorted) at the end of the sorted list when ascending == true. Written in Swift, this class merely extends the idea from this SO answer:
import Foundation
class UBINullableSortDescriptor: NSSortDescriptor {
override init(key: String, ascending: Bool) {
super.init(key: key, ascending: ascending)
required override init(key: String, ascending: Bool, selector: Selector) {
super.init(key: key, ascending: ascending, selector: selector)
natecook1000 / NSTimer+Closure.swift
Last active January 6, 2024 07:23
Scheduled NSTimer with a Swift closure
extension NSTimer {
Creates and schedules a one-time `NSTimer` instance.
- Parameters:
- delay: The delay before execution.
- handler: A closure to execute after `delay`.
- Returns: The newly-created `NSTimer` instance.
### Function to get UUID from .mobileprovision file
### $1 - .mobileprovision file to get UUID for
function get_uuid() {
uuid=`/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i "$1")`
echo $uuid
### Go through all provisioning profiles and just echo their uuids