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 / 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 / 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 / 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 / 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 / login_test.rb
Created September 29, 2011 16:18
Sample Watir Unit Test
require 'rubygems'
require 'test/unit'
require 'watir-webdriver'
class LoginTest < Test::Unit::TestCase
def setup
@browser = Watir::Browser.new :ff
end
@rossta
rossta / gist:1052211
Created June 28, 2011 21:10 — forked from noahd1/gist:1051970
Moneyball Rules

Changelog

v. 3.0.0

  • created, ignoring all previous incarnations of the rules, from draft of an email

v 3.0.1

  • Clarifications
@rossta
rossta / unmasking_benchmark.rb
Created June 2, 2011 10:56 — forked from mloughran/unmasking_benchmark.rb
Making WebSocket unmasking fast in ruby
module EventMachine
module WebSocket
class MaskedString < String
def read_mask
raise "Too short" if bytesize < 4 # TODO - change
@masking_key = String.new(self[0..3])
end
@rossta
rossta / _autoescaped_partial.html.erb
Created February 25, 2011 23:42
Enable automatic html-escaping locally rather than by default.
<% autoescape do %>
<div>
<%= content_helper_gets_escaped %>
</div>
<% end %>
@rossta
rossta / em_server.rb
Created December 27, 2010 04:32
running the eventmachine in my game server
class Server
def start
EM.run {
EM.start_server @host, @port, Client::Socket, :app => self do |players|
@players << player
player.send_data("READY\r\n")
end
@rossta
rossta / em_run.rb
Created December 26, 2010 18:40
Starting and stopping the event loop
EM.run {
# our fantastic eventmachine code
}