Skip to content

Instantly share code, notes, and snippets.

View AngeloStavrow's full-sized avatar

Angelo Stavrow AngeloStavrow

View GitHub Profile
@timarnold
timarnold / gist:3151932
Created July 20, 2012 17:08
TextExpander Snippet (using AppleScript) to open the currently visible page in Safari in Chrome
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
@kristopherjohnson
kristopherjohnson / KeyboardNotification.swift
Last active October 6, 2023 14:45
Swift convenience wrapper for the userInfo values associated with a UIKeyboard notification
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
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 16, 2024 01:02
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

@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@marcpalmer
marcpalmer / DebugMetrics.swift
Created July 6, 2020 23:45
Helper for rendering metrics of SwiftUI views in debugging
// 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
@SofiaMNC
SofiaMNC / CleanBackwardCompatibility.swift
Last active November 2, 2021 16:13
An example of a back port implementation to facilitate backward compatibility handling in 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 :