Skip to content

Instantly share code, notes, and snippets.

View leptos-null's full-sized avatar
🏔️
Darwin tooling

Leptos leptos-null

🏔️
Darwin tooling
View GitHub Profile
@leptos-null
leptos-null / abi.py
Last active September 10, 2023 22:55 — forked from dlevi309/abi.py
script to switch between iOS13 (00000002) and iOS14 (80000002) arm64e ABI
import sys
FAT_MAGIC = b'\xca\xfe\xba\xbe' # big endian
FAT_MAGIC_64 = b'\xca\xfe\xba\xbf' # big endian
MH_MAGIC_64 = b'\xfe\xed\xfa\xcf' # big endian
MH_CIGAM_64 = b'\xcf\xfa\xed\xfe' # little endian
CPU_TYPE_ARM64 = b'\x01\x00\x00\x0c' # big endian
CPU_SUBTYPE_IOS13 = b'\x00\x00\x00\x02' # big endian
@leptos-null
leptos-null / OrderedSet.swift
Last active June 3, 2023 07:57
A simple OrderedSet implementation backed by an Array and a Set
import Foundation
struct OrderedSet<Element: Hashable>: Sequence {
private var order: [Element]
private var membership: Set<Element>
func makeIterator() -> IndexingIterator<Array<Element>> {
order.makeIterator()
}
@leptos-null
leptos-null / redirect_stdout.swift
Created May 27, 2023 03:57
Swift function to redirect stdout. Helpful for using print in environments where stdout is not easily accessible
import Foundation
func redirectStdout(to path: String) throws {
let (openResult, posixErrorCode) = path.withCString {
// idea thanks to https://github.com/leptos-null/ClassDumpRuntime/blob/31e3601/classdumpctl/main.m#L456-L459
// error checking thanks to https://github.com/leptos-null/Forest/blob/ba4b89a/Shared/Tar.swift#L172-L174
let result = open($0, O_WRONLY | O_CREAT | O_TRUNC, 0o644)
let globalError = errno // copy errno since it may change before we access it again later
return (result, globalError)
}
@leptos-null
leptos-null / ForEach+Enumerated.swift
Created February 6, 2023 21:13
SwiftUI ForEach initializers that create enumerated elements
import SwiftUI
extension ForEach {
init<Base: Sequence>(enumerated base: Base, @ViewBuilder content: @escaping (Data.Element) -> Content) where Data == Array<EnumeratedSequence<Base>.Element>, ID == Base.Element, Content: View, ID: Identifiable {
self.init(Array(base.enumerated()), id: \.element, content: content)
}
init<Base: Sequence>(enumerated base: Base, id: KeyPath<Base.Element, ID>, @ViewBuilder content: @escaping (Data.Element) -> Content) where Data == Array<EnumeratedSequence<Base>.Element>, Content: View {
let basePath: KeyPath<EnumeratedSequence<Base>.Element, Base.Element> = \.element
self.init(Array(base.enumerated()), id: basePath.appending(path: id), content: content)
}
@leptos-null
leptos-null / ARCBlood.md
Created April 12, 2020 16:56
Red Cross Blood REST API Reference

Red Cross Blood REST API Reference

This guide is based on research from version 1.7.3 of Red Cross Blood iOS app.

Host: blood.arc.cubeapis.com

This reference is for version 2.1 of the interface.

Authentication

Keybase proof

I hereby claim:

  • I am leptos-null on github.
  • I am leptos_null (https://keybase.io/leptos_null) on keybase.
  • I have a public key ASA0dcmIggGRcMrdxDzFRDAutr7TdLveEOWsHbCkWeWN0Qo

To claim this, I am signing this object:

@leptos-null
leptos-null / watchPreviewDate.m
Created September 19, 2019 05:10
The date used for previews on watchOS, primarily for complications
static NSDate *watchPreviewDate() {
static NSDateComponents *comps;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
comps = [NSDateComponents new];
comps.calendar = NSCalendar.autoupdatingCurrentCalendar;
comps.timeZone = NSTimeZone.localTimeZone;
comps.year = 2014;
comps.month = 9;
comps.day = 9;
@leptos-null
leptos-null / pathdiff.m
Last active August 29, 2019 23:28
Find tools with the with the same name in a PATH
@import Foundation;
int main(int argc, const char *argv[]) {
const char *const arg = argv[1];
if (arg) {
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0 || argc > 2) {
printf("Usage: %s [PATH]\n"
"Walk through PATH and find any repeated file names. "
"A different PATH can be provided by passing it in as the first argument.\n", argv[0]);
return 1;
@leptos-null
leptos-null / open_app.m
Created August 28, 2019 05:42
[iOS] Open an application from the command line by bundle identifier
@import Foundation;
@import MobileCoreServices;
API_AVAILABLE(ios(5.0))
@interface LSApplicationWorkspace : NSObject
+ (instancetype)defaultWorkspace;
- (BOOL)openApplicationWithBundleID:(NSString *)bundleID API_AVAILABLE(ios(7.0));
@end
@leptos-null
leptos-null / UIImageUnicode.m
Last active October 19, 2020 18:49
Draw UIImage of Unicode character
@implementation UIImage (UIImageUnicode)
+ (UIImage *)imageFromUnicodePoint:(unichar)codepoint compatibleWithTraitCollection:(UITraitCollection *)traitCollection API_AVAILABLE(ios(10.0)) {
NSString *str = [NSString stringWithCharacters:&codepoint length:1];
UIFont *weightRef = [UIFont preferredFontForTextStyle:UIFontTextStyleBody compatibleWithTraitCollection:traitCollection];
UIFont *sizeRef = [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2 compatibleWithTraitCollection:traitCollection];
NSAttributedString *drawReady = [[NSAttributedString alloc] initWithString:str attributes:@{
NSFontAttributeName : [weightRef fontWithSize:sizeRef.pointSize]
}];
UIGraphicsBeginImageContextWithOptions([drawReady size], NO, 0);