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 / trim.m
Created November 4, 2012 20:19
Trimming
@interface NSString (TrimAdditions)
- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set options:(NSStringCompareOptions)options;
@end
@implementation NSString (TrimAdditions)
- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set options:(NSStringCompareOptions)options
{
set = [set invertedSet];
@PsychoH13
PsychoH13 / navbar.m
Created September 5, 2012 13:36
Transparent navigation bar
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1.0, 1.0), NO, 0.0);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[[self navigationController] navigationBar] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[[[self navigationController] navigationBar] setOpaque:NO];
@PsychoH13
PsychoH13 / pragmas.h
Created September 4, 2012 22:49
New Addition to OpenEmu
#define GENERATE_PRAGMA(x) _Pragma(#x)
#define TODO(x) GENERATE_PRAGMA(message("[TODO] " #x))
#define FIXME(x) GENERATE_PRAGMA(message("[FIXME] " #x))
#define NOTE(x) GENERATE_PRAGMA(message("[NOTE] " #x))
@PsychoH13
PsychoH13 / PSYObjCSupport.h
Last active October 8, 2015 01:38
Support for ObjC subscripting and @yES and @no in iOS 4 and 5
/*
PSYObjCSupport.h
Created by Remy "Psy" Demarest on 04/08/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 / tagged-array.m
Created July 24, 2012 02:07
Tagged Array
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
void _objc_insert_tagged_isa(unsigned char slotNumber, Class isa);
@interface _PSYTaggedArray : NSArray
@end
@implementation _PSYTaggedArray
@PsychoH13
PsychoH13 / test.m
Created July 5, 2012 16:28
False-positive static analyzer
struct RandomStruct { NSInteger columnSpan; };
void WeirdStaticAnalyzerDiagnostic(void)
{
struct TestStruct { struct RandomStruct strf; NSUInteger intf; } origin = { { 0 }, 0 };
origin.strf = (struct RandomStruct){ 0 };
struct TestStruct trigger = origin;
NSLog(@"%ld", trigger.intf);
@PsychoH13
PsychoH13 / UIScrollView_PSYAdditions.h
Created July 3, 2012 18:16
UIScrollView cumulative contentInset. Prevent conflicts when multiple classes try to set the contentInset of the same scroll view.
/*
UIScrollView+TSAdditions.h
Created by Remy "Psy" Demarest on 03/07/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 / template_enumerator.mm
Created April 29, 2012 02:32
Template multi enumerator
#import <Foundation/Foundation.h>
#define OBJECT_BUFFER_SIZE 8 /* I don't necessary want to allocate too much memory there... */
typedef struct _PSYMultiEnumState {
__unsafe_unretained id objectsBuf[OBJECT_BUFFER_SIZE];
NSFastEnumerationState state;
unsigned long mutationPtrValue;
NSUInteger count;
NSUInteger position;
@PsychoH13
PsychoH13 / padding.m
Created April 24, 2012 01:22
Padding String
@interface PSYPaddingString : NSString
+ (id)paddingStringWithString:(NSString *)aString length:(NSUInteger)length;
- (id)initWithString:(NSString *)aString length:(NSUInteger)length;
@end
@implementation PSYPaddingString
{
NSString *paddingString;
NSUInteger paddingLength;
NSUInteger stringLength;
@PsychoH13
PsychoH13 / va_arg_invocation.m
Created April 22, 2012 23:45
va_arg invocation !
NSArray *arguments = nil;
char encode[] = "@@:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
encode[[arguments count] + 3] = 0;
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:encode]];
NSInteger idx = 2;
for(__unsafe_unretained id arg in arguments)