Skip to content

Instantly share code, notes, and snippets.

View lukaskubanek's full-sized avatar

Lukas Kubanek lukaskubanek

View GitHub Profile
@lukaskubanek
lukaskubanek / Bundle+TestFlight.swift
Last active April 26, 2024 08:48
A code snippet for detecting the TestFlight environment for a macOS app at runtime
/// MIT License
///
/// Copyright (c) 2021 Lukas Kubanek, Structured Path GmbH
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@lukaskubanek
lukaskubanek / SwiftUIListRowHighlightFix.swift
Last active March 26, 2024 17:51
A workaround for fixing SwiftUI’s list row highlighting behavior by preventing unwanted delays
import InterposeKit
import SwiftUI
/// A workaround for an issue in SwiftUI related to delayed highlighting of list rows upon user
/// interaction, rendering it inconsistent with UIKit.
///
/// This fix implements the solution proposed by Léo Natan and utilizes `InterposeKit` by Peter
/// Steinberger to modify the behavior of `UICollectionViewCell` instances used internally
/// by SwiftUI.
///
@lukaskubanek
lukaskubanek / fn-shortcuts.md
Last active February 21, 2024 16:26
macOS Monterey Keyboard Shortcuts Leveraging the Fn Key
Shortcut Description Overridable?[^1]
Fn-A Navigate Dock No
Fn-Shift-A Launchpad No
Fn-C Control Center No
Fn-E Emoji & Symbols Yes
Fn-F Enter/Exit Full Screen Yes
Fn-H Desktop No
Fn-M Navigate Main Menu Yes
Fn-N Notifications No
@lukaskubanek
lukaskubanek / View+KeyboardAvoidance.swift
Created December 4, 2023 07:28
A patch for SwiftUI views that disables keyboard avoidance
import InterposeKit
import UIKit
import SwiftUI
import SwiftUIIntrospect
extension View {
public func keyboardAvoidanceDisabled() -> some View {
self.introspect(.viewController, on: .iOS(.v17)) { viewController in
if let hostingView = viewController.parent?.view {
if String(describing: type(of: hostingView)).hasPrefix("_UIHostingView") {
@lukaskubanek
lukaskubanek / NSView Drawing Issue on macOS Big Sur.md
Last active July 18, 2022 08:09
NSView Drawing Issue on macOS Big Sur

This is an excerpt from our internal documentation describing an issue with drawing in NSViews on macOS Big Sur.

1️⃣ Introduction

In macOS Big Sur (probably starting with β9), Apple changed the default contents format for backing layers of NSViews. Instead of an explicit CALayerContentsFormat.RGBA8Uint value, an „Automatic“ value is now used. Even though it also resolves into „RGBA8“ in our testing, it has some serious implications as it breaks assumptions our code relies on.

I first stumbled upon this issue in this tweet by Frank. It links to a thread on Apple Forums by Mark that contains valuable information as well as ideas for workarounds. The changed behavior was also confirmed by Marcin in this tweet.

2️⃣ Impact on Diagrams

@lukaskubanek
lukaskubanek / NSBezierPath+CGPath.swift
Created June 14, 2015 08:19
NSBezierPath+CGPath.swift
import AppKit
public extension NSBezierPath {
public convenience init(path: CGPath) {
self.init()
let pathPtr = UnsafeMutablePointer<NSBezierPath>.alloc(1)
pathPtr.initialize(self)
@lukaskubanek
lukaskubanek / XCTAssertThrowsError.swift
Created March 14, 2021 18:58
XCTAssertThrowsError(…) With Error Equality Check
import XCTest
public func XCTAssertThrowsError<T, E: Error & Equatable>(
_ expression: @autoclosure () throws -> T,
expected expectedError: E,
_ message: String = "",
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertThrowsError(try expression(), message, file: file, line: line) { error in
@lukaskubanek
lukaskubanek / keybase-github.md
Last active April 7, 2016 12:36
Updating keybase.io public key to work with GitHub
  1. Import keybase.io keys to GPG locally (→ link)
  2. Add new email address to the public key (→ link)
  3. Export the public key and upload it to keybase.io again (→ link)
  4. Configure GPG for Git locally (→ link)
@lukaskubanek
lukaskubanek / disable_undo.m
Created January 12, 2014 21:46
Disabling undo for a specific operation of Core Data
- (void)method
{
NSUndoManager *undoManager = [self undoManager];
[undoManager disableUndoRegistration];
/* do something */
[self.managedObjectContext processPendingChanges];
[undoManager enableUndoRegistration];
}
@lukaskubanek
lukaskubanek / disable-notification-center.sh
Last active December 11, 2015 02:18
Disable the Notification Center in Mac OS X using cURL.
#!/bin/sh
# commands taken from http://osxdaily.com/2012/08/06/disable-notification-center-remove-menu-bar-icon-os-x/
# usage: curl -L https://gist.github.com/raw/4529265/eb7df9dcd9bf92ecab978ccc500bd80221565aef/disable-notification-center.sh | sh
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
killall NotificationCenter