Skip to content

Instantly share code, notes, and snippets.

View jaredsinclair's full-sized avatar

Jared Sinclair jaredsinclair

View GitHub Profile
@jaredsinclair
jaredsinclair / ancestor-commit-check.sh
Created May 14, 2024 17:30
Ancestor Commit Check
# Does this branch contain my fix?
git merge-base --is-ancestor <maybe_ancestor> <descendant> && echo "Yes" || echo "No"

Set value

GCC_PREPROCESSOR_DEFINITIONS = FOO=My Value

Add Constants.m

It is particularly important to check that the definition of your value exists here, as it will not cause a compilation failure, but instead result in the generation of @"FOO".

@import Foundation;
@jaredsinclair
jaredsinclair / spm-nuke-manifest-db.txt
Last active December 13, 2023 19:01
Nuke macOS Swift Package Manager manifest cache database
# ​Xcode does not offer a way to fully remove all cached Package manifest data from
# macOS. This script takes care of it for you.
#
# Important: SPM implicitly relies on the `org.swift.swiftpm` Swift package
# to manage a local database of resolved package manifest files. That database
# will happily cache your resolved manifest to character-level accuracy. To
# clear out the resolved package manifest, there is only one known solution:
# nuking and paving that database. Running the following command (standard
# user permissions works fine) will nuke the database:

Repackaging a Fat Static Library as an xcframework

Consider this directory tree from a vendor:

OwningTheLibs/
  OwningTheLibs.a
  include/
    OwningTheLibs/
      OwningTheLibs.h
@jaredsinclair
jaredsinclair / Composition.swift
Last active May 28, 2020 21:48
Exposing private members to tests via composition.
import Foundation
/// This class is public, because my library exposes this to the rest of my app.
public class ObligatoryNetworkingClient {
public enum GetEndpoint {
case timeline
case profile(userID: String)
case directMessages
}
@jaredsinclair
jaredsinclair / .zshrc
Last active January 23, 2024 19:02
The World's Most Disappointing .zshrc File
# ______ ______ __ __
# /\___ \ /\ ___\ /\ \_\ \
# \/_/ /__ \ \___ \ \ \ __ \
# /\_____\ \/\_____\ \ \_\ \_\
# \/_____/ \/_____/ \/_/\/_/
#
# THE GODDAMN PROMPT
# ---------------------------------------------------------------
# Looks best with certain fonts, e.g. SFMono, smoothing enabled.
@jaredsinclair
jaredsinclair / Importer.swift
Created April 8, 2019 01:02
Transform a Feedbin JSON backup file into a directory of Jekyll-formatted posts
import Foundation
/*
Alls you gotta do is (in Main.swift):
1. Initialize an Importer with the file URL to the JSON file (origin) and a URL to the directory that will contain all the Jekyll-formatted posts (destination).
2. Call the `run()` method on the Importer.
*/
@jaredsinclair
jaredsinclair / xcode-gsuite-email-notifs.md
Last active February 16, 2021 15:49
Setting Up Xcode Server Email Notifications So They Send From Your GSuite Account

Setting Up Xcode Server Email Notifications on a Repurposed Household Mac So They Send From Your GSuite Account

I recently repurposed a family computer to play a new role: Xcode build server. Setting up the bot wasn't too bad overall, but there was one really big hurdle: getting post-integration email notifications to actually send. Despite the (relative) user-friendliness of the UI, the email notification feature is very unforgiving. It expects to be running on a mac that is hosting (or sitting behind) a domain that's also running it's own SMTP service. A repurposed family computer is not going to have such a setup. Outbound mail is going to either not send at all or else likely get bounced by spam filtering.

I do have a GSuite account for small business stuff. I host my website at Media Temple, but the email service is run by Gmail, with DNS records configured to route mail traffic to Gmail. What I want is for my Xcode bot to send email notifications from one of my GSuite accounts. The following are s

@jaredsinclair
jaredsinclair / Autocodable.swift
Last active January 22, 2022 00:23
[Notion]: Automatic Codable synthesis for Enums with Codable associated values.
enum MyEnum: Codable {
case foo
case bar(Int)
case baz(label: String)
case qux(Bool, label: String, Int)
case anotherCase(discriminator: String, anotherCase_1: Int)
}
// Begin synthesized code...
@jaredsinclair
jaredsinclair / NSString+HTML.swift
Created December 18, 2017 05:21
Convert HTML string to plain text (Swift version of MWFeedParser's utility)
/// Quick-n-dirty translation of MWFeedParser's algorithm from Objective-C to Swift
/// seealso: https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString%2BHTML.m
public extension NSString {
public func byConvertingHTMLToPlainText() -> String {
let stopCharacters = CharacterSet(charactersIn: "< \t\n\r\(0x0085)\(0x000C)\(0x2028)\(0x2029)")
let newLineAndWhitespaceCharacters = CharacterSet(charactersIn: " \t\n\r\(0x0085)\(0x000C)\(0x2028)\(0x2029)")
let tagNameCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")