Skip to content

Instantly share code, notes, and snippets.

View ryanmaxwell's full-sized avatar

Ryan Maxwell ryanmaxwell

  • Auckland, New Zealand
View GitHub Profile
@ryanmaxwell
ryanmaxwell / gist:1983009
Created March 6, 2012 02:37
UIImage Resizing Utility Methods
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)size {
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(size);
}
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
@ryanmaxwell
ryanmaxwell / gist:1989630
Created March 6, 2012 23:04
Escape NSString so that it can be passed to webview
- (NSString *)stringByEscapingJSONReservedCharacters {
return [[[[[[[[self stringByReplacingOccurrencesOfString:@"\\\\" withString:@"☃"] /* \\ (single slash character) for snowman */
stringByReplacingOccurrencesOfString:@"\\n" withString:@"\\\\n"] /* \n for \\n */
stringByReplacingOccurrencesOfString:@"\\t" withString:@"\\\\t"] /* \t for \\t */
stringByReplacingOccurrencesOfString:@"\\b" withString:@"\\\\b"] /* \b for \\b */
stringByReplacingOccurrencesOfString:@"\\f" withString:@"\\\\f"] /* \f for \\f */
stringByReplacingOccurrencesOfString:@"\\r" withString:@"\\\\r"] /* \r for \\r */
stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\\\\\""] /* \" for \\" */
stringByReplacingOccurrencesOfString:@"☃" withString:@"\\\\\\\\"]; /* snowman for \\\\ (single slash character) */
}
@ryanmaxwell
ryanmaxwell / ryan-objc.cfg
Last active June 26, 2019 16:41
Objective-C Uncrustify Config
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.2 (140)
#
# Alignment
# ---------
## Alignment
@ryanmaxwell
ryanmaxwell / gist:4999567
Last active December 14, 2015 00:29
NSString+GroupedDelimitedString Category
#import <Foundation/Foundation.h>
@interface NSString (GroupedDelimitedString)
- (NSString *)stringByGroupingBySize:(NSInteger)groupSize withDelimiter:(NSString *)delimiter;
@end
@ryanmaxwell
ryanmaxwell / NSString+Comparisons.h
Last active December 14, 2015 22:28
NSString+Comparisons
@interface NSString (Comparisons)
- (BOOL)containsString:(NSString *)substring;
- (BOOL)isSubstringOfString:(NSString *)string;
- (BOOL)isEqualToAnyOfStrings:(NSArray *)strings;
- (BOOL)isEqualToNoneOfStrings:(NSArray *)strings;
@end
@ryanmaxwell
ryanmaxwell / gist:6227531
Last active December 21, 2015 01:28
Useful utility method to get the most appropriate image resource from the main bundle for the device based on filename. Fills a need until the new asset packages in Xcode 5 is released.
+ (UIImage *)imageResource:(NSString *)name ofType:(NSString *)type {
NSString *systemVersion = UIDevice.currentDevice.systemVersion;
NSString *iOSMajorSystemVersion = (systemVersion.length) ? [NSString stringWithFormat:@"iOS%@", [systemVersion substringToIndex:1]] : @"iOS";
if (UIScreen.mainScreen.bounds.size.height == 568.0f) {
/* iPhone 5 */
NSString *iPhone5SystemVersionImageName = [NSString stringWithFormat:@"%@-%@-568h@2x", name, iOSMajorSystemVersion];
NSString *iPhone5SystemVersionImagePath = [NSBundle.mainBundle pathForResource:iPhone5SystemVersionImageName ofType:type];
@ryanmaxwell
ryanmaxwell / TXLocation.h
Last active December 23, 2015 01:19
Mantle JSON Mapping Example
@interface TXLocation : MTLModel <MTLJSONSerializing>
@property (strong, nonatomic, readonly) NSString *status;
@property (strong, nonatomic, readonly) NSNumber *sector;
@property (strong, nonatomic, readonly) NSString *macAddress;
@property (strong, nonatomic, readonly) NSNumber *facilityId;
@property (strong, nonatomic, readonly) NSNumber *departmentId;
@property (strong, nonatomic, readonly) NSNumber *mapId;
@property (strong, nonatomic, readonly) NSNumber *mapVersion;
@ryanmaxwell
ryanmaxwell / blinds.lua
Last active April 30, 2019 10:45
Fibaro HC2 Scene for dimmer S2 switch button to trigger open/close/pause of multiple blinds in a room
--[[
%% properties
378 sceneActivation
%% weather
%% events
%% globals
--]]
function anyBlindIsClosed(blindIDs)
for index, blindID in ipairs(blindIDs) do