Skip to content

Instantly share code, notes, and snippets.

View izackp's full-sized avatar

Isaac Paul izackp

View GitHub Profile
@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 / 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 / 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 / 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 / .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 / 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 / CollisionUpdater.cs
Created July 22, 2015 14:33
Example of moving objects and checking for collisions. However, it can be cleaned up a bit, and it does not do any stepping!! meaning instances jump from point a to point b. So fast objects such a bullets may jump past walls.
public class CollisionUpdater
{
List<IPhysics> components;
public CollisionUpdater ()
{
components = new List<IPhysics> ();
}
public void AddComponent (IPhysics newComp)
{
@izackp
izackp / PBKDF2.cs
Last active September 6, 2016 19:34
PBKDF2 simplified interface in C# - To anyone reading this: just use the BCrypt library its simpler and safer.
using System;
using System.Security.Cryptography;
namespace Security
{
public static class PBKDF2
{
const int cSaltByteLength = 24;
const int cDerivedKeyLength = 24;
const int cIterationCount = 2;
@izackp
izackp / ConfigCamera.cs
Last active April 4, 2017 16:59
Zoom While Maintaining Pixel Perfect Ratio
using UnityEngine;
public class ConfigCamera : MonoBehaviour {
public float Zoom = 1.0f;
float _pixelsPerUnit = 1.0f; //Set this to whatever you set for your texture
public float ScreenWidth; //For Debugging
public float ScreenHeight; //For Debugging
Rect _bounds;
@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 %