Skip to content

Instantly share code, notes, and snippets.

View nielsbot's full-sized avatar

nielsbot nielsbot

View GitHub Profile
@nielsbot
nielsbot / UIImage+JPEG2000.h
Created February 19, 2012 00:43
Decoding JPEG 2000 files to UIImage
#import <Foundation/Foundation.h>
extern UIImage * UIImageWithJPEG2000Data( NSData * data ) ;
@nielsbot
nielsbot / ShakeAnimation.m
Created February 21, 2012 18:59
Shake animation on UIView
// this code will cause a UIView to shake--good for "login error"
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
anim.values = [ NSArray arrayWithObjects:
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ],
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f) ],
nil ] ;
anim.autoreverses = YES ;
anim.repeatCount = 2.0f ;
anim.duration = 0.07f ;
@nielsbot
nielsbot / profiler.h
Created February 25, 2012 02:30 — forked from PlacePop/profiler.h
Quick and Dirty Profiler for iPhone
//
// 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.
@nielsbot
nielsbot / README
Created February 25, 2012 02:31 — forked from PlacePop/README
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!
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!
@nielsbot
nielsbot / SetViewCenter.m
Created March 15, 2012 00:33
Pixel align your UIViews even when using the center property
@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;
@nielsbot
nielsbot / PropertyContainer.h
Created April 12, 2012 20:32
PropertyContainer
//
// 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
@nielsbot
nielsbot / AppDelegate.h
Created July 18, 2012 22:05
How to overlay a transparent window on the system keyboard
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property ( strong ) IBOutlet UITextField * textField ;
@end
@nielsbot
nielsbot / procinfo.c
Created August 24, 2012 20:05
Get number of threads (running) in all tasks on OS X
#import <libproc.h>
#import <stdlib.h>
#import <stdio.h>
int main( int argc, const char * argv[])
{
pid_t * pids = calloc(0x4000, 1);
int count = proc_listallpids(pids, 0x4000);
printf("count=%u\n", count) ;
@nielsbot
nielsbot / CGPathCreateRoundRect.m
Created August 26, 2012 23:47
Function to create a round rect CGPath
CGPathRef CGPathCreateRoundRect( const CGRect r, const CGFloat cornerRadius )
{
CGMutablePathRef p = CGPathCreateMutable() ;
CGPathMoveToPoint( p, NULL, r.origin.x + cornerRadius, r.origin.y ) ;
CGFloat maxX = CGRectGetMaxX( r ) ;
CGFloat maxY = CGRectGetMaxY( r ) ;
CGPathAddArcToPoint( p, NULL, maxX, r.origin.y, maxX, r.origin.y + cornerRadius, cornerRadius ) ;
@nielsbot
nielsbot / MemoryMappedDataConsumer.h
Last active August 8, 2018 01:13
memory mapped core graphics data consumer for writing PDFs
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@interface MemoryMappedDataConsumer : NSObject
@property ( nonatomic, readonly ) size_t size ;
@property ( nonatomic, readonly ) size_t capacity ;
@property ( nonatomic, readonly ) CGDataConsumerRef CGDataConsumer ;
@property ( nonatomic, readonly, copy ) NSURL * url ;