Skip to content

Instantly share code, notes, and snippets.

View brennanMKE's full-sized avatar

Brennan Stehling brennanMKE

View GitHub Profile
@brennanMKE
brennanMKE / hybridPaging.m
Last active August 29, 2015 14:06
Hybrid Paging for table and collection views
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
// if the velocity is "slow" it should just go the next cell, otherwise let it go to the next paged position
// positive x is moving right, negative x is moving left
// slow is < 2.0
CGFloat width = CGRectGetWidth(self.collectionView.frame);
NSUInteger currentIndex = MAX(MIN(round(self.collectionView.contentOffset.x / CGRectGetWidth(self.collectionView.frame)), kNumberOfItems - 1), 0);
if (fabsf(velocity.x) > 2.0) {
CGFloat x = targetContentOffset->x;
@brennanMKE
brennanMKE / lookup.js
Created October 21, 2014 23:27
Facebook Lookup
// Dependencies:
// "rest": "^1.2.0",
// "when": "^3.4.6"
var when = require('when');
var rest = require('rest');
// allows promises to be passed in as an array
var waitForPromises = function(promises) {
return when.join.apply(this, promises);
@brennanMKE
brennanMKE / isNowAGoodTimeForADrink.m
Created December 14, 2014 01:09
isNowAGoodTimeForADrink
- (BOOL)isNowAGoodTimeForADrink {
NSDate *now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday|NSCalendarUnitHour fromDate:now];
BOOL isWeekend = components.weekday == 7 || components.weekday == 0; // sat or sun
// it is a good time for a drink on weekends after 11am and weekdays after 5pm
return (isWeekend && components.hour >= 11) || (!isWeekend && components.hour >= 17);
}
@brennanMKE
brennanMKE / ParseCrashReporting.sh
Last active August 29, 2015 14:13
Parse Crash Reporting build script
# Input Files
# $(DWARF_DSYM_FOLDER_PATH)/$(DWARF_DSYM_FILE_NAME)
# Output Files
# $(DERIVED_FILE_DIR)/ParseCrashReporting.txt
echo "Parse Crash Reporting"
CLOUD_CODE_DIR=${PROJECT_DIR}/ParseCloudCode
@brennanMKE
brennanMKE / .bash_profile
Last active June 20, 2018 23:12
Open in Visual Studio Code
# Add the alias below to ~/.bash_profile on a Mac
# Save the file and run: source ~/.bash_profile
alias code='open $@ -a "Visual Studio Code"'
@brennanMKE
brennanMKE / testEnums.m
Last active August 29, 2015 14:21
Enums and bit shifted values
#import <XCTest/XCTest.h>
// When setting bit shifted values use NS_OPTIONS instead of NS_ENUM
// set the value using bit shifting
typedef NS_OPTIONS(NSUInteger, MyState) {
MyStateNone = 0, // (0000 = 0)
MyStateOn = (1 << 0), // (0001 = 1)
MyStateOff = (1 << 1), // (0010 = 2)
MyStateEnabled = (1 << 2), // (0100 = 4)
@brennanMKE
brennanMKE / loginStatusEnums.m
Created May 13, 2015 00:04
Enums for login status and user state
#import <XCTest/XCTest.h>
typedef NS_OPTIONS(NSUInteger, LoginState) {
LoginStateNone = 0,
LoginStateSuccess = (1 << 0),
LoginStateFailure = (1 << 1),
LoginStateIncomplete = (1 << 2),
};
#pragma mark - Font Size
#pragma mark -
// Origin: Facebook SDK in FBSDKUIUtility.h (2015)
CG_INLINE CGSize ceilForSize(CGSize value) {
return CGSizeMake(ceil(value.width), ceil(value.height));
}
- (CGSize)getTextSize:(NSString *)text font:(UIFont *)font constrainedSize:(CGSize)constrainedSize lineBreakMode:(NSLineBreakMode)lineBreakMode {
@brennanMKE
brennanMKE / enums.m
Last active August 29, 2015 14:21
Enums
//// Making Code More Readable with Enums and Bitwise Operators
// simple enum
typedef enum {
StatusNone,
StatusSuccess,
StatusError,
} Status;
@brennanMKE
brennanMKE / .lldbinit
Last active March 17, 2016 16:40
LLDB Config
# LLDB Init
# http://lldb.llvm.org/tutorial.html
# Import Frameworks
# http://furbo.org/2015/05/11/an-import-ant-change-in-xcode/
command alias uikit expr @import UIKit
command alias foundation expr @import Foundation
# Facebook Chisel
command script import /usr/local/opt/chisel/libexec/fblldb.py