Skip to content

Instantly share code, notes, and snippets.

View rcdilorenzo's full-sized avatar
🙌
Working in His Kingdom (Col 3:17)

Christian Di Lorenzo rcdilorenzo

🙌
Working in His Kingdom (Col 3:17)
View GitHub Profile
#import <Foundation/Foundation.h>
@interface NSObject (Swizzling)
- (void)swizzleMethod:(SEL)originalSelector toMethod:(SEL)newSelector;
@end
@rcdilorenzo
rcdilorenzo / UIViewSubclass.m
Created October 23, 2013 13:36
A piece of code for doing auto layout in a UIView subclass
// Declare this property in your header / private header
@property (nonatomic, strong) NSMutableArray *updatingConstraints;
- (void)updateConstraints {
if (self.updatingConstraints) {
[self removeConstraints:self.updatingConstraints];
}
self.updatingConstraints = [NSMutableArray array];
// Create and add all of your constraints here
#import <UIKit/UIKit.h>
@interface SODimButton : UIButton
@property (nonatomic, strong) UIColor *buttonColor;
@property (nonatomic, strong) UIColor *selectedButtonColor;
@property (nonatomic) CGFloat backgroundAlpha;
@end
@rcdilorenzo
rcdilorenzo / UIStoryboard+LDMain.h
Last active December 25, 2015 07:49
Get the main storyboard in an iOS app as set by the .plist file. (You may need to change the return type to id if you are on 6.1 or earlier.)
#import <UIKit/UIKit.h>
@interface UIStoryboard (LDMain)
+ (instancetype)mainStoryboard;
@end
@rcdilorenzo
rcdilorenzo / log.txt
Created October 3, 2013 13:55
DocsetViewer for iPad symbolicated log
Incident Identifier: 522DD016-33ED-4B63-B412-AAA86ADD0C6E
CrashReporter Key: 23e49df87511097784dee7a45d876f55f889ff39
Hardware Model: iPad2,3
Process: DocsetViewer [650]
Path: /var/mobile/Applications/027B8708-30A6-474D-9239-110622BD5F1E/DocsetViewer.app/DocsetViewer
Identifier: com.decafninja.docsetviewer
Version: 208 (1.4.1)
Code Type: ARM (Native)
Parent Process: launchd [1]
@rcdilorenzo
rcdilorenzo / gist:6437406
Last active December 22, 2015 07:19
CoreGraphics - clipping an inner circle (used in reference to a Stack Overflow question: http://stackoverflow.com/questions/18614376/calayer-clip-cgcontextaddarc-making-a-donut-slide-pie-chart
- (void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)) radius:CGRectGetHeight(self.bounds) startAngle:0 endAngle:2.0*M_PI clockwise:YES];
[path addArcWithCenter:CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)) radius:100 startAngle:0 endAngle:2.0*M_PI clockwise:NO];
[path addClip];
self.layer.cornerRadius = 10.0;
CGFloat colors[12] = {
0.1, 0.18, 0.54, 1.0,
#define IMAGE_WIDTH 100.0
#define IMAGE_HEIGHT 100.0
@implementation SOMaskScrollView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
// Initialization code
@rcdilorenzo
rcdilorenzo / gist:3379731
Created August 17, 2012 15:14
Ruby-Like select for Array
Array::select = (requestedElement) ->
count = {}
array = []
for element in this
count[element] = (count[element] || 0) + 1
if count[requestedElement]
for i in [1..count[requestedElement]]
array.push(requestedElement)
return array
else
@rcdilorenzo
rcdilorenzo / gist:3179889
Created July 26, 2012 02:18
IBAction for presenting modal controller with custom setup
- (IBAction)startGame:(id)sender {
LDNViewController *ldnVC = [self.storyboard instantiateViewControllerWithIdentifier:@"gameController"];
if (playerNameField.text != @"" && playerNameField.text != nil) {
ldnVC.game = [[LDNGoFishGame alloc] init];
[ldnVC.game setupWithLivePlayer:playerNameField.text];
[self presentModalViewController:ldnVC animated:YES];
}
}
@rcdilorenzo
rcdilorenzo / modeOfArray.m
Created July 25, 2012 18:19
Find Mode of Array in Obj C
NSMutableArray *cardRanks = [[NSMutableArray alloc] init];
for (LDNPlayingCard *card in self.cards) {
[cardRanks addObject:card.rank];
}
NSCountedSet *bagOfCardRanks = [[NSCountedSet alloc] initWithArray:cardRanks];
NSString *modeOfRanks = [[NSString alloc] init];
NSUInteger highestElementCount = 0;
for (NSString *rank in bagOfCardRanks) {
if ([bagOfCardRanks countForObject:rank] > highestElementCount) {
highestElementCount = [bagOfCardRanks countForObject:rank];