This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def what_is_gist | |
"A bad ass version-able pastebin" | |
This is sorta cool I guess? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pseudoforked from mojombo: http://rubyisawesome.com/2007/10/13/lazy-mixin | |
# Before you ask--yes, this has a very specific use case and is not | |
# generally applicable to the problem of fine-grained lazy evaluation. | |
# But it does *exactly* what I need it to do. =) | |
# Allows attributes to be declared as lazy, meaning that they won't be | |
# computed until they are asked for. Just mix this module in: | |
# | |
# class Foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wise's mod, from: http://blogwi.se/post/47083009/slightly-pimped-activerecord-create-or-update | |
# original from Rails Spikes: http://railspikes.com/2008/2/1/loading-seed-data | |
def self.create_or_update(options = {}) | |
id = options.delete(:id) | |
conditions = options.delete(:conditions) | |
record = id ? find_by_id(id) : find(:first, :conditions => conditions) || new | |
options.each_pair { |key, value| record[key] = value } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************** | |
BEGIN TOOL TIP CSS | |
**************************/ | |
a.tip {position: relative;} | |
a span.tip-content, | |
a span.tip-bottom { | |
position: absolute; | |
width: 273px; | |
padding: 20px 50px 5px 20px; | |
bottom: 48px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# never render the full layout if it's an XmlHttpRequest | |
class ApplicationController < ActionController::Base | |
def render(*args) | |
args.first[:layout] = false if request.xhr? and args.first[:layout].nil? | |
super | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## from railscasts: http://railscasts.com/episodes/124-subdomains | |
# models/invitation.rb | |
belongs_to :sender, :class_name => 'User' | |
has_one :recipient, :class_name => 'User' | |
validates_presence_of :recipient_email | |
validate :recipient_is_not_registered | |
validate :sender_has_invitations, :if => :sender | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete_dups_for(model, collect_by) | |
keep_array = Hash.new { |h,k| h[k] = [] } | |
delete_array = [] | |
model_name = model.name | |
all_objects = model.all.reverse #so we add newest first, sort of | |
pbar = ProgressBar.new(model_name.pluralize, all_objects.count) | |
all_objects.each do |obj| | |
if detect_dup((keep_array[obj.send(collect_by)]), obj).nil? | |
keep_array[obj.send(collect_by)] << obj | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sync_changesets | |
return unless ENABLE_SUBVERSION | |
begin | |
latest_changeset = changesets.find(:first, :select => 'revision', :order => 'revised_at DESC') | |
start = latest_changeset ? latest_changeset.revision.to_i + 1: 1 | |
stop = latest_revision | |
return if start > stop | |
Changeset.transaction do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# put in /etc/munin/plugins and restart munin-node | |
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin | |
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats | |
def output_config | |
puts <<-END | |
graph_category App | |
graph_title passenger status | |
graph_vlabel count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# put in /etc/munin/plugins and restart munin-node | |
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin | |
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats | |
def output_config | |
puts <<-END | |
graph_category App | |
graph_title Passenger memory stats | |
graph_vlabel count |
OlderNewer