Skip to content

Instantly share code, notes, and snippets.

View flexih's full-sized avatar

Xinghua flexih

  • Beijing
  • 08:49 (UTC +08:00)
View GitHub Profile
@Kyle-Ye
Kyle-Ye / UICollectionViewCell+RCTRootViewDemo.swift
Last active November 17, 2024 04:44
Workaround for UICollectionViewCell+RCTRootView
import Dispatch
import Foundation
import UIKit
extension DispatchQueue {
/// Run the action immediately if it's on the main thread, otherwise dispatch it to the main thread asynchronously.
public static func onMainThread(_ action: @escaping () -> Void) {
if Thread.isMainThread {
action()
} else {
@sebjvidal
sebjvidal / ViewController.swift
Created May 28, 2024 16:39
UICustomViewMenuElement Demo
//
// ViewController.swift
// UIMenu-Demo
//
// Created by Seb Vidal on 28/05/2024.
//
import UIKit
class ViewController: UIViewController {
@stephancasas
stephancasas / sonoma-text-insertion-point-downgrade.jxa.js
Created October 7, 2023 02:58
Disable Sonoma Text Insertion Point ("Cursor" / "Caret")
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
const kCFPrefsFeatureFlagsDir = '/Library/Preferences/FeatureFlags/Domain';
const kCFPrefsFeatureEnabledKey = 'Enabled';
const kUIKitDomainPrefsTemporaryPath = '/tmp/UIKit.plist';
const kUIKitRedesignedTextCursorKey = 'redesigned_text_cursor';
@finestructure
finestructure / async-defer.swift
Last active August 5, 2024 01:34
Async defer
@discardableResult
func run<T>(_ operation: () async throws -> T,
defer deferredOperation: () async throws -> Void) async throws -> T {
do {
let result = try await operation()
try await deferredOperation()
return result
} catch {
try await deferredOperation()
throw error
@dreampiggy
dreampiggy / objc_xrefs_helper_hopper_v5.py
Last active August 26, 2024 20:41
Hopper 5 script to support Objective-C relative method list (iOS 14/macOS 11+)
#objective-c xrefs hopper script
#rewrite the IDAPython script https://github.com/fireeye/flare-ida/blob/master/python/flare/objc2_xrefs_helper.py
#author: Kai Lu(@k3vinlusec)
#editor: Zhuoli Li(@dreampiggy)
def getRefPtr(doc,classMethodsVA,objcSelRefs, objcMsgRefs, objcConst):
ret = (None, None)
namePtr = doc.readUInt64LE(classMethodsVA) #get name field in struct __objc_method, it's selector
ctn = 0
@ariccio
ariccio / BluetoothConstants.ts
Created January 10, 2022 18:59
GATT services and characteristics
//Extracted 1/10/2022 from my COVID-CO2-tracker project, in case they're useful to anybody. I'm gonna file an issue/suggesting a few places, and it seems polite to dump it here rather than a long preformatted bit in an issue.
export const GENERIC_GATT_SERVICE_SHORT_ID_DESCRIPTIONS = new Map([
//these are hex strings, without the 0x. Chrome zero extends the devices... so 0x1800 becomes 0x00001800.
// This is a hack to make things easy.
['1800', "generic_access"],
['1801', "generic_attribute"],
['1802', "immediate_alert"],
['1803', "link_loss"],
@ethanhuang13
ethanhuang13 / VirtualKeyboard.swift
Last active February 7, 2024 05:58
MacBook Air M1 Zhuyin Keyboard written with SwiftUI ~=300 LOC, < 4hrs
//
// VirtualKeyboard.swift
// MacBook Air M1 Zhuyin Keyboard
// Written with SwiftUI ~=300 LOC, < 4hrs
// Created by Ethan Huang on 2021/1/13.
// Twitter: @ethanhuang13
import SwiftUI
struct VirtualKeyboard: View {
@shaps80
shaps80 / Font.swift
Last active October 20, 2024 09:46
A set of UIFont/NSFont helpers that matches the equivalent SwiftUI Font API. (Supports iOS 13+ and macOS 10.15+)
import SwiftUI
#if os(macOS)
public typealias Font = NSFont
public typealias FontDescriptor = NSFontDescriptor
#else
public typealias Font = UIFont
public typealias FontDescriptor = UIFontDescriptor
#endif

Debugging the Swift Toolchain

Use these steps to debug components of the Swift toolchain. This allows you to see Swift's source code from the debugger – instead of disassembly. The debugger can also provide some variable names and values. This has been initially tested with libswiftCore.dylib.

These instructions were updated as of Swift 5.2.1.

Prerequisites

@agiletortoise
agiletortoise / PointerEnabledButton.swift
Created March 24, 2020 20:00
PointerEnabledButton class demonstrating pointer support for iPadOS 13.4
import UIKit
class PointerEnabledButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
if #available(iOSApplicationExtension 13.4, *) {
enablePointer()
}
}