Skip to content

Instantly share code, notes, and snippets.

View randydailey's full-sized avatar

Randy Dailey randydailey

View GitHub Profile
@randydailey
randydailey / TransactionalPush.rb
Created November 13, 2014 13:04
Transactional Push Example
# Using Ruby 2.1.2
require 'net/http'
require 'json'
require 'SecureRandom'
#
#
#### Configuration ####
#
#
//
// AppDelegate.m
//
// This skeleton code provides a custom 'tagEvent' wrapper method to be used in leiu of directly calling the Localytics
// tagEvent method. This method will automatically detect when a customer lifetime value increase has occured and will
// toggle a custom dimension after the first CLV increase has occured.
@implementation AppDelegate
//
// GSAppDelegate.m
// ProximiT
//
// Created by Randy Dailey on 5/30/13.
// Copyright (c) 2013 JLRD. All rights reserved.
//
@implementation GSAppDelegate
+ (NSString *)stringForBucketedHours:(int)seconds
{
NSArray *buckets = [NSArray arrayWithObjects:@1,@3, @10, @24, @48, @96, nil];
return [NSString stringWithFormat:@"%@ hours", [GSAnalyticsProvider bucket:(seconds/3600.0f) andStep:buckets]];
}
+ (NSString *)stringForBucketedMeters:(int)meters
{
NSArray *buckets = [NSArray arrayWithObjects:@20, @50, @100, @150, @200, @500, @1000, @5000, nil];
return [NSString stringWithFormat:@"%@ meters", [GSAnalyticsProvider bucket:meters andStep:buckets]];
@randydailey
randydailey / SessionManagement.mm
Last active December 29, 2015 10:39
Managing foreground and background sessions
//
// App Delegate
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[GSAnalyticsProvider startSession:launchOptions];
return YES;
}
// Remove all Localytics code from this method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
// This method changes!
// This method is optional, per our integration guide
- (void)applicationDidBecomeActive:(UIApplication *)application
{
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
// Recieved a notification while the app was already open. May want to record seperately or ignore
}
else
{
// Recieved notification while in background. Tag this as if it came from a cold start
QString LocalyticsSession::formatAttribute(QString name, QString value, bool firstAttribute)
{
QString formattedString;
if (!firstAttribute)
{
formattedString.append(QLatin1Char(','));
}
QString quotedName = QString(QLatin1String("\"%1\"")).arg(escapeString(name));
value = value.isEmpty() ? QString(QLatin1String("null")) : QString(QLatin1String("\"%1\"")).arg(escapeString(value));
formattedString.append(quotedName).append(QLatin1Char(':')).append(value);
private static string EscapeString(string input)
{
StringBuilder escapedStringBuilder = new StringBuilder();
escapedStringBuilder.Append("\"");
foreach (char character in input)
{
switch (character)
{
case '\"':
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>POST Server Demo</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}