Skip to content

Instantly share code, notes, and snippets.

View casademora's full-sized avatar

Saul Mora casademora

View GitHub Profile
@drewmccormack
drewmccormack / gist:5262375
Created March 28, 2013 11:03
A category method for NSArray that facilitates enumeration with regular draining of the autorelease pool. Useful for those long, memory accumulating loops.
@implementation NSArray (AutoreleasePoolDraining)
-(void)enumerateObjectsDrainingEveryIterations:(NSUInteger)iterationsBetweenDrains usingBlock:(void (^)(id object, NSUInteger index, BOOL *stop))block
{
NSUInteger total = 0;
NSUInteger count = self.count;
NSUInteger numberOfChunks = (count / MAX(1,iterationsBetweenDrains) + 1);
BOOL stop = NO;
for ( NSUInteger chunk = 0; chunk < numberOfChunks; chunk++ ) {
@autoreleasepool {
@mpospese
mpospese / CGRectIntegralScaled.m
Created February 28, 2013 03:34
Pixel aligns rectangles, taking the device's screen scale into account.
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}
@mikeabdullah
mikeabdullah / gist:4740463
Last active January 6, 2024 07:31
Atomic file copying
- (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL
toURL:(NSURL *)destinationURL
error:(NSError **)outError
{
NSFileManager *manager = [NSFileManager defaultManager];
// First copy into a temporary location where failure doesn't matter
NSURL *tempDir = [manager URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask
appropriateForURL:destinationURL
+ (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context
{
NSMutableArray *objects = [NSMutableArray array];
[listOfObjectData enumerateObjectsWithOptions:0
usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary * dict = obj;
if([dict isKindOfClass:[NSDictionary class]])
@AlanQuatermain
AlanQuatermain / ChangeLicenses.rb
Created January 6, 2013 17:27
I needed to go through a large number of Xcode-generated source-code files the other day, replacing the copyright line with a license header statement. Since there were lots of files in a nested structure I decided to use a script, and I added in a glob pattern to exclude certain files/folders— because there was some public domain source in ther…
#!/usr/bin/ruby
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active April 20, 2025 10:20
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
@alloy
alloy / Instructions.md
Created June 28, 2012 12:56
Run iOS unit tests (in a Xcode workspace) when a file changes and *only* those tests related to the changed file. Also trims otest output and colors test results.
@c0diq
c0diq / Xcode4HockeyAppTestFlightintegration.sh
Created March 27, 2012 07:13
Automatic TestFlight/HockeyApp Upload XCode Script
#!/bin/bash
#
# (Above line comes out when placing in Xcode scheme)
#
# Inspired by original script by incanus:
# https://gist.github.com/1186990
#
# Rewritten by martijnthe:
# https://gist.github.com/1379127
#
@c0diq
c0diq / gist:2213492
Created March 27, 2012 07:02
Automatic CFBundleVersion increment Build Pre-Action Scheme
#!/bin/bash
if [[ $CONFIGURATION == *Adhoc* ]]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${PROJECT_DIR}/${INFOPLIST_FILE})
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" ${PROJECT_DIR}/${INFOPLIST_FILE}
fi
@tonyarnold
tonyarnold / gist:2010649
Created March 10, 2012 07:22
Exhaustively check if an Objective-C object is "empty"
static inline BOOL CBIsEmpty(id obj) {
return obj == nil
|| (NSNull *)obj == [NSNull null]
|| ([obj respondsToSelector:@selector(length)] && [obj length] == 0)
|| ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}