This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreMotion | |
public class Main | |
{ | |
var motionManager:CMMotionActivityManager! | |
let motionHandler:CMMotionActivityHandler! = { (activity:CMMotionActivity?) -> Void in | |
let desc = activity?.debugDescription ?? "no activity" | |
println("activity is \(desc)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// profiler.h | |
// Quick and dirty profiler | |
// | |
// Created by Niels Gabel on 9/1/08. | |
// | |
// Copyright 2008-2011 Niels Gabel | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds support for loading UIImage's from PDF files. I think it's a great way to add resolution-independent graphics to your apps, and also remove the "export to bitmap" step from your workflow. Just save directly from Illustrator! | |
What it does: | |
- You can pass the name of a PDF file (with or without the '.pdf') to +[UIImage imageNamed:] | |
- You can use the name of a PDF file inside Interface Builder, in your UIImageView's | |
- Turn a multi-page PDF into an array of UIImage's... good for animation. | |
Feedback to gists @nielsbot.com. Thanks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIView (PositionAtCenter) | |
-(void)centerPixelAligned:(CGPoint)p | |
{ | |
CGSize size = self.bounds.size ; | |
p.x = floorf( p.x ) + 0.5 * fmodf( size.width, 2.0f ) ; | |
p.y = floorf( p.y ) + 0.5 * fmodf( size.height, 2.0f ) ; | |
self.center = p; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PropertyContainer.h | |
// | |
// Created by Niels Gabel on 12/14/11. | |
// Copyright (c) 2011 DoubleDutch Inc. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface PropertyContainer : NSObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface AppDelegate : UIResponder <UIApplicationDelegate> | |
@property (strong, nonatomic) IBOutlet UIWindow *window; | |
@property ( strong ) IBOutlet UITextField * textField ; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSNull (IfNullThenNil) | |
-(id)ifNullThenNil { return nil ; } | |
@end | |
@implementation NSObject (IfNullThenNil) | |
-(id)ifNullThenNil { return self ; } | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static CGColorRef CGColorCreateWithCSSColor( NSString * string ) | |
{ | |
union { | |
struct { | |
#if LITTLE_ENDIAN | |
uint8 alpha ; | |
uint8 blue ; | |
uint8 green ; | |
uint8 red ; | |
#else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// when setting the position of a layer, use this: | |
// layer.position = [ layer pixelAlignedPostionForPoint:<originalPoint> ] ; | |
@implementation CALayer (SetPositionPixelAligned) | |
-(CGPoint)pixelAlignedPositionForPoint:(CGPoint)p | |
{ | |
CGSize size = self.bounds.size ; | |
CGPoint anchorPoint = self.anchorPoint ; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NWGKeyValueObserving.h | |
// by nielsbot ( nielsbot@nielsbot.com) | |
typedef void (^KeyValueObserverBlock)( NSDictionary * change ) ; | |
@interface NWGKeyValueObserver : NSObject | |
@property ( nonatomic, readonly, copy ) NSString * keyPath ; | |
@property ( nonatomic, readonly ) id target ; | |
@property ( nonatomic, readonly ) NSKeyValueObservingOptions options ; |
OlderNewer