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
@rcdilorenzo
rcdilorenzo / rspec_conversion_helper.rb
Created July 18, 2012 16:04
Ruby Test Unit to Rspec Helper
def assert_equal(a, b)
puts "#{a}.should == #{b}"
end
def assert_not_nil(a)
puts "#{a}.should_not == nil"
end
def assert_raise(*all_args)
puts "Cannot convert assert_raise"
@rcdilorenzo
rcdilorenzo / PlayingCard.m
Created July 25, 2012 15:48
Draw Card from Image
- (void)drawFromPosition:(CGPoint)location view:(UIView *)view size:(CGFloat)size {
UIImage *cardImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png", [[self.suit substringToIndex:1] lowercaseString], [[self.rank substringToIndex:1] lowercaseString]]];
UIImageView *cardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, cardImage.size.width*size, cardImage.size.height*size)];
[cardImageView setImage:cardImage];
[view addSubview:cardImageView];
}
@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];
@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 / 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
#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: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,
@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 / 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
#import <UIKit/UIKit.h>
@interface SODimButton : UIButton
@property (nonatomic, strong) UIColor *buttonColor;
@property (nonatomic, strong) UIColor *selectedButtonColor;
@property (nonatomic) CGFloat backgroundAlpha;
@end