Skip to content

Instantly share code, notes, and snippets.

View willrust's full-sized avatar

William Rust willrust

  • San Francisco, CA
View GitHub Profile
@willrust
willrust / doorkeeper_applicaition
Created December 15, 2014 03:40
ActiveAdmin Doorkeeper Resource
ActiveAdmin.register Doorkeeper::Application do
permit_params :name, :redirect_uri
# ActiveAdmin will name Rails Engine models with their namespaced names (ex:doorkeeper_application) which
# will fail validation and spit back a form with errors where the fields would otherwise be valid.
# Setting the model resource name back to 'application'.
controller do
resources_configuration[:self][:instance_name] = 'application'
end
@willrust
willrust / shake.swift
Created December 14, 2014 00:54
Shake Animation
func shakeView(view: UIView, completion:((success: Bool) -> Void)?) {
UIView.animateKeyframesWithDuration(0.5,
delay: 0,
options: UIViewKeyframeAnimationOptions.BeginFromCurrentState,
animations: {
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/4, animations: {
view.transform = CGAffineTransformMakeTranslation(-5, 0)
})
UIView.addKeyframeWithRelativeStartTime(1/4, relativeDuration: 1/4, animations: {
view.transform = CGAffineTransformMakeTranslation(5, 0)
@willrust
willrust / Authorized POST
Created December 4, 2014 06:41
Doorkeeper Rails API integration test POST with access token and params using rspec and factory girl.
it "responds with status 201" do
post "#{url}", { user: FactoryGirl.attributes_for(:user) }, { "HTTP_AUTHORIZATION" => "Bearer #{access_token.token}" }
expect(last_response.status).to eq(201)
end
@willrust
willrust / Pizza.playground
Created October 3, 2014 17:32
Pizza Playground
import UIKit
import QuartzCore
let crustWidth:CGFloat = 25.0
let pepDiam:CGFloat = 25.0
let pepCount = 20
let pizza = UIView()
pizza.bounds = CGRect(x: 0, y: 0, width: 300, height: 300)
@willrust
willrust / gist:16614ac542b5d947cdeb
Last active August 29, 2015 14:03
Recording view duration as a property in KISSmetrics Android SDK
//In your Activities: (Replace "someViewDuration" with an appropriate name for each activity)
long appearedAtTime;
@Override
public void onResume() {
super.onResume();
appearedAtTime = System.currentTimeMillis();
}
@willrust
willrust / gist:1a6f819147e9d2a1c470
Last active August 29, 2015 14:03
Recording view duration as a property in KISSmetrics iOS SDK v2
//In your ViewControllers: (Replace "someViewDuration" with an appropriate name for each view)
NSTimeInterval appearedAtTime;
- (void)viewWillAppear:(BOOL)animated {
appearedAtTime = [[NSDate date] timeIntervalSince1970];
}
- (void)viewWillDisappear:(BOOL)animated {
@willrust
willrust / gist:1f59eb7b4d067492226f
Last active August 29, 2015 14:03
KISSmetrics & Tapstream Android integration helper
#import org.json.JSONArray;
#import org.json.JSONException;
#import android.content.SharedPreferences;
SharedPreferences preferences = getApplicationContext().getSharedPreferences("MyKMPrefs", getApplicationContext().MODE_PRIVATE);
if (preferences.getBoolean("TSKMIdentified", false)) {return;}
Tapstream tracker = Tapstream.getInstance();
tracker.getConversionData(new ConversionListener() {
@Override
@willrust
willrust / gist:8410938
Last active January 3, 2016 04:39
KISSmetrics & Tapstream iOS integration helper. Compatible with iOS 5.0+ & KISSmetrics-iOS-SDK v2.0.0+.
//#import <KISSmetricsSDK/KISSmetricsAPI.h>
//#import "TSTapstream.h"
// Aquire km_identity from TapStream's first-run modification feature and apply as KISSmetrics alias.
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"TSKMIdentified"]) {
TSTapstream *tracker = [TSTapstream instance];
[tracker getConversionData:^(NSData *jsonInfo) {
if (jsonInfo != nil) {