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 / gist:8ca22217830e0ce1a0f1
Last active October 12, 2016 02:06
Just an easier format for code from this SO question (not mine): http://stackoverflow.com/questions/25311736.
- (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]
#import <Foundation/Foundation.h>
@interface BarrierOperation : NSOperation
@end
@interface BarrierQueue : NSObject
- (void)addOperation:(NSOperation *)op;
@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 / 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?
}

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 / 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=
@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 / unicode_bracketish.txt
Last active March 3, 2023 13:39
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.
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): ༻
@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 / gist:6029091
Last active October 10, 2023 14:26
UIInterfaceOrientationMask vs. UIInterfaceOrientation. As far as I know, a function like this isn't available in the API. I derived this from the enum def for UIInterfaceOrientationMask.
// UIInterfaceOrientationMask vs. UIInterfaceOrientation
// As far as I know, a function like this isn't available in the API. I derived this from the enum def for
// UIInterfaceOrientationMask.
inline BOOL OrientationMaskSupportsOrientation(UIInterfaceOrientationMask mask, UIInterfaceOrientation orientation) {
return (mask & (1 << orientation)) != 0;
}