Skip to content

Instantly share code, notes, and snippets.

Avatar
🌱
Lawn & Garden

Clay Bridges claybridges

🌱
Lawn & Garden
View GitHub Profile
View n10ns.md

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(...)
View DefaultUsingBackingStore.swift
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 Sep 26, 2018
Drop in replacement/wrapper for xcodebuild, fixes Xcode 7 build dependency on system ruby vs. rvm. Explained further @ http://stackoverflow.com/questions/33041109.
View xcbuild-safe.sh
#!/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 Aug 29, 2015
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.
View save_xcode_for_el_cap.bash
#!/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()
{
View gist:4b787873a3efad4cfe3f
(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 Nov 27, 2014
Allows setting of WKPreferences.developerExtrasEnabled flag
View WKPreferences+DevExtras.h
@import WebKit;
@interface WKPreferences (DevExtras)
@property (nonatomic, setter=_setDeveloperExtrasEnabled:) BOOL _developerExtrasEnabled;
- (void)enableDevExtras;
@end1
View gist:01575ecb7817f6c8f853
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 }
}
@claybridges
claybridges / gist:c289d5fa6e3e386e8921
Last active Oct 9, 2016
Use rvm in a shell script
View gist:c289d5fa6e3e386e8921
#!/usr/bin/env bash
# Xcode scripting does not invoke rvm. To get the correct ruby,
# we must invoke rvm manually. This requires loading the rvm
# *shell function*, which can manipulate the active shell-script
# environment.
# cf. http://rvm.io/workflow/scripting
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@claybridges
claybridges / gist:8ca22217830e0ce1a0f1
Last active Oct 12, 2016
Just an easier format for code from this SO question (not mine): http://stackoverflow.com/questions/25311736.
View gist:8ca22217830e0ce1a0f1
- (void) addTasksToSessionWithTaskObject:(Task*)taskObject withSessionInitialisationNeeded:(BOOL) needed{
NSString *filePath = [[NSBundle mainBundle] pathForResource:pathForResourceFile ofType:resourceFileType];
S3PutObjectRequest *putObjectRequest = [[S3PutObjectRequest alloc] initWithKey:targetFileKey
inBucket:_bucketname];
putObjectRequest.cannedACL = [S3CannedACL publicReadWrite];
putObjectRequest.filename = filePath;
putObjectRequest.contentType = [resourceFileType isEqualToString:@"MOV"] ? @"movie/mov" : @"image/jpg";
putObjectRequest.endpoint = @"http://s3.amazonaws.com";
putObjectRequest.contentLength=[[[NSFileManager defaultManager]
@claybridges
claybridges / unicode_bracketish.txt
Last active Jun 11, 2021
Comes from this SO answer: http://stackoverflow.com/a/13535289/45813. Per answerer's direction, `DOUBLE ANGLE QUOTATION MARK`s edited to correct for bash error.
View unicode_bracketish.txt
LEFT PARENTHESIS (U+0028, Ps): (
RIGHT PARENTHESIS (U+0029, Pe): )
LEFT SQUARE BRACKET (U+005B, Ps): [
RIGHT SQUARE BRACKET (U+005D, Pe): ]
LEFT CURLY BRACKET (U+007B, Ps): {
RIGHT CURLY BRACKET (U+007D, Pe): }
LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00AB, Pi): «
RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (U+00BB, Pf): »
TIBETAN MARK GUG RTAGS GYON (U+0F3A, Ps): ༺
TIBETAN MARK GUG RTAGS GYAS (U+0F3B, Pe): ༻