Skip to content

Instantly share code, notes, and snippets.

@amleszk
amleszk / gist:5225924
Created March 23, 2013 01:13
Hack to get around Facebook keyboard hiding, to keep compatibility for another hack to UIWindowLevel described here:(http://stackoverflow.com/questions/3753097/how-to-detect-touches-in-status-bar)
-(void) presentShareController:(SLComposeViewController*)shareCompose
{
if ([shareCompose.serviceType isEqualToString:SLServiceTypeFacebook]) {
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIWindowLevel prevWindowLevel = window.windowLevel;
window.windowLevel = UIWindowLevelNormal;
SLComposeViewControllerCompletionHandler handler = shareCompose.completionHandler;
shareCompose.completionHandler = ^(SLComposeViewControllerResult result){
@amleszk
amleszk / utableview reordering cells
Last active December 15, 2015 15:09
Example code to re-order all cells in a tableview
int toIndex=0;
[self.tableView beginUpdates];
for (NSDictionary* reddit in sortedReddits) {
NSString *displayName = [reddit valueForKeyPath:@"data.display_name"];
NSUInteger fromIndex =
[_reddits indexOfObjectPassingTest:^BOOL(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
if ([[obj valueForKeyPath:@"data.display_name"] isEqualToString:displayName] ) {
*stop = YES;
return YES;
}
int toIndex=0;
[self.tableView beginUpdates];
for (NSDictionary* reddit in sortedReddits) {
NSString *displayName = [reddit valueForKeyPath:@"data.display_name"];
NSUInteger fromIndex =
[_reddits indexOfObjectPassingTest:^BOOL(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
if ([[obj valueForKeyPath:@"data.display_name"] isEqualToString:displayName] ) {
*stop = YES;
return YES;
}
#import <XCTest/XCTest.h>
typedef id (^OperationToExchangeForClass)(void);
@interface RCTestCase : XCTestCase
- (void) exchangeClassMethodForClass:(Class)clazz selector:(SEL)selector operation:(OperationToExchangeForClass)operation;
@property (nonatomic) NSBundle *unitTestBundle;
@amleszk
amleszk / gist:c79d0f6701022a91d8da
Created May 14, 2014 21:11
Adding a query string to an NSURL
#import "NSURL+MUAdditions.h"
@implementation NSURL (MUAdditions)
-(NSURL*) URLByAppendingQueryString:(NSString*)queryString
{
NSString *absoluteString = [self absoluteString];
NSInteger startOfQueryString = [absoluteString rangeOfString:@"?"].location;
NSInteger startOfFragment = [absoluteString rangeOfString:@"#"].location;
@amleszk
amleszk / gist:3ad63f5fd8b164fb1149
Created October 3, 2014 16:08
post_install xcode example
post_install do |installer|
project = Xcodeproj::Project.open('MeetupApp.xcodeproj')
config_mapping = {
:Debug => 'Configuration/Debug.xcconfig'
}
set_xcconfig_reference(project,'MeetupApp','Debug','Configuration/Debug.xcconfig')
end
def set_xcconfig_reference(project, target_name, config_name, xcconfig_name)
@amleszk
amleszk / gist:7f93e55e5cbbf41ec9fb
Last active August 29, 2015 14:08
Example of main thread safety for Core data
//RCCoreData helper class
+(BOOL) onMainThread:(void (^)(void))mainThreadOperation
{
BOOL isMainThread = [NSThread isMainThread];
NSAssert(isMainThread, @"Should be on main thread");
if (isMainThread) {
mainThreadOperation();
} else {
dispatch_async(dispatch_get_main_queue(), mainThreadOperation);
@amleszk
amleszk / run-scan-build
Created May 27, 2015 21:57
Hinge scan-build wrapper
#!/bin/sh
# run_scan_build.sh
# Hinge
#
# Created by al on 27/05/2015.
# Copyright (c) 2015 Hinge, Inc. All rights reserved.
CLANG_CHECK="Xcode"
XCODE_COMPILER_LOCATION="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
ibrary/Caches/Snapshots
2015-06-30 17:58:50.852 <Notice> ======== HNGConfigurationService AppStore, Beta, production Hinge, 3.5.0 (10356) 2015.06.30, iPhone6,1 8.3 ========
2015-06-30 17:58:51.022 <Notice> Breadcrumb: Using configuration: Beta
2015-06-30 17:58:51.088 <Notice> Breadcrumb: begin transaction UARegistration
2015-06-30 17:58:51.414 <Error> -[DatabaseManager initialisePersistentStore] [Line 196] [NSCocoaErrorDomain(259)] The operation couldn’t be completed. (Cocoa error 259.) {
NSSQLiteErrorDomain = 11;
NSUnderlyingException = "Fatal error. The database at /var/mobile/Containers/Data/Application/DB1255CB-0CE6-4572-8130-DBD693B8AFFF/Documents/hinge330.sqlite is corrupted. SQLite error code:11, 'database disk image is malformed'";
}
2015-06-30 17:58:51.423 <Notice> Breadcrumb: logged error:The operation couldn’t be completed. (Cocoa error 259.)
2015-06-30 17:58:51.433 <Warning> --- Deleting Store: file:///var/mobile/Containers/Data/Application/DB1255CB-0CE6-4572-8130-DBD693B8AFFF/Documen
@amleszk
amleszk / UIImageView+RestaurantWebImage.h
Created June 22, 2016 13:50
Fallback URL handling in SDWebImage
//
// UIImageView+RestaurantWebImage.h
// DinerApp
//
// Created by ALeszkiewicz on 6/21/16.
// Copyright © 2016 GrubHub Inc. All rights reserved.
//
#import <UIKit/UIKit.h>