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 / 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();
};
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 }
}
(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 / 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()
{
@claybridges
claybridges / gist:4658680
Created January 28, 2013 20:24
Objective-C ProtocolContainsInstanceSelector
BOOL ProtocolContainsInstanceSelector(NSString *protocolName, SEL sel);
BOOL ProtocolContainsInstanceSelector(NSString *protocolName, SEL sel)
{
Protocol *p = objc_getProtocol([protocolName cStringUsingEncoding:NSUTF8StringEncoding]);
// must check for both required = {YES, NO}
struct objc_method_description desc = protocol_getMethodDescription(p, sel, YES, YES);
BOOL contains = desc.name != NULL && desc.types != NULL;
if (!contains) {
@claybridges
claybridges / gist:5849621
Last active December 18, 2015 21:48
HexNSStringFromBytes
NSString *HexNSStringFromBytes(uint8_t *bytes, NSUInteger count) {
char *hexCString = calloc(count * 2 + 1, sizeof(char *));
static char hexLookup[] = "0123456789abcdef";
NSMutableString* testString = [NSMutableString string];
for (int i = 0; i < count; ++i) {
uint8_t fullByte = bytes[i];
// each byte converts to two hex characters
@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
@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: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 / 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];
}