Skip to content

Instantly share code, notes, and snippets.

View drewmccormack's full-sized avatar

Drew McCormack drewmccormack

View GitHub Profile
@drewmccormack
drewmccormack / UpdateLocalizations.swift
Last active September 26, 2023 08:36
Using the AppStoreConnect_Swift_SDK package to update localizations on App Store Connect.
import AppStoreConnect_Swift_SDK
func updateMetadata(forBundleID bundleID: String) async throws {
let configuration = try! APIConfiguration(issuerID: "...", privateKeyID: "...", privateKey: "...")
let provider = APIProvider(configuration: configuration)
// Get app
let appRequest = APIEndpoint.v1
.apps
.get(parameters: .init(filterBundleID: [bundleID], include: [.appInfos, .appStoreVersions]))
@drewmccormack
drewmccormack / SendFile.scpt
Created July 4, 2016 17:41
Javascript (JXA) script to send attached files one per email
// Open in Script Editor, and Export as an Application
// To use, drag files from folder onto Droplet
function openDocuments(docs) {
var mail = Application("Mail")
for (var i = 0; i < docs.length; i++) {
var doc = docs[i].toString()
var filename = doc.replace(/^.*[\\\/]/, '')
@drewmccormack
drewmccormack / symbolicate-sample-dump.py
Last active August 15, 2023 09:32
Symbolicates a sample dump from Activity Monitor
#!/usr/bin/env python
#
# To use this, just put the DSYMS in the same directory as the sample dump file,
# and run the script from that directory, passing the sample dump file name as only argument
#
import re, sys, os, subprocess
sampleFile = sys.argv[1]
@drewmccormack
drewmccormack / Queue.swift
Created September 29, 2022 07:02
A Queue (FIFO) built from an actor.
actor Queue {
private var tasks: [() async -> Void] = []
func enqueue(_ task: @escaping () async -> Void) {
tasks.append(task)
Task { await runNext() }
}
private func runNext() async {
guard !tasks.isEmpty else { return }
@drewmccormack
drewmccormack / NSString+MCHTMLToPlainTextConversion.h
Created October 5, 2012 14:29
Convert a NSString with HTML into a plain text string using NSXMLParser.
#import <Foundation/Foundation.h>
@interface NSString (MCHTMLToPlainTextConversion)
-(NSString *)stringByConvertingHTMLToPlainText;
@end
@drewmccormack
drewmccormack / LabelUniqueSet.swift
Created August 10, 2021 09:33
Introduces a Set type that stores enums, including those with associated types, and uniques on the label rather than the value.
struct Label: Hashable {
var label: String
}
protocol LabelUniquing {
var label: Label { get }
}
extension LabelUniquing {
//
// Lightweight but powerful state machine.
//
// Usage:
// enum TrafficLight: State {
// case red, orange, green
// }
//
// var trafficLights = StateMachine<TrafficLight>(initialState: .red)
// trafficLights.addRoute(from: .red, to: .green)
@drewmccormack
drewmccormack / prefixer.py
Created May 10, 2011 07:25
Change the prefix of a Cocoa project
#!/usr/bin/env python
#---------
# Script to change the prefix of a framework
#---------
import os
import re
import string
@drewmccormack
drewmccormack / MCURLExtensions.m
Created July 14, 2011 13:05
NSURL category method to get the UTI of a file
@implementation NSURL (MCExtensions)
-(NSString *)UTI
{
FSRef fileRef;
Boolean isDirectory;
NSString *utiString = nil;
if ( !self.isFileURL ) return nil;
@drewmccormack
drewmccormack / gist:5262375
Created March 28, 2013 11:03
A category method for NSArray that facilitates enumeration with regular draining of the autorelease pool. Useful for those long, memory accumulating loops.
@implementation NSArray (AutoreleasePoolDraining)
-(void)enumerateObjectsDrainingEveryIterations:(NSUInteger)iterationsBetweenDrains usingBlock:(void (^)(id object, NSUInteger index, BOOL *stop))block
{
NSUInteger total = 0;
NSUInteger count = self.count;
NSUInteger numberOfChunks = (count / MAX(1,iterationsBetweenDrains) + 1);
BOOL stop = NO;
for ( NSUInteger chunk = 0; chunk < numberOfChunks; chunk++ ) {
@autoreleasepool {