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
| class ApiKey < ActiveRecord::Base | |
| belongs_to :user | |
| around_create :generate_api_key | |
| def generate_api_key | |
| self.api_key = "" | |
| chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.," |
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
| class UndefinedMethodOddity | |
| def foo | |
| bar 1 | |
| bar 2 | |
| end | |
| def bar(arg) | |
| end | |
| 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
| def self.active | |
| s = arel_table | |
| where( | |
| s[:begins_at].lteq(Time.now.utc).or(s[:begins_at].eq(nil)).and( | |
| s[:ends_at].gt(Time.now.utc).or(s[:ends_at]).eq(nil)) | |
| ) | |
| 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
| scope :voted_since, lambda{|since| | |
| joins(:votes) | |
| .where("`votes`.created_at >= ? AND `votes`.project_id = `users`.project_id", since.to_s(:db)) | |
| .group("`votes`.user_id") | |
| .order("COUNT(`votes`.user_id) DESC") | |
| } |
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 last_activity_description(date, user_id) | |
| user_activity = UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat | |
| e, user_id], :order => 'updated_at DESC') | |
| user_activity.activity.description | |
| end | |
| # better | |
| def last_activity(date, user_id) | |
| UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat | |
| e, user_id], :order => 'updated_at DESC').activity |
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 last_activity(date, user_id) | |
| active_id = UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat | |
| e, user_id], :order => 'updated_at DESC').activity_id | |
| 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
| digraph G { | |
| size = "5,5"; node[fontsize=16]; | |
| struct3 [shape=record,label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"]; | |
| // incoming | |
| client -> server; | |
| server -> client; | |
| } |
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
| class Photo | |
| def photo_filename= filename | |
| if (self.photo = File.read(filename) rescue nil) | |
| save! | |
| end | |
| end | |
| end | |
| # ... |