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:c289d5fa6e3e386e8921
Last active November 15, 2023 18:10
Use rvm in a shell script
#!/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 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]
@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): ༻
#import <Foundation/Foundation.h>
@interface BarrierOperation : NSOperation
@end
@interface BarrierQueue : NSObject
- (void)addOperation:(NSOperation *)op;
@claybridges
claybridges / BlockAdapter.m
Created March 19, 2014 17:15
Adapt one block type to another, in this case to get rid of commonly unwanted parameters. In this SO answer: http://stackoverflow.com/a/22513387/45813
@class TKState, TKStateMachine;
typedef void (^LongStateBlock)(TKState *state, TKStateMachine *stateMachine);
static inline LongStateBlock Adapter(void(^block)()) {
void(^heapBlock)() = [block copy]; // forces block to be on heap rather than stack, a one-time expense
LongStateBlock longBlock = ^(TKState *s __unused, TKStateMachine *sm __unused) {
heapBlock();
};
@claybridges
claybridges / gist:6156676
Created August 5, 2013 15:10
Problems with the [NSDecimalNumber* -initWithDecimal:] selector? This test crashes on Xcode 4.6.3 vs. OS X 10.8.4.
- (void)testInitWithDecimal {
Method m = class_getInstanceMethod([NSDecimalNumber class], @selector(initWithDecimal:));
const char *types = method_getTypeEncoding(m);
// this will yield:
// +[NSMethodSignature signatureWithObjCTypes:]: unsupported type encoding spec '{?}'
NSMethodSignature *ms = [NSMethodSignature signatureWithObjCTypes:types];
}
@claybridges
claybridges / gist:6132147
Created August 1, 2013 14:53
Test for bug in cache for ext_globalMethodSignatureForSelector, in libextobj.
typedef struct {
Class class;
SEL sel;
} SelStruct; // not sure about the name SelStruct, but works for now
NSString *NSStringFromSelStruct(SelStruct s) {
return [NSString stringWithFormat:@"-[%@ %@]", s.class, NSStringFromSelector(s.sel)];
}
- (void)testCache {
@claybridges
claybridges / ReactiveCocoa.podspec
Last active December 20, 2015 03:09 — forked from tonyarnold/ReactiveCocoa.podspec
Podspec for ReactiveCocoa 2.0-development. A couple of fixes to work by @tonyarnold. See comments for Podfile line.
Pod::Spec.new do |s|
s.name = "ReactiveCocoa"
s.version = "2.0.0dev"
s.summary = "A framework for composing and transforming sequences of values."
s.homepage = "https://github.com/blog/1107-reactivecocoa-is-now-open-source"
s.author = { "Josh Abernathy" => "josh@github.com" }
s.source = { :git => "https://github.com/ReactiveCocoa/ReactiveCocoa.git", :branch => '2.0-development' }
s.license = 'Simplified BSD License'
s.description = "ReactiveCocoa offers:\n" \
"1. The ability to compose operations on future data.\n" \
@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;
}
@claybridges
claybridges / gist:5849642
Last active December 18, 2015 21:48
MD5StringFromBytes
#import <CommonCrypto/CommonDigest.h>
NSString *MD5StringFromBytes(uint8_t *bytes, NSUInteger count)
{
uint8_t md5Bytes[CC_MD5_DIGEST_LENGTH];
CC_MD5(bytes, count, md5Bytes);
// convert to hex string
static char hexLookup[] = "0123456789abcdef";
char hexCString[CC_MD5_DIGEST_LENGTH * 2 + 1]; // each byte converts to two hex characters, plus null terminator