Skip to content

Instantly share code, notes, and snippets.

View McZonk's full-sized avatar

Max McZonk

  • Germany
View GitHub Profile
@McZonk
McZonk / UIImageView+UIPImageFrame.m
Created October 8, 2013 09:59
Category to calculate the image frame in UIImageView
#import "UIImageView+UIPImageFrame.h"
@implementation UIImageView (UIPImageFrame)
- (CGRect)imageFrame
{
UIViewContentMode contentMode = self.contentMode;
UIImage *image = self.image;
if(image == nil)
@McZonk
McZonk / CheckClearColor.m
Last active January 1, 2016 15:09
Fixing TRAUMA OpenGL ES debugger warnings
if(flashIntensity > 0.0f)
{
glClearColor(flashIntensity, flashIntensity, flashIntensity, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
else
{
glClear(GL_COLOR_BUFFER_BIT);
}
// vertex shader
attribute vec4 a_position;
attribute vec2 a_tex_coord;
varying mediump vec2 v_tex_coord;
void main() {
v_tex_coord = a_tex_coord;
gl_Position = a_position;
}
// fragment shader
// vertex shader
attribute vec4 a_color;
attribute vec4 a_position;
attribute vec2 a_tex_coord;
varying highp vec2 v_tex_coord;
varying lowp vec4 v_color_mix;
void main() {
v_color_mix = a_color;
v_tex_coord = a_tex_coord;
gl_Position = a_position;
// vertex shader
uniform float u_selected;
attribute vec4 a_position;
attribute vec4 a_color;
varying lowp vec4 v_color;
void main() {
if (u_selected > 0.0) {
v_color = vec4(0.5, 1.0, 1.0, 1.0);
} else {
v_color = a_color;
// vertex shader
attribute vec4 a_color;
attribute vec4 a_position;
attribute vec2 a_tex_coord;
varying mediump vec2 v_tex_coord;
varying lowp vec4 v_color_mix;
void main() {
v_color_mix = a_color;
v_tex_coord = a_tex_coord;
gl_Position = a_position;
@McZonk
McZonk / GKLeaderboardIdentifier.m
Created February 12, 2014 21:41
Fix the missing declaration of the GKLeaderboard identifier on OS X 10.9.
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
@interface GKLeaderboard (IdentifierSupport)
@property (copy, readonly) NSString *identifier;
@end
+ (NSCharacterSet *)ignoredCharactersBeforeSmartInserts
{
static NSCharacterSet *characterSet;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
/*
Character set taken from AppKit's __getPreSmartSet
*/
NSMutableCharacterSet *mutableSet = [NSMutableCharacterSet characterSetWithCharactersInString:@"([\\\"'#$/-`{<"];
#import <Foundation/Foundation.h>
@protocol SomeProtocol <NSObject>
- (void)someMethod;
@end
@protocol MyProtocol <SomeProtocol>
- (void)myMethod;
@McZonk
McZonk / main.c
Created September 21, 2014 21:07
#ifdef __OBJC__
// clang -framework Foundation -o ObjC -ObjC main.c
#import <Foundation/Foundation.h>
int main(int argc, const char **argv)
{
NSString *string = [[NSString alloc] initWithUTF8String:"Objective-C"];