Skip to content

Instantly share code, notes, and snippets.

View PsychoH13's full-sized avatar

Remy Demarest PsychoH13

  • Grasse, France / San Francisco, California
View GitHub Profile
@PsychoH13
PsychoH13 / PSYEnumerator-Examples.m
Last active October 3, 2015 09:58
PSYMultiEnumerator allows block enumeration over multiple objects at once, all objects must implement NSFastEnumeration protocol
/*
Example.m
Created by Remy "Psy" Demarest on 21/04/2012.
Copyright (c) 2012. Remy "Psy" Demarest
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@PsychoH13
PsychoH13 / New Diagnostic.m
Created March 31, 2012 21:46
New Diagnostic in Clang: -Wimplicit-pointer-condition
@class MyClass;
int main(int argc, char *argv[])
{
void *obj = nil;
if(obj) {}
if((obj)) {}
@PsychoH13
PsychoH13 / selector-bug.m
Created February 9, 2012 19:15
-Wselector bug
#import <Foundation/Foundation.h>
@protocol MyProtocol <NSObject>
@optional
- (void)myMethod;
@end
@interface MyClass : NSObject
@PsychoH13
PsychoH13 / MyClass-oldStyle.m
Created February 8, 2012 01:32
Multipleton pattern
@interface MyClass : NSObject
+ (MyClass *)sharedInstance;
@end
@implementation MyClass
+ (MyClass *)sharedInstance;
{
static MyClass *sharedInstance = nil;
@PsychoH13
PsychoH13 / UIViewController+ViewControllerContainmentRetroCompatibility.m
Created January 17, 2012 17:03
Making UIViewController containment retro-compatible
@implementation UIViewController (ViewControllerContainmentRetroCompatibility)
static void _UIViewController_hack_removeFromParentViewController(UIViewController *self, SEL _cmd);
{
UIViewController *parent = [self parentViewController];
id childControllers = [parent valueForKey:@"_childViewControllers"];
[childControllers removeObject:self];
- (NSArray *)TS_addRotationFrameViews;
{
UIView *baseView = containerView;
CGRect bounds = [baseView bounds];
CGFloat halfWidth = ceilf(CGRectGetWidth(bounds) / 2.0f);
CGFloat halfHeight = ceilf(CGRectGetHeight(bounds) / 2.0f);
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(bounds),
CGRectGetMinY(bounds) - halfHeight,
CGRectGetWidth(bounds),
@PsychoH13
PsychoH13 / compare.m
Created December 6, 2011 15:27
Compare initWithBytesNoCopy: and initWithUTF8String:
#define COUNT 1000000
void incrementString(char *str)
{
while(*str != 0)
{
(*str)++;
if(*str < 0x7F) break;
@PsychoH13
PsychoH13 / MyMultipleton.h
Created October 11, 2011 23:01
Multipleton
@interface MyMultipleton : NSObject
+ (MyMultipleton *)sharedInstance;
@end
@implementation SomeClass
{
int ivar;
}
- (void)method
{
if(booleanValue && obj != nil)
{
do
@PsychoH13
PsychoH13 / gist:1263731
Created October 5, 2011 05:37
BambooTalk syntax
- class Array
{
- (void)enumerateObjectsUsingBlock:((void) enumerateObject:(id)obj atIndex:(UInteger)idx shouldStop:(Boolean out)stop)block
{
- Boolean stop := NO.
for(UInteger i := 0, count := self count ; i < count; i := + 1)
{
block enumerateObject: (self objectAtIndex: i) atIndex: i shouldStop: stop.
if(stop) break.