Skip to content

Instantly share code, notes, and snippets.

View jtushman's full-sized avatar

Jonathan Tushman jtushman

View GitHub Profile
# In my controller
monitor :only => [:create,:destroy],
:alias => {:create => :voted},
:target => :voteable
# Calls this method in my ActivityLogger module
def monitor(options = {})
if !options.has_key?(:only) && !options.has_key?(:except)
options[:only] = [:show,:create,:update,:destroy]
end
class ActivityMonitor
include Tracking::ActivityMonitor
def initialize
monitor Answer, :only => [:update,:destroy,:create],
:alias => {:create => :answered},
:target => :question
monitor Company
source :gemcutter
gem "rails", "2.3.4"
gem "pg"
# bundler requires these gems in all environments
gem 'will_paginate'
gem 'warden'
gem 'devise', "1.0.8"
gem "panda", "1.0"
gem 'formtastic', '1.1'
def enqueue_for_encoding
notifications = []
notifications << "#{AppConfig.zencoder.callback_url.sub(/:id/,id.to_s)}" unless Rails.env == 'development'
#Make sure that urls match url in the has_attached_file method in video,thumbnail and encodings!
#TODO: Don't make the default security public
response = Zencoder::Job.create({
:input => raw.url,
:output => {:label => "base",
@jtushman
jtushman / Mouse Tracking issue
Created December 7, 2010 17:01
Why is google ads telling me: "Encountered flash error - ad cannot use mouse tracking."
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="336" minHeight="280" width="336" height="280" includeInLayout="true" click="handleClick(event)">
<fx:Script>
<![CDATA[
public function handleClick(mouseEvent:MouseEvent):void {
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");
# Used to replace Abingo:Statistics
#
# Background here: http://en.wikipedia.org/wiki/F-test
# Has access to the following variables when included in an ABingo::Experiment
#
# TODO: Get a real stat guy to confirm my analysis
# Question: Does this work when there are varing observations per level
#
# alternatives (includes conversion_rate and participants)
# best_alternative
@jtushman
jtushman / resque_worker_management.rb
Created July 19, 2011 15:37
tweaking load_env to use 'syck'
def load_env(rubber_only=true)
env = ENV["RUBBER_ENV"] ||= "development"
root = File.expand_path('../..', __FILE__)
rails_env_file = File.join(root, 'config', 'environment.rb')
if ! rubber_only && File.exists?(rails_env_file)
require(rails_env_file)
else
require 'yaml'
YAML::ENGINE.yamler= 'syck'
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
Statsamurai::Application.load_tasks
@jtushman
jtushman / gist:1236519
Created September 23, 2011 01:10
Mongo dressed up as Memcached
# My own little Memcache
class KeyValueStore
include Mongoid::Document
include Mongoid::Timestamps::Created
field :key, type: String
field :value, type: Binary
field :expires, type: Time
DEFAULT_EXPIRY = 1.minute
@jtushman
jtushman / gist:1364960
Created November 14, 2011 19:57
zencoder job
module Zencoder
class Job < Base
def self.create(params={}, options={})
params = apply_api_key(params, options[:format])
HTTP.post("#{options[:base_url] || base_url}/jobs",
encode(params, options[:format]),
options)
end