Skip to content

Instantly share code, notes, and snippets.

View r3econ's full-sized avatar

r3econ r3econ

View GitHub Profile
@r3econ
r3econ / NSObject+Extensions.h
Last active August 29, 2015 13:56
NSObject Extensions.
#import <Foundation/Foundation.h>
@interface NSObject (Extensions)
- (void)performBlock:(void (^)(void))block
afterDelay:(NSTimeInterval)delay;
@end
@r3econ
r3econ / Distance between two CGPoints.
Created February 20, 2014 22:11
Distance between two CGPoints.
CGFloat DistanceBetweenTwoPoints(CGPoint pointA, CGPoint pointB)
{
CGFloat dx = pointB.x - pointA.x;
CGFloat dy = pointB.y - pointA.y;
return sqrt(dx*dx + dy*dy);
};
@r3econ
r3econ / UIColor+Extensions.h
Last active August 29, 2015 13:56
UIColor Extensions.
@interface UIColor (Extensions)
/**
Returns a UIColor for a color given in a hexadecimal string format.
Such as #00FF00.
*/
+ (UIColor *)colorWithHexString:(NSString *)hexString;
@r3econ
r3econ / gist:9132993
Created February 21, 2014 11:48
Blocks

Block Declaration Syntax

  • return_type be the type of object/primitive/etc. you'd like to return (commonly void)
  • blockName be the variable name of the block you're creating
  • var_type be the type object/primitive/etc. you'd like to pass as an argument (leave blank for no parameters)
  • varName be the variable name of the given parameter And remember that you can create as many parameters as you'd like.

Blocks as Variables

Possibly the most common for of declaration.

@r3econ
r3econ / NSString+RAFExtensions.h
Last active August 29, 2015 13:56
NSString Extensions.
#import <Foundation/Foundation.h>
@interface NSString (RAFExtensions)
/**
Returns random alphanumeric string with a given length.
*/
+ (NSString *)randomStringWithLength:(NSUInteger)length;
/**
@r3econ
r3econ / gist:9137844
Last active August 29, 2015 13:56
Degrees to radians conversion.
CGFloat DegreesToRadians(CGFloat degrees)
{
return degrees * M_PI / 180;
};
CGFloat RadiansToDegrees(CGFloat radians)
{
return radians * 180 / M_PI;
};
@r3econ
r3econ / gist:9345283
Last active August 29, 2015 13:56
Perform a block in a background thread, and call a completion block on the main thread when its done.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
// Background thread stuff.
dispatch_async(dispatch_get_main_queue(), ^
{
// Main thread stuff.
});
});
@r3econ
r3econ / UIFont+FamilyNames.h
Last active August 29, 2015 13:57
UIFont category for logging all available fonts in iOS project.
@interface UIFont (FamilyNames)
+ (void)logFontNames;
@end
@r3econ
r3econ / DragBehavior.cs
Created March 22, 2014 19:17
Unity 3D Click & Drag Behavior.
using UnityEngine;
using System.Collections;
public class DragBehavior : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown ()
{
@r3econ
r3econ / UIButton+VerticalLayout.h
Last active May 14, 2020 01:30
UIButton category for centering title label and image vertically. The text label is placed below the image.
@interface UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding;
- (void)centerVertically;
@end