Skip to content

Instantly share code, notes, and snippets.

View zaneclaes's full-sized avatar

Zane Claes zaneclaes

View GitHub Profile
//
// SNFirebase.m
// SharedNotes
//
// Created by Zane Claes on 4/12/14.
// Copyright (c) 2014 inZania LLC. All rights reserved.
//
#import "SNFirebase.h"
//
// SNFirebase.m
// SharedNotes
//
// Created by Zane Claes on 4/12/14.
// Copyright (c) 2014 inZania LLC. All rights reserved.
//
#import "SNFirebase.h"
@zaneclaes
zaneclaes / SNFirebase.h
Created May 4, 2014 15:37
This Firebase helper class uses transient Firebase objects, so that each object is never used for more than a single transaction. It also prevents Firebase crashes by creating mutable deep copies. The observe method also does sanity checking.
//
// SNFirebase.h
// SharedNotes
//
// Created by Zane Claes on 4/12/14.
// Copyright (c) 2014 inZania LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Firebase/Firebase.h>
__weak typeof (self) wself = self;
[self runRequest:request handler:^(NSError *err) {
__strong typeof (wself) sself = wself;
__weak typeof(sself) wself2 = sself;
[sself runSecondRequest:data handler:^(NSError *err) {
__strong typeof (wself2) sself2 = wself2;
[sself2 doStuff];
}];
}];
//
// Detect's the user's mobile client
// If it is a matched client, creates a referral item in parse and returns a redirect URL for the AppStore
//
function createReferral($params = array()) {
require_once '../cms/Mobile_Detect.php';
$detect = new Mobile_Detect;
$ios_url = 'https://itunes.apple.com/us/app/aftermath-pvp-guilds-strategy/id702615597?ls=1&mt=8';
$clients = array('iPhone'=>$ios_url,
//
// Detect's the user's mobile client
// If it is a matched client, creates a referral item in parse and returns a redirect URL for the AppStore
//
function createReferral($params = array()) {
require_once '../cms/Mobile_Detect.php';
$detect = new Mobile_Detect;
$ios_url = 'https://itunes.apple.com/us/app/aftermath-pvp-guilds-strategy/id702615597?ls=1&mt=8';
$clients = array('iPhone'=>$ios_url,
//
// Detect's the user's mobile client
// If it is a matched client, creates a referral item in parse and returns a redirect URL for the AppStore
//
function createReferral($params = array()) {
require_once '../cms/Mobile_Detect.php';
$detect = new Mobile_Detect;
$ios_url = 'https://itunes.apple.com/us/app/aftermath-pvp-guilds-strategy/id702615597?ls=1&mt=8';
$clients = array('iPhone'=>$ios_url,
static NSString * const kKeyHasAttributedReferral = @"hasAttributedReferral";
- (void)attributeReferral {
if([[NSUserDefaults standardUserDefaults] boolForKey:kKeyHasAttributedReferral]) {
return;
}
// Attribute referrals
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"device"] = [[UIDevice currentDevice].model componentsSeparatedByString:@" "].firstObject;
if(!isset($_POST['device']) || !isset($_POST['os_version'])) {
die('missing params');
}
$params = $_POST;
$params['ip'] = $_SERVER['REMOTE_ADDR'];
// Now we'd query the database for a Referral object match on device, os_version, and ip
// We could also restrict our query to recently created Referral objects and/or objects
// which have not been "Claimed."
<?php
if(!isset($_POST['device']) || !isset($_POST['os_version'])) {
die('missing params');
}
$params = $_POST;
$params['ip'] = sha1($_SERVER['REMOTE_ADDR']);
// Now we'd query the database for a Referral object match on device, os_version, and ip
// We could also restrict our query to recently created Referral objects and/or objects