Skip to content

Instantly share code, notes, and snippets.

View claybridges's full-sized avatar
✌️
peace

Clay Bridges claybridges

✌️
peace
View GitHub Profile
@claybridges
claybridges / force_package_resolved_urls.rb
Created August 23, 2023 17:45
For SPM Package.resolved file, force all urls to either have/not-have a .git suffix
#!/usr/bin/env ruby
# Forces all SPM urls in `Package.resolved` files to either have, or not have,
# a .git suffix, based on `use_suffix`. NOTE: probably WILL rewrite your
# `Package.resolved` files, though in predictable and semantically identical ways.
#
# If you want to do this on only specific files, pass an array of these (full paths)
# for `against_files`.
#
def force_package_resolved(use_suffix:, against_files: nil)
@claybridges
claybridges / WithFunctions.swift
Last active February 20, 2023 18:34
Swift with() and withLet() functions
/**
Groups operations on an item, using shorthand to reduce repetition.
Using this function, repetitive code like
```
let myWellDescribedLabel = UILabel()
myWellDescribedLabel.attributedText = attributedStringTitle
myWellDescribedLabel.isAccessibilityElement = true
myWellDescribedLabel.numberOfLines = 1
```
@claybridges
claybridges / failure.txt
Last active April 25, 2022 13:48
RVM failure
$ ./rvm_test.sh
+ installRvmFunction
+ local found=0
+ for rvmScript in '"$HOME/.rvm/scripts/rvm"' /usr/local/rvm/scripts/rvm
+ '[' -s /Users/clay/.rvm/scripts/rvm ']'
+ . /Users/clay/.rvm/scripts/rvm
++ builtin test -n '3.2.57(1)-release' -o -n '' -o -n ''
++ case "`uname`" in
+++ uname
+++ command ps -p 31878 -o ucomm=

Notification observations and handlers

For a class, each notification observation should be handled by a single method. The name of that method should be handle appended with the name of the notification being observed. For instance, for notification name

NSNotification.Name.LUUICachedPaymentMethodDidUpdate

the handler would be

private func handleCachedPaymentMethodDidUpdate(...)
@claybridges
claybridges / DefaultUsingBackingStore.swift
Created November 18, 2019 21:14
Property Wrapper Question
var defaultNum = 1
class MyClass {
var num: Int {
get { _num ?? defaultNum }
set { _num = newValue }
}
private var _num: Int?
}
@claybridges
claybridges / xcbuild-safe.sh
Last active September 26, 2018 18:21
Drop in replacement/wrapper for xcodebuild, fixes Xcode 7 build dependency on system ruby vs. rvm. Explained further @ http://stackoverflow.com/questions/33041109.
#!/bin/bash --login
# Cf. http://stackoverflow.com/questions/33041109
#
# Xcode 7 (incl. 7.0.1) seems to have a dependency on the system ruby.
# xcodebuild is screwed up by using rvm to map to another non-system
# ruby†. This script is a fix that allows you call xcodebuild in a
# "safe" rvm environment, but will not (AFAIK) affect the "external"
# rvm setting.
#
@claybridges
claybridges / save_xcode_for_el_cap.bash
Last active August 29, 2015 14:26
Xcode 6.4 and Xcode 7 beta 4 both stopped working with OS X El Cap beta 6. This seems to fix it. See comments for deets. Requires a sudo password, don't be freaked out.
#!/usr/bin/env bash
#
# Based on original solution by user lembacon, here:
# https://forums.developer.apple.com/thread/13170?start=105&tstart=0
# Watch fix added by user Richie__.
#
# Created by Clay Bridges, 5 Aug 2015
move_dyld_sim()
{
(defn center-y-for-note
; arity = 2
([{:keys [origin size]} note]
(let [{:keys [height]} size]
(center-y-for-note (origin :y) (size :height) note)))
; arity = 3
([origin-y height note]
(let [note-increment (/ height 8)
ymin (+ origin-y height)]
@claybridges
claybridges / WKPreferences+DevExtras.h
Created November 27, 2014 02:25
Allows setting of WKPreferences.developerExtrasEnabled flag
@import WebKit;
@interface WKPreferences (DevExtras)
@property (nonatomic, setter=_setDeveloperExtrasEnabled:) BOOL _developerExtrasEnabled;
- (void)enableDevExtras;
@end1
FROM XCODE CONSOLE:
*** Unable to run app in Simulator If you believe this error represents a bug, please attach the log file at /var/folders/74/k54kppb928s963936by98fzm0000gn/T/com.apple.dt.XCTest-status/Session-2014-11-21_13:05:32-Rla0wx.log
FROM THAT LOG FILE:
2014-11-21 13:05:32.265 Beginning test session with Xcode 6A1052c
2014-11-21 13:05:32.265 Testing on device: <DVTiPhoneSimulator: 0x7fa48133f4b0> {
SimDevice: SimDevice : RedactedName.PhotoTest (3219C047-04CE-41BF-9BE4-F200B2BE25C1) : state={ Booted } deviceType={ SimDeviceType : com.apple.CoreSimulator.SimDeviceType.iPhone-6 } runtime={ SimRuntime : 8.1 (12B411) - com.apple.CoreSimulator.SimRuntime.iOS-8-1 }
}