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 / WeakSel.m
Created September 30, 2011 18:22
MAZeroingWeakRef additions
#ifndef __has_feature
#define __has_feature(feature) 0
#endif
#define MAWeakVar(var) __weak_ ## var
#if __has_feature(objc_arc_weak)
#define MAWeakDeclare(var) __weak __typeof__((var)) MAWeakVar(var) = var
#define MAWeakImport(var) __typeof__((MAWeakVar(var))) var = MAWeakVar(var)
@PsychoH13
PsychoH13 / AnotherSyntax.m
Created September 17, 2011 20:31
Weak import propositions
id object = [[NSObject alloc] init];
dispatch_queue_t queue = dispatch_queue_create("whatever", 0);
dispatch_async(queue, ^ void (void) __weak(object) {
if(object != nil)
{
[object doNastyThings];
}
});
@PsychoH13
PsychoH13 / gist:1211619
Created September 12, 2011 15:59
NS_CONSUMES_SELF
#ifndef NS_CONSUMES_SELF
#define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
#endif
@PsychoH13
PsychoH13 / MyClass.h
Created July 5, 2011 18:41
Redefining self inside a block
#import <Foundation/Foundation.h>
@interface MyClass : NSObject
- (id)initWithIvar:(int)value;
- (void)testInnerBlock;
@end
@PsychoH13
PsychoH13 / Evil.m
Created June 14, 2011 17:37
Debauching ObjC's dot-syntax and blocks in ObjC
#import <Foundation/Foundation.h>
@interface NSString (Evil)
@property(assign, setter=initWithString:) NSString *initWithString;
@property(assign, readonly) NSString *test;
@property(assign, readonly) NSArray *(^split)(NSString *);
@end
int main(int argc, char *argv[])
{
@PsychoH13
PsychoH13 / New JSONKit.m
Created May 20, 2011 18:29
Difference of building JSON...
isClass = [object PSYJK_JSONClass];
if(isClass == PSYJKClassUnknown
#import <UIKit/UIKit.h>
@interface UIControl (PSYBlockTargetAddition)
- (id)addTargetForControlEvents:(UIControlEvents)controlEvents usingBlock:(void(^)(id sender, UIEvent *event))block;
- (void)removeTarget:(id)target forControlEvents:(UIControlEvents)controlEvents;
@end
@PsychoH13
PsychoH13 / PSYLayerConstraintLayoutManager.h
Created November 28, 2010 00:25
Layout manager using direct layer references
/*
* PSYLayerConstraintLayoutManager.h
* LayoutManager
*
* Created by Remy Demarest on 27/02/2010.
* Copyright (c) 2010, Remy Demarest
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@PsychoH13
PsychoH13 / NSMutableData+PSYDataWriter.h
Created August 3, 2010 23:00
A class enabling NSData object scanning and a category enabling NSMutableData writing.
/*
NSMutableData+PSYDataWriter.h
Created by Remy "Psy" Demarest on 22/01/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
NSPoint PSYPointInBezierPath(NSPoint *points, NSInteger pointCount, CGFloat t,
NSPoint *getPoints, NSInteger getPointCount)
{
if(getPointCount > 0 && pointCount == getPointCount)
for(int i = 0; i < getPointCount; i++)
getPoints[i] = points[i];
if(pointCount <= 1) return *points;
NSPoint *newPoints = calloc(pointCount - 1, sizeof(NSPoint));