Skip to content

Instantly share code, notes, and snippets.

@aspitz
aspitz / Remove SVN
Created June 20, 2013 13:34
This bash command removes SVN from a folder and all it's children
find . -name ".svn" -exec rm -Rf {} \;
@aspitz
aspitz / NSUserDefaults+Utilities
Created June 18, 2013 19:46
Category code to store and retrieve CGPoint and CGRect
#import "NSUserDefaults+Utilities.h"
@implementation NSUserDefaults (Utilities)
- (CGPoint)CGPointForKey:(NSString *)key
{
CGPoint pt = CGPointZero;
NSArray *ptArray = [self objectForKey:key];
if (ptArray != nil)
@aspitz
aspitz / NSWindow+Utilities
Created June 18, 2013 19:44
Category code to position a window based on the upper right hand corner of the screen
#import "NSWindow+Utilities.h"
@implementation NSWindow (Utilities)
- (void)setTopLeftRelativeToMainScreen:(CGPoint)topLeftPt{
CGRect mainScreenVisibleFrame = NSScreen.mainScreen.visibleFrame;
CGPoint pt = CGPointZero;
pt.x = topLeftPt.x;
pt.y = mainScreenVisibleFrame.origin.y + mainScreenVisibleFrame.size.height - topLeftPt.y;
[self setFrameTopLeftPoint:pt];
@aspitz
aspitz / UIImage+Alpha
Created May 20, 2013 20:02
UIImage category that adds a method to create a white image based on the source images alpha channel
@implementation UIImage (Alpha)
- (UIImage *)alphaImage{
CGRect imageRect = CGRectMake(0, 0, self.size.width, self.size.height);
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); // create an RGB Color Space
// create the context to do our drawing in
CGContextRef context = CGBitmapContextCreate(NULL, imageRect.size.width, imageRect.size.height, 8, imageRect.size.width * 4, rgbColorSpace, kCGImageAlphaPremultipliedLast);
// use the images alpha channel as a mask
CGContextClipToMask(context, imageRect, self.CGImage);