Skip to content

Instantly share code, notes, and snippets.

Avatar

Angelo Stavrow AngeloStavrow

View GitHub Profile
@madimedia
madimedia / CleanBackwardCompatibility.swift
Last active Nov 2, 2021
An example of a back port implementation to facilitate backward compatibility handling in Swift.
View CleanBackwardCompatibility.swift
//
// Demo.swift
// bedtimefanlite
//
// Created by Sofia Chevrolat on 02/11/2021.
// Inspired by [Dave DeLong's post](https://davedelong.com/blog/2021/10/09/simplifying-backwards-compatibility-in-swift/)
//
// Two small examples of a "backport" implementation to facilitate backward compatibility.
//
// USAGE :
@marcpalmer
marcpalmer / DebugMetrics.swift
Created Jul 6, 2020
Helper for rendering metrics of SwiftUI views in debugging
View DebugMetrics.swift
// Created by Marc Palmer on 13/02/2020.
//
// Usage: Add .debugMetrics(.yellow) or similar to any view
import Foundation
import SwiftUI
/// Renders the width and height of a view
struct DebugMetricsModifier: ViewModifier {
let colour: Color
@unnamedd
unnamedd / MacEditorTextView.swift
Last active Nov 13, 2021
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
View MacEditorTextView.swift
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active Dec 7, 2021
Making efficient use of the libdispatch (GCD)
View libdispatch-efficiency-tips.md

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

@kristopherjohnson
kristopherjohnson / KeyboardNotification.swift
Last active Jun 9, 2021
Swift convenience wrapper for the userInfo values associated with a UIKeyboard notification
View KeyboardNotification.swift
import UIKit
/// Wrapper for the NSNotification userInfo values associated with a keyboard notification.
///
/// It provides properties that retrieve userInfo dictionary values with these keys:
///
/// - UIKeyboardFrameBeginUserInfoKey
/// - UIKeyboardFrameEndUserInfoKey
/// - UIKeyboardAnimationDurationUserInfoKey
/// - UIKeyboardAnimationCurveUserInfoKey
@timarnold
timarnold / gist:3151932
Created Jul 20, 2012
TextExpander Snippet (using AppleScript) to open the currently visible page in Safari in Chrome
View gist:3151932
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
if appIsRunning("Google Chrome") then
tell application "Google Chrome"
make new window
set URL of active tab of window 0 to theURL
activate
end tell