This file contains hidden or 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
# 2.3 | |
named_scope :last_active_since, lambda { |la| la = 10.minutes.ago if la.nil?; {:conditions => ['last_active_at >= ?', la]}} | |
# 3 scopes | |
named_scope :last_active_since, lambda { |la| la = 10.minutes.ago if la.nil?; where('last_active_at >= ?', la) } | |
# 3 method |
This file contains hidden or 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
Rails Rumble 'Alumni' | |
2007: | |
* http://tastyplanner.com | |
* ??? | |
2008: | |
* http://prioritizd.com |
This file contains hidden or 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
module ActiveRecord | |
module Batches # :nodoc: | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
# When processing large numbers of records, it's often a good idea to do | |
# so in batches to prevent memory ballooning. | |
module ClassMethods | |
# Yields each record that was found by the find +options+. The find is |
This file contains hidden or 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
define_index do | |
indexes :name, :sortable => true | |
indexes entry(:subdomain), :as => :entry_subdomain, :sortable => true | |
indexes entry(:description), :as => :entry_description, :sortable => true | |
indexes entry(:name), :as => :entry_name, :sortable => true | |
indexes entry(:resources_used), :as => :entry_resources, :sortable => true | |
has :state | |
where "state IN ('approved', 'qualified', 'verified')" | |
end |
This file contains hidden or 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 | |
require 'rubygems' | |
require 'fastercsv' | |
require 'json' | |
def jsonify(set) | |
Dir.chdir set | |
images = [] | |
folders = Dir["*/"] | |
folders.each do |folder| |
This file contains hidden or 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
/* GitHub Commits, version 0.0.1 | |
* (c) 2009 Jeff Rafter | |
* | |
* Based on GitHub Badge by Dr Nic Williams (but with the good code removed) | |
* | |
* You need: jquery.js, md5.js | |
* | |
* See http://pajhome.org.uk/crypt/md5 for more info. | |
* | |
*--------------------------------------------------------------------------*/ |
This file contains hidden or 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
# Require RubyGems by default. | |
require 'rubygems' | |
# Require UtilityBelt for lots of functionality | |
# http://utilitybelt.rubyforge.org/ | |
require 'utility_belt' | |
UtilityBelt::Equipper.equip(:defaults) | |
UtilityBelt::Equipper.equip(:with, :string_to_proc, :pipe, :not, | |
:language_greps, :is_an, :clipboard, | |
:interactive_editor) |
This file contains hidden or 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 rating(*args) | |
options = args.extract_options! | |
category = options.delete(:category) | |
as_float = options.delete(:as_float) | |
certified = options.delete(:certified) | |
user_or_ip = options.delete(:user) || options.delete(:ip) | |
if user_or_ip && Rating.instance_methods.include?('user') | |
options[:conditions] = ["user_id = ?", user_or_ip.id] | |
elsif user_or_ip |
This file contains hidden or 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
>> e = Entry.find(:first, :conditions => {:name => 'MyConf'}) | |
=> #<Entry id: 137, name: "MyConf", .... | |
>> e.ratings.average(:value) | |
=> 2.469 | |
>> e.ratings.certified.average(:value) | |
=> 2.6507 | |
>> e.rating(:as_float => true) | |
=> 2.6507 | |
>> e.rating(:certified => true, :as_float => true) | |
=> 2.469 |
This file contains hidden or 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
>> users = User.all | |
<< snip >> | |
>> def trim_percentage(users, cutoff) | |
>> above, below, novote = 0, 0, 0 | |
>> users.each do |user| | |
?> avg = user.ratings.average(:value).to_f | |
>> if avg < 1 | |
>> novote += 1 | |
>> elsif avg < cutoff | |
>> below += 1 |
NewerOlder