Skip to content

Instantly share code, notes, and snippets.

View brennanMKE's full-sized avatar

Brennan Stehling brennanMKE

View GitHub Profile
@brennanMKE
brennanMKE / pi.sh
Created March 14, 2014 21:17
Run `pod install` and check if Ruby will require sudo
#!/bin/sh
RUBY=`which ruby`
if [[ $RUBY = '/usr/bin/ruby' ]] ; then
echo "error: You must run the following command from the command-line."
echo "sudu gem pod install"
else
if [[ -e 'Podfile' ]]; then
gem pod install
@brennanMKE
brennanMKE / wta.sh
Last active August 29, 2015 13:57
What The Archive
#!/bin/sh
// What The Archive!
// The argument passed in should be the Xcode project name so it can find and run lipo on each archive to
// look for each of the supported architectures to help the developer see what is there and what is missing.
// It looks in the DerivedData folder for the most recent matching folder using the given project name.
PROJECT_NAME=$1
BASE_DIR=~/Library/Developer/Xcode/DerivedData/
@brennanMKE
brennanMKE / indexPathForViewInTableView.m
Last active August 29, 2015 13:57
indexPathForView:inTableView:
- (NSIndexPath *)indexPathForView:(UIView *)view inTableView:(UITableView *)tableView {
UIView *superview = view;
while (superview && ![superview isKindOfClass:[UITableViewCell class]]) {
superview = superview.superview;
}
if ([superview isKindOfClass:[UITableViewCell class]]) {
NSIndexPath *indexPath = [tableView indexPathForCell:(UITableViewCell *)superview];
return indexPath;
}
@brennanMKE
brennanMKE / embedGists.js
Last active August 29, 2015 13:58
Embed Gists
$(function() {
var gistPrefix = 'https://gist.github.com/';
var embedGists = function() {
$('a[href^="' + gistPrefix + '"]').each(function(index, anchor) {
var href = $(anchor).attr('href');
var gistId = href.substring(gistPrefix.length);
var url = gistPrefix + gistId + '.json?callback=?';
$.getJSON(url, function(gistData) {
var cssUrl = gistPrefix + gistData.stylesheet;
@brennanMKE
brennanMKE / epsilon.m
Last active August 29, 2015 13:58
Usage of __FLT_EPSILON__ in UIImage-BlurredFrame
BOOL hasBlur = blurRadius > __FLT_EPSILON__;
BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
@brennanMKE
brennanMKE / testaccuracy.m
Last active February 26, 2016 06:12
Test accuracy with an Epsilon value
XCTAssertEqualWithAccuracy(image.size.width, 1, FLT_EPSILON, @"Invalid image width");
XCTAssertEqualWithAccuracy(image.size.height, 1, FLT_EPSILON, @"Invalid image height");
@brennanMKE
brennanMKE / screenshotOfView.m
Last active December 3, 2020 11:40
Screenshot of a view excluding views
- (UIImage *)screenshotOfView:(UIView *)view excludingViews:(NSArray *)excludedViews {
if (!floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
NSCAssert(FALSE, @"iOS 7 or later is required.");
}
// hide all excluded views before capturing screen and keep initial value
NSMutableArray *hiddenValues = [@[] mutableCopy];
for (NSUInteger index=0;index<excludedViews.count;index++) {
[hiddenValues addObject:[NSNumber numberWithBool:((UIView *)excludedViews[index]).hidden]];
((UIView *)excludedViews[index]).hidden = TRUE;
+ (CGFloat)widthForAttributedString:(NSAttributedString *)text maxHeight:(CGFloat)maxHeight {
CGSize size = [self sizeForAttributedString:text maxSize:CGSizeMake(CGFLOAT_MAX, maxHeight)];
return size.width;
}
+ (CGFloat)widthForString:(NSString *)text font:(UIFont *)font maxHeight:(CGFloat)maxHeight {
CGSize size = [self sizeForString:text font:font maxSize:CGSizeMake(CGFLOAT_MAX, maxHeight)];
return size.width;
}
@brennanMKE
brennanMKE / random_key.sql
Last active August 29, 2015 14:00
Random Key for Check Ins with a PostgreSQL database
-- Example table for check ins (adjust to use real tables)
-- Table: check_ins
-- DROP TABLE check_ins;
CREATE TABLE check_ins
(
check_in_id serial NOT NULL,
check_in_key character varying(20) NOT NULL,
note text NULL,
- (void)openLyft {
NSURL *lyftURL =[NSURL URLWithString:@"fb275560259205767://"];
if ([[UIApplication sharedApplication] canOpenURL:lyftURL]) {
[[UIApplication sharedApplication] openURL:lyftURL];
}
else {
NSString *appStoreLink = @"itms-apps://itunes.apple.com/us/app/lyft/id529379082?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreLink]];
}
}