Skip to content

Instantly share code, notes, and snippets.

View jrallison's full-sized avatar

John Allison jrallison

View GitHub Profile
id planlimit actual percentage
8 1000 444937 4449370.0
326 50000 6898878 1379775.6
157 1000 104069 1040690.0
716 1000 81610 816100.0
6 5000 366381 732762.0
944 1000 52382 523820.0
190 1000 48945 489450.0
122 1000 38109 381090.0
18 1000 30379 303790.0
@jrallison
jrallison / gist:5815086
Created June 19, 2013 15:11
QUnit loader HTML and CSS
<body>
<div id="results"></div>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="ember-testing-container"><div id="application"></div></div>
<style>
#results {
font-family: Courier New;
font-size: 12px;
@jrallison
jrallison / gist:5779381
Created June 14, 2013 04:05
Ember with fixtures
App = Em.Application.create
LOG_TRANSITIONS: true
rootElement: "#application"
App.Store = DS.Store.extend
revision: 12,
# Specifying the fixture adapter rather than RESTAdapter, etc
adapter: DS.FixtureAdapter.create()
App.Campaign = DS.Model.extend
@jrallison
jrallison / application_controller.rb
Created May 22, 2012 14:58
Force timeout before the unicorn worker gets reaped
class ApplicationController < ActionController::Base
around_filter :force_timeout
protected
def force_timeout(&block)
begin
# Make sure the timeout here is less than
# the timeout configured for unicorn reaping.
# Here we set a timeout of 10 seconds and
@jrallison
jrallison / customerio_client.rb
Created May 1, 2012 19:59
Simple Customer.io API client in Ruby using HTTParty.
# Simple Customer.io API client in Ruby (1.9 syntax) using HTTParty.
# Uses https://github.com/jnunemaker/httparty for all the heavy lifting.
#
# Usage:
#
# client = Customerio.new("YOUR SITE ID", "YOUR API SECRET KEY")
#
# # Identifying a user with user attributes
# user.email = "user@example.com"
# client.identify(user, { first_name: "Bob", plan: "basic" })
@jrallison
jrallison / gist:1483238
Created December 15, 2011 22:31
Admin assistant and Rails 3.0.10 issue.
diff --git a/Gemfile b/Gemfile
index 861f72a..e63813d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,8 @@ gem 'rails', '3.0.10'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
+gem 'mysql'
@jrallison
jrallison / gist:1370496
Created November 16, 2011 16:11
results

EXPLAIN

mysql> explain SELECT * FROM `submissions` WHERE `submissions`.`id` = 5334;
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | submissions | const | PRIMARY       | PRIMARY | 4       | const |    1 |       | 
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+

1 row in set (0.01 sec)

@jrallison
jrallison / gist:1264762
Created October 5, 2011 15:40
Mixpanel server events
# In controllers
mixpanel("event name")
# Anywhere else
Mixpanel.new(:event => "event name", :id => some_user.id, :ip => ???).track!
# ApplicationController
def mixpanel(event, opts = {})
unless current_user.admin? || masquerading?
opts = {:event => event, :id => current_user.id, :ip => request.remote_ip}.merge(opts)
@jrallison
jrallison / gist:977391
Created May 17, 2011 21:02
Everything you need to know about rollout

1) Rollout configuration is in models

/web/models/lib/models/config/rollout.rb

$rollout = Rollout.new(REDIS)

$rollout.define_group(:admin) do |user|
  user.admin?
end
# Model
class Model < ActiveRecord::Base
default_scope where(:hidden => false)
def hide!
update_attributes!(:hidden => true)
end
end