Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@steipete
steipete / gist:504e79558d861211a3a9ff794e09c817
Created May 20, 2020 07:47
Twitter crash on 12-inch MBP on macOS 10.15.4 stable
Process: Twitter [45863]
Path: /Applications/Twitter.app/Contents/MacOS/Twitter
Identifier: Twitter
Version: 8.19 (8.19.1)
App Item ID: 1482454543
App External ID: 835910359
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Twitter [45863]
User ID: 501
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
public func run<V: View>(view: V) {
let delegate = AppDelegate(view)
let app = NSApplication.shared
NSApp.setActivationPolicy(.regular)
app.mainMenu = app.customMenu
@steipete
steipete / gist:92f66ec9387e8e4c7c17ffebb0824a8e
Created May 14, 2020 07:22
deciphering kernel debug=0x104c44
Need to run with csrutil disable or recovery
sudo nvram boot-args="debug=0x104c44”
0x104c44 = 1 0000 0100 1100 0100 0100
DB_NMI 0x4 // changes the power-button to create a non-maskable interrupt?
DB_ARP 0x40 // allows debugging across subnets via ARP?
DB_KERN_DUMP_ON_PANIC 0x400 // Trigger core dump on panic
@steipete
steipete / FirebaseCoordinator.swift
Created April 13, 2020 13:38
If you're as confused as I am that there's an API for custom options, yet Google still requires a file named GoogleService-Info.plist in your app, here's some swizzling that fixes that for ya. All Swift :)
class FirebaseCoordinator {
static let shared = FirebaseCoordinator()
static let initialize: Void = {
/// We modify Google Firebase (and eventually Analytics) to load the mac-specific plist at runtime.
/// Google enforces that we have a file named "GoogleService-Info.plist" in the app resources.
/// This is unfortunate since we need two different files based on iOS and Mac version
/// One solution is a custom build step that copies in the correct file:
/// https://stackoverflow.com/questions/37615405/use-different-googleservice-info-plist-for-different-build-schemes
/// However, this is basically impossible since Catalyst doesn't set any custom build variables, so detection is extremely difficult.
/// We swizzle to modify the loading times.
@steipete
steipete / RuntimeScanner.swift
Last active August 8, 2024 08:47
Runtime Scanner to find large ObjC encodings. Inspired by https://medium.com/@dmaclach/objective-c-encoding-and-you-866624cc02de - this code scans the runtime to find excessive Objective-C type encodings, usually created when you mix it with C++. We were able to reduce the binary size by 100KB with rewriting just a few methods that were extremel…
//
// Copyright © 2020 PSPDFKit GmbH, Peter Steinberger. MIT Licensed.
//
import Foundation
extension String {
fileprivate init?(maybeCString: UnsafePointer<CChar>?) {
guard let cString = maybeCString else { return nil }
self.init(cString: cString)
@steipete
steipete / PSPDFPointerInteractionSupport.h
Created March 26, 2020 14:27
Support Pointer Interactions while CI still running on Xcode 11.3
//
// Copyright © 2020 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//
#import <Foundation/Foundation.h>
@steipete
steipete / gist:cb92914494763b2ed5aa20e5dc589280
Created February 21, 2020 19:46
Twitter crashes on macOS 10.15.4b2
Process: Twitter [12485]
Path: /Applications/Twitter.app/Contents/MacOS/Twitter
Identifier: maccatalyst.com.atebits.Tweetie2
Version: 8.9 (8.9)
App Item ID: 1482454543
App External ID: 834769122
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Twitter [12485]
User ID: 501
@implementation UIImage (ResourceProxyHack)
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format {
// HACK: proxy seems garbage so we always show PDF for now.
let cgImage = [_bridge imageForFileType:@"pdf"];
// HACK: We use mainScreen here but could have multiple screens.
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
return image;
}
@implementation UIImage (ResourceProxyHack)
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format {
// HACK: proxy seems garbage so we always show PDF for now.
let cgImage = [_bridge imageForFileType:@"pdf"];
// HACK: We use mainScreen here but could have multiple screens.
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
return image;
}
@steipete
steipete / UIScreenDebugLLDB.txt
Last active October 10, 2019 12:24
UIScreen on Catalyst is.. weird (tested with 10.15.0 GM). Reported as FB7364971
(lldb) po UIScreen.mainScreen
<UIScreen: 0x119905f10; bounds = {{0, 0}, {960, 540}}; mode = <UIScreenMode: 0x600000290300; size = 1920.000000 x 1080.000000>>
Display: 15,4-inch (2880 x 1800)
Scaling set to max, so effectively 1920x1200 (virtual screen of 3840x2400)
What I would expect: <UIScreen bounds = {{0, 0}, {1920, 1200}}; mode = <UIScreenMode: 0x600000290300; size = 3840.000000 x 2400.000000>>
------