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 / NSArrayDiff.h
Created August 26, 2016 15:25
A class to diff between two types of arrays (take a look at the test to see how it works)
#import <Foundation/Foundation.h>
typedef BOOL(^NSArrayDiffMatch)(id _Nonnull original, id _Nonnull comparedTo);
@interface NSArrayDiff : NSObject
+ (instancetype _Nonnull)newWithOriginal:(NSArray * _Nonnull)original
diffedAgainst:(NSArray * _Nonnull)compareTo
match:(NSArrayDiffMatch _Nonnull)match;
@rcdilorenzo
rcdilorenzo / calculator.erl
Created March 30, 2016 21:58
A dead simple erlang module for calculating the sum of the first N numbers or factorial of N
-module(calculator).
-export([sum/1, sum/2, factorial/1, factorial/2]).
sum(N) when N > 0 ->
sum(N, 0).
sum(N, Current) when N > 0 ->
sum(N-1, Current+N);
sum(0, Current) ->
defmodule Standard do
def fib(0), do: 0
def fib(1), do: 1
def fib(n), do: fib(n-1) + fib(n-2)
end
defmodule Optimized do
def fib(0), do: 0
def fib(1), do: 1
def fib(1, current, _), do: current
@rcdilorenzo
rcdilorenzo / KIFUITestActor+Generic.m
Created December 12, 2013 16:11
A KIF extension to allow tapping a cell based on its name
- (void)tapCellWithName:(NSString *)name inTableViewWithAccessibilityLabel:(NSString *)accessibilityLabel {
[tester runBlock:^KIFTestStepResult(NSError *__autoreleasing *error) {
UITableView *tableView = (UITableView *)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
NSIndexPath *foundIndexPath = nil;
for (int section = 0; section < tableView.numberOfSections; section++) {
for (int row = 0; row < [tableView numberOfRowsInSection:section]; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.textLabel.text isEqualToString:name]) {
foundIndexPath = indexPath;
@rcdilorenzo
rcdilorenzo / comments.txt
Created December 11, 2013 20:37
Unique programmer comments
long long ago; /* in a galaxy far far away */
// Replaces with spaces the braces in cases where braces in places cause stasis
$str = str_replace(array("\{","\}")," ",$str);
#define TRUE FALSE //Happy debugging suckers
// sometimes I believe compiler ignores all my comments
// I am not sure if we need this, but too scared to delete.
@rcdilorenzo
rcdilorenzo / gist:7169910
Created October 26, 2013 14:14
Animating constraints in the method "updateConstraints"
- (void)animateConstraints {
[self setNeedsUpdateConstraints];
[UIView animateWithDuration:0.4 animations:^{
[self layoutIfNeeded];
}];
}
#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