Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@christophercotton
christophercotton / OpaqueLayer.h
Created January 5, 2012 04:25
Basic Cocos2d Layer to swallow all the touch events on it
// Feel free to use. MIT License
#import <Foundation/Foundation.h>
#import "cocos2d.h"
// Layer that will just capture any touch events on it
@interface OpaqueLayer : CCLayerColor {
}
@interface UIImage (fixOrientation)
- (UIImage *)fixOrientation;
@end
@AtomicCat
AtomicCat / gist:1407621
Created November 30, 2011 01:57
UIView (NibLoadingExtension)
@implementation UIView (NibLoadingExtension)
+ (id)viewFromNib
{
static NSMutableDictionary *caches = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
caches = [[NSMutableDictionary dictionary] retain];
});
@seanh
seanh / gist:1217489
Created September 14, 2011 19:14
A -boundingBox method for Cocos2D CCNode subclasses that returns the bounding box of all the bounding boxes of a node's descendants.
-(CGRect) fullBoundingBox
{
NSMutableArray *stack = [[NSMutableArray new] autorelease];
for (CCNode *childNode in self.children)
{
[stack addObject:childNode];
}
float leftmost, highest, rightmost, lowest;
while ([stack count] > 0)
{
@pratikshabhisikar
pratikshabhisikar / gist:1173386
Created August 26, 2011 13:22
UIView Flip Animation
[UIView beginAnimations:@"FlipAnimation" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myFirstDrillDownView cache:NO];
[UIView setAnimationBeginsFromCurrentState:YES];
[myFirstDrillDownView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
@ryochin
ryochin / gist:1156124
Created August 19, 2011 05:35
Moonphase for Objective-C
@interface MoonPhase : NSObject {
@private
NSDate *now;
}
- (float) phase;
@end
// ---------------------------------------
@pratikshabhisikar
pratikshabhisikar / gist:1136244
Created August 10, 2011 06:26
Dismissing UIView manually
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[self.view removeFromSuperview];
}
-(void) dismiss {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
@alexbw
alexbw / AutoEncoder.h
Created June 28, 2011 19:58
Autoencoder for Objective-C
//
// AutoEncoder.h
// QuartzTest
//
// Created by Alex Wiltschko on 6/27/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@haikusw
haikusw / gist:1050447
Created June 28, 2011 03:48
Objective C singleton pattern templates discussion
// Accessorizer's default generated singleton code for class Foo
static Foo *sharedInstance = nil;
+ (void) initialize
{
if (sharedInstance == nil)
sharedInstance = [[self alloc] init];
}