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
class Topic < ActiveRecord::Base | |
before_create :set_start_trending | |
before_save :check_content | |
before_save :set_hot_topic, :if => Proc.new { |topic| topic.mentions >= HOT_TOPIC_MENTIONS } | |
scope :trending_top, lambda { |num| where("started_trending > ?", 1.day.ago).order('mentions desc').limit(num) } | |
HOT_TOPIC_MENTIONS = 1000 |
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
class ContentModerator | |
def self.is_suitable?(content) | |
# checks against a web service | |
# or local dictionary | |
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
class TweetsController < ApplicationController | |
def index | |
# @tweets = Tweet.all | |
# Tweet Load (0.4ms) SELECT `tweets`.* FROM `tweets` ORDER BY created_at desc | |
# User Load (0.4ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1 | |
# User Load (0.4ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 2) LIMIT 1 | |
# User Load (0.3ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1 |
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
# in the user form partial | |
<h3>Preferences</h3> | |
<% User::PREFERENCES.each do |preference| %> | |
<div class="field"> | |
<%= check_box_tag "user[preferences[#{preference.to_s}]]", "1", @user.preferences ? @user.preferences[preference] : false %> | |
<%= label_tag :attribute, preference.to_s.titleize %> | |
</div> | |
<% 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
class User < ActiveRecord::Base | |
has_many :tweets | |
has_one :account_setting, :dependent => :destroy | |
accepts_nested_attributes_for :account_setting | |
validates_presence_of :first_name, :last_name, :email | |
validates_uniqueness_of :email | |
validates_presence_of :age | |
validates_exclusion_of :age, :in => 0..18, :message => 'underage' |
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
desc 'Long running task involving all tweets' | |
task :long_running_task => :environment do | |
ActiveRecord::Base.logger = Logger.new STDOUT | |
# defaults to 1000 | |
Tweet.find_each() do |tweet| | |
p "long running task for #{tweet}" | |
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
class TopicsController < ApplicationController | |
def index | |
@topics = Topic.select([:id, :name]).order('mentions desc') | |
#@topics = Topic.order('mentions desc') | |
end | |
def show | |
@topic = Topic.find(params[:id]) | |
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
<% @tweets.each do |tweet| %> | |
<tr> | |
<td><%= tweet.status %></td> | |
<!--<td><%#= tweet.user.display_name %></td>--> | |
<td> | |
<em> | |
<%#= (tweet.user.account_setting && tweet.user.account_setting.location_on_tweets?) ? 'available' : 'unavailable'%> | |
<%= tweet.has_location_data? ? 'available' : 'unavailable' %> | |
</em> | |
</td> |
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
before = Time.now.to_i | |
sleep 5 | |
now = Time.now.to_i | |
p "#{now - before} seconds have passed" |
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
function Machine(){ | |
this.totalAmount = 0; | |
this.items = {'twix': 0, 'coke': 0, 'tostitos': 0}; | |
this.insertMoney = function(amount){ | |
this.totalAmount += amount; | |
} | |
this.total = function(){ |