Skip to content

Instantly share code, notes, and snippets.

@mhomol
mhomol / MovingObstacles2.cs
Created January 4, 2016 21:04
Bag Labs Post - 3D Runner - Moving Obstacles pt. 2
void Update ()
{
if (running == true)
{
updateCubePosition (-4.0f, 0f, -22, "Cube1");
//Keep adding for new cubes, make sure tag name matches, and change the range for the X axis
updateCubePosition (0f, 4.0f, -22, "Cube2");
}
}
@mhomol
mhomol / Start.cs
Created January 4, 2016 21:03
Bag Labs Post - 3D Runner - Start
m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionZ;
@mhomol
mhomol / CollisionHandler.cs
Created January 4, 2016 21:01
Bag Labs Post - 3D Runner - Handling Collisions
void OnCollisionEnter (Collision collision)
{
Rigidbody body = collision.rigidbody;
if (body != null)
{
if (body.tag == "Cube1")
{
MovingObstacles movingObstacles = GameObject.FindObjectOfType(typeof(MovingObstacles)) as MovingObstacles;
movingObstacles.running = false;
@mhomol
mhomol / MovingObstacles.cs
Created January 4, 2016 20:58
Bag Labs Post - 3D Runner - Obstacles
public float speed = 0.1f;
public bool running = true;
private void updateCubePosition(float min, float max, float startZ, string id)
{
GameObject cube1 = GameObject.FindGameObjectWithTag (id);
Vector3 currentPosition = cube1.transform.position;
//Reset the cube's position once it has passed the player
@mhomol
mhomol / CloudKitManager.swift
Created September 17, 2015 13:30
Bag Labs Post - CloudKit and Swift - Code
import CloudKit
class CloudKitManager : NSObject
{
var container : CKContainer?
let privateDB : CKDatabase?
override init() {
container = CKContainer.defaultContainer()
privateDB = container!.privateCloudDatabase
@mhomol
mhomol / Load.swift
Created September 17, 2015 13:21
Bag Labs Post - Keychain and Swift -
func load(service: NSString, userName:String) -> NSString?
{
//Create the query keychain
var keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, userName, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecReturnDataValue, kSecMatchLimitValue])
var dataTypeRef :Unmanaged<AnyObject>?
// Search for the keychain items
let status: OSStatus = SecItemCopyMatching(keychainQuery, &dataTypeRef)
let opaque = dataTypeRef?.toOpaque()
var contentsOfKeychain: NSString?
@mhomol
mhomol / saveLogin.swift
Created September 17, 2015 13:20
Bag Labs Post - Keychain and Swift - SaveLogin
//Don't forget to add the Security.framework to your project.
import Security
private let kSecClassValue = NSString(format: kSecClass)
private let kSecAttrAccountValue = NSString(format: kSecAttrAccount)
private let kSecValueDataValue = NSString(format: kSecValueData)
private let kSecClassGenericPasswordValue = NSString(format: kSecClassGenericPassword)
private let kSecAttrServiceValue = NSString(format: kSecAttrService)
private let kSecMatchLimitValue = NSString(format: kSecMatchLimit)
private let kSecReturnDataValue = NSString(format: kSecReturnData)
private let kSecMatchLimitOneValue = NSString(format: kSecMatchLimitOne)
@mhomol
mhomol / Receipt_Validation_pt3.swift
Created September 17, 2015 13:14
Bag Labs Post - In-App Purchase Validation - Receipt Validation Part 3
func getProductIdFromReceipt(data:NSData) -> String?
{
var p = UnsafePointer<UInt8>(data.bytes)
var dataLength = data.length
var type:Int32 = 0
var tag:Int32 = 0
var length = 0
var end = p + dataLength
ASN1_get_object(&p, &length, &type, &tag, end - p)
@mhomol
mhomol / Receipt_Validation_pt2.swift
Created September 17, 2015 13:13
Bag Labs Post - In-App Purchase Validation - Receipt Validation Part 2
let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).memory.contents)
var ptr = UnsafePointer<UInt8>(octets.memory.data)
let end = ptr.advancedBy(Int(octets.memory.length))
var type: Int32 = 0
var xclass: Int32 = 0
var length = 0
ASN1_get_object(&ptr, &length, &type, &xclass, end - ptr)
if (type != V_ASN1_SET) {
@mhomol
mhomol / Receipt_Validation_pt1.swift
Last active September 17, 2015 13:13
Bag Labs Post - In-App Purchase Validation - Local Validation Part 1
//Load in the receipt
var receipt: NSData = NSData(contentsOfURL:receiptUrl!, options: nil, error: nil)!
var receiptBio = BIO_new(BIO_s_mem())
BIO_write(receiptBio, receipt.bytes, Int32(receipt.length))
var receiptPKCS7 = d2i_PKCS7_bio(receiptBio, nil)
//Read in Apple's Root CA
var appleRoot = NSBundle.mainBundle().URLForResource("AppleIncRootCertificate", withExtension: "cer")
var caData = NSData(contentsOfURL: appleRoot!)
var caBIO = BIO_new(BIO_s_mem())