Skip to content

Instantly share code, notes, and snippets.

View izackp's full-sized avatar

Isaac Paul izackp

View GitHub Profile
@izackp
izackp / Dictionary.cs
Created February 14, 2015 17:06
Serializer for a key as string only dictionary with Full Serializer library (used with unity). This works around the ugly produced dictionaries with key and value properties in the json. It also makes it easier for hand made json.
using FullSerializer;
using System.Collections.Generic;
[fsObject(Converter = typeof(DictionaryConverter))]
public class Dictionary<TValue> : Dictionary<string, TValue> {
}
@izackp
izackp / .gitignore
Last active August 29, 2015 14:10
Meh Git Ignore
# Source: https://gist.github.com/izackp/967c059abe102745f61d
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
@izackp
izackp / Sweep2dCol.c
Created October 28, 2014 14:57
Sweeping 2D Collision Detection Example
float x = 5.0f;
float y = 5.0f;
float destX = 25.0f;
float destY = 30.0f;
float diffX = abs(destX - x);
float diffY = abs(destY - y);
float scale = 0.0f;
@izackp
izackp / downSample.sh
Created October 6, 2014 20:33
down samples images from @2x to @1x
dir=$(pwd)
find "$dir" -name "*@2x.png" | while read image; do
outfile=$(dirname "$image")/$(basename "$image" @2x.png).png
if [ "$image" -nt "$outfile" ]; then
basename "$outfile"
width=$(sips -g "pixelWidth" "$image" | awk 'FNR>1 {print $2}')
height=$(sips -g "pixelHeight" "$image" | awk 'FNR>1 {print $2}')
@izackp
izackp / Hypothenuse_Calculations.cpp
Last active April 5, 2017 15:08
Hypothenuse Calculations
h = sqrt(a² + b²);
//All these assume 0 ≤ a ≤ b.
h = ((sqrt(2) - 1) * a) + b; //Max Error: 8.24% over true value, b must the be larger number
h = 0.414213562 * a + b; //Same as above. Either works compiler will optimize.
h = 4142 * a / 10000 + b; //Same as above. We just only use ints
h = (a >> 1) + b; //Max Error: a/2 //Simplified version of above to be faster and less accurate
h = b + 0.337 * a // max error ≈ 5.5 %
@izackp
izackp / dispatchPause.m
Created August 12, 2014 19:41
Have a dispatch queue listen for the pause button in xcode
//Brandon Levasseur
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGSTOP, 0, queue);
if (source) {
dispatch_source_set_event_handler(source, ^{
NSLog(@"Hi, I am: %@", weakSelf);
});
dispatch_resume(source);
@izackp
izackp / NSString+Formatting.h
Last active August 29, 2015 14:05
A more accurate check for retina in iOS. (Assumes all future devices are retina)
@interface NSString (Formatting)
- (NSString*)stringWithOnlyLetters;
- (NSString*)stringWithOnlyNumbers;
@end
@izackp
izackp / .gitignore
Created May 22, 2014 17:20
IOS .gitignore file
# Xcode
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
@izackp
izackp / Widget.h
Last active August 29, 2015 14:01
Widget class which allows you to inherit from widget and create a xib file with the same name as the class. Once this is done you can reuse the xib anywhere by setting a view's subclass.
#import <UIKit/UIKit.h>
@interface Widget : UIView
@property (strong, nonatomic, readonly) IBOutlet UIView* view;
@end
source ~/.bash_profile
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi