Skip to content

Instantly share code, notes, and snippets.

View rossta's full-sized avatar
💭
Being curious

Ross Kaffenberger rossta

💭
Being curious
View GitHub Profile
@rossta
rossta / admin.rb
Created September 30, 2011 22:53
Pattern for extending ActiveRecord models
# app/models/user_extensions/admin.rb
module UserExtensions
module Admin
extend ActiveSupport::Concern
ADMIN = 'admin'
module ClassMethods
@rossta
rossta / rossta.zsh-theme
Created October 4, 2011 13:52
rossta zsh theme
# CANDY Extension
PROMPT_PREFIX="%{$fg[blue]%}[%{$reset_color%}"
PROMPT_SUFFIX="$fg[blue]%}]%{$reset_color%}"
HOST_PROMPT="%{$fg_bold[green]%}%n@%m"
DATE_PROMPT="$PROMPT_PREFIX%{$fg[red]%}%D{%I:%M:%S}$PROMPT_SUFFIX"
PWD_PROMPT="$PROMPT_PREFIX%{$fg[white]%}%~$PROMPT_SUFFIX"
LEADER_PROMPT="%{$fg_bold[blue]%}\$%{$reset_color%}"
# Get the current ruby version in use with RVM:
@rossta
rossta / custom_gem.rb
Created October 13, 2011 11:42
Custom gem method for local using gems locally (courtesy of ruby-amqp)
# Use local clones if possible.
# If you want to use your local copy, just symlink it to vendor.
def custom_gem(name, options = Hash.new)
local_path = File.expand_path("../vendor/#{name}", __FILE__)
if File.exist?(local_path)
gem name, options.merge(:path => local_path).delete_if { |key, _| [:git, :branch].include?(key) }
else
gem name, options
end
end
@rossta
rossta / background_callbacks.rb
Created October 17, 2011 12:27
Enable :background => true option for active record callbacks + "send_later"
ActiveRecord::Base.class_eval do
public :callback
def self.define_background_callback(callback_name)
class_eval <<-RUBY
define_callbacks :background_#{callback_name} # define_callbacks :background_after_create
#
#{callback_name} do |object| # after_create do |object|
object.queue_background_callbacks(:#{callback_name}) # object.queue_background_callbacks(:after_create)
end # end
@rossta
rossta / devise_monkey_patch.rb
Created October 19, 2011 04:02
Devise patch for test env to cut out expensive password calculations
# Don't need passwords in test DB to be secure, but we would like 'em to be
# fast -- and the stretches mechanism is intended to make passwords
# computationally expensive.
module Devise
module Models
module DatabaseAuthenticatable
protected
def password_digest(password)
password
@rossta
rossta / caching_config.rb
Last active September 28, 2015 23:08
Set controller caching in RSpec around block
RSpec.configure do |config|
config.around(:each, :caching) do |example|
caching = ActionController::Base.perform_caching
ActionController::Base.perform_caching = example.metadata[:caching]
example.run
Rails.cache.clear
ActionController::Base.perform_caching = caching
end
end
@rossta
rossta / ordered_by_counter.rb
Created October 17, 2012 10:27
OrderedByCounter article
module MyModule
extend ActiveSupport::Concern
# removed code that modified User when
# including this module in Article
end
module OrderedByCounter
extend ActiveSupport::Concern
@rossta
rossta / index.html
Last active December 10, 2015 10:58
Click to add balls
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
@rossta
rossta / index.html
Created January 1, 2013 18:24
Balls with wall collision; Click to add balls
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
@rossta
rossta / ruby_trello_demo.rb
Created January 8, 2013 03:37
Ruby-trello and Threads: Making requests on behalf of multiple clients is not currently thread-safe, as demonstrated in the gist below (with placeholders for sensitive data).
include Trello
include Trello::Authorization
Trello::Authorization.const_set :AuthPolicy, OAuthPolicy
OAuthPolicy.consumer_credential = OAuthCredential.new('user_key', 'user_secret')
threads = []
tokens = %w[ not_rosstas_token rosstas_token ]
tokens.each_with_index do |token, i|