Skip to content

Instantly share code, notes, and snippets.

@mattyohe
mattyohe / gist:6392485
Created August 30, 2013 17:48
STRINGIFY
#include <stdio.h>
#define stringify(VALUE) # VALUE
enum {
DERP,
DERRRRP
};
int main(void) {
#pragma mark - Utilities
/*! Returns the major version of iOS, for iOS 6.1.3 it returns 6.
*/
NSUInteger DeviceSystemMajorVersion()
{
static NSUInteger _deviceSystemMajorVersion = -1;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@mattyohe
mattyohe / gist:6195538
Created August 9, 2013 17:41
Make an image out of a color
+ (UIImage*)imageWithSize:(CGSize)size color:(UIColor*)color
{
UIView *view = [[UIView alloc] initWithSize:size];
view.backgroundColor = color;
UIGraphicsBeginImageContextWithOptions(size, YES, 0);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0);
[[view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@mattyohe
mattyohe / gist:6122602
Created July 31, 2013 14:44
Wouldn't it be nice to have a UIBackdropView?
@interface _UIBackdropEffectView : UIView
{
CABackdropLayer *_backdropLayer;
float _zoom;
}
+ (Class)layerClass;
@property(nonatomic) float zoom; // @synthesize zoom=_zoom;
@property(retain, nonatomic) CABackdropLayer *backdropLayer; // @synthesize backdropLayer=_backdropLayer;
- (void)backdropLayerStatisticsDidChange:(id)arg1;
@mattyohe
mattyohe / gist:6122600
Created July 31, 2013 14:44
Wouldn't it be nice to have a UIBackdropView?
@interface _UIBackdropEffectView : UIView
{
CABackdropLayer *_backdropLayer;
float _zoom;
}
+ (Class)layerClass;
@property(nonatomic) float zoom; // @synthesize zoom=_zoom;
@property(retain, nonatomic) CABackdropLayer *backdropLayer; // @synthesize backdropLayer=_backdropLayer;
- (void)backdropLayerStatisticsDidChange:(id)arg1;
@mattyohe
mattyohe / gist:6040298
Last active December 20, 2015 00:18
NSURL is dumb.
NSString *str = @"http://example.com/å.png";
NSURL *url = [NSURL URLWithString:str];
NSLog(@"%@",url); // NOPE!
NSString *str = @"http://example.com/å.png";
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:str];
NSLog(@"%@",url); // YUP!
@implementation UICollectionView (TEST)
-(void)setContentSize:(CGSize)contentSize
{
[super setContentSize:contentSize];
NSLog(@"%@",NSStringFromCGSize(contentSize));
}
@end
UIBackgroundTaskIdentifier taskId = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
}];
/// Do something...
double delayInSeconds = 3.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
@mattyohe
mattyohe / gist:5847202
Created June 24, 2013 01:26
Calculate height, width...
void DrawStringInRect(NSString *string, CGRect rect, UIFont *font, NSTextAlignment alignment, UIColor *color)
{
CGContextRef context = UIGraphicsGetCurrentContext();
if (context == NULL) return;
NSRange range = NSMakeRange(0, string.length);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
+ (NSString *) ipsum:(NSUInteger) numberOfParagraphs
{
NSString *urlString = [NSString stringWithFormat:@"http://loripsum.net/api/%0d/short/prude/plaintext", numberOfParagraphs];
NSError *error;
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&error];
if (!string)
{
NSLog(@"Error: %@", error.localizedDescription);
return nil;