Skip to content

Instantly share code, notes, and snippets.

View ddonovan's full-sized avatar

David Donovan ddonovan

View GitHub Profile
@ddonovan
ddonovan / AppDelegate.m
Created December 10, 2014 21:10
Snippet on adding logging to the app using Lumberjack.
//
// Logging.h
//
#import <CocoaLumberjack/CocoaLumberjack.h>
//
//typedef NS_ENUM(NSUInteger, DDLogLevel) {
// DDLogLevelOff = 0,
// DDLogLevelError = (DDLogFlagError), // 0...00001
// DDLogLevelWarning = (DDLogLevelError | DDLogFlagWarning), // 0...00011
// DDLogLevelInfo = (DDLogLevelWarning | DDLogFlagInfo), // 0...00111
@ddonovan
ddonovan / DebugViewController.m
Last active August 29, 2015 14:11
snippet from DebugTableViewController to collect .log files and zip them into an email attachment.
#import "DebugTableViewController.h"
#import <ZipArchive/ZipArchive.h>
#import <MessageUI/MessageUI.h>
@interface DebugTableViewController ()<MFMailComposeViewControllerDelegate>
@end
@ddonovan
ddonovan / collectionviewcontroller
Created December 3, 2014 06:26
Calculate a cell size for flowlayout in uicollectionview , assuming you want square cells and have 1pt spacing all around.
- (void)viewWillLayoutSubviews;
{
[super viewWillLayoutSubviews];
UICollectionViewFlowLayout *flowLayout = (id)self.collectionViewLayout;
// really should get this value from the Photo class, but for now max thumb of 110px.
CGFloat cellSize = [self calculateCellSizeForMaxImageWidth:110];
flowLayout.itemSize = CGSizeMake(cellSize, cellSize);
}
@ddonovan
ddonovan / collectionview
Created December 3, 2014 06:17
sample of detecting device orientation iOS and changing cell item size in flow layout.
if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
flowLayout.itemSize = CGSizeMake(115.f, 115.f);
} else {
flowLayout.itemSize = CGSizeMake(105.f, 105.f);
}
@ddonovan
ddonovan / hightlight.m
Created November 6, 2014 04:14
Sample of how to add a glow to a UITextField, for something like active control, or error, etc.
- (void)highlightControl: (UITextField *) textField{
;
// textField.layer.cornerRadius = 5;
// textField.clipsToBounds = YES;
// textField.layer.borderWidth = 1;
// textField.layer.borderColor =[[UIColor redColor] CGColor];
textField.layer.masksToBounds = NO;
textField.layer.shadowColor = [[UIColor redColor] CGColor];
textField.layer.shadowOffset = CGSizeZero;
@ddonovan
ddonovan / afnetworking_error_to_json
Created October 19, 2014 04:10
sample of how to change AFHTTPSessionManager : GET response failure block updated to extract the error message sent from server and use inside an NSError object or however you might use it.
failure:^(NSURLSessionDataTask *task, NSError *error) {
//convert error.data back to json
NSError* jsonerror;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:error.userInfo[@"com.alamofire.serialization.response.error.data"] //1
options:kNilOptions
error:&jsonerror];
NSLog(@"json response data %@",json);
@ddonovan
ddonovan / afnetworking_acceptable_status.m
Created October 19, 2014 03:54
sample of how to configure AFNetworking to allow http response codes other than 200 as an acceptable success, which allow the data sent from the server to be serialized to json.
NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(200, 100)];
[mutableIndexSet addIndex:401];
[mutableIndexSet addIndex:403];
_sharedClient.responseSerializer.acceptableStatusCodes = mutableIndexSet;
@ddonovan
ddonovan / event.php
Created June 26, 2014 15:07
Laravel / Github Webhooks
Event::listen('github.webhook', function($payload)
{
Log::info('Github Webhook Push Event fired');
Log::info('Deploying new code because of a commit push by ' . $payload->head_commit->author->name);
Log::info('Deploying commit ID : ' . $payload->after);
// really only need to use this if you have ngrok running and testing the webhook code.
if (App::environment('local'))
{
@ddonovan
ddonovan / start.php
Created May 19, 2014 01:43
Environment detection for larval app.
/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/
@ddonovan
ddonovan / sample.js
Created May 19, 2014 01:34
sample multi part gist for demo
$( ".delete-confirm" ).on('click', function(e) {
var input = $(this);
var form = input.next();
e.preventDefault();
bsconfirm.confirm(function(confirmed){
if(confirmed){
form.submit();
}