Skip to content

Instantly share code, notes, and snippets.

View orospakr's full-sized avatar

Andrew Clunis orospakr

View GitHub Profile
@mayankmkh
mayankmkh / PrettyPrint.kt
Last active February 5, 2024 03:58
Pretty Print Kotlin Data Class
fun Any.prettyPrint(): String {
var indentLevel = 0
val indentWidth = 4
fun padding() = "".padStart(indentLevel * indentWidth)
val toString = toString()
val stringBuilder = StringBuilder(toString.length)
@josephlord
josephlord / FetchedResultsControllerPublisher.swift
Created June 10, 2019 23:08
Making a Combine publisher from a FetchedResultsController
//
// FetchedResultsControllerPublisher.swift
// ListsModel
//
// Created by Joseph Lord on 09/06/2019.
// Copyright © 2019 Joseph Lord. All rights reserved.
//
import Foundation
import Combine
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active March 11, 2024 22:57
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

@pookjw
pookjw / seedutil.md
Last active July 6, 2023 02:47
Enroll macOS Beta Seed without profile installation

seedutil

Enroll macOS Beta Seed without profile installation

Usage

$ sudo /System/Library/PrivateFrameworks/Seeding.framework/Versions/A/Resources/seedutil 
usage: seedutil enroll SEED_PROGRAM
    seedutil unenroll

seedutil current

trait Tree
data object Empty : Tree
data class Leaf(val value: Int) : Tree
data class Node(val left: Tree, val right: Tree) : Tree
fun max(x:Int, y:Int):Int = if (x > y) x else y
fun depth(t: Tree): Int = when (t) {
is Empty -> 0
is Leaf -> 1