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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>twitter</title> | |
<meta name="generator" content="TextMate http://macromates.com/"> | |
<meta name="author" content="Alex MacCaw"> | |
<!-- Date: 2009-01-10 --> |
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 TwitterBinder < Binder::Collection | |
class << self | |
# What about filters - should they be implemented? | |
# | |
# I also feel this is lacking 'views'. | |
# There should be a view for the index, and the login | |
# There should also be an easy api in ruby/js for switching views | |
def index | |
self.items = twit.timeline(:user) |
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 UsersBinder < Binder::Collection | |
class << self | |
# self.items is a special method | |
# Basically it'll update users on the client side | |
def index | |
self.items = User.all | |
end | |
# def index(offset) | |
# self.items = User.all(:conditions => ['id > ?', offset]) |
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
require 'digest/sha1' | |
require 'net/http' | |
class GravatarFetcher | |
# Gravatar is a bit stupid, in that there's | |
# no way to tell if they're returning the default | |
# avatar - here's a hack to do that. | |
class << self | |
def fetch(email, size=60) | |
email_hash = Digest::MD5.hexdigest(email) | |
http = Net::HTTP.new("www.gravatar.com", 80) |
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
# Simple application config. | |
# Create a file in config/application.yml | |
# with the following: | |
# | |
# :defaults: &defaults | |
# :app_name: MyApp | |
# | |
# :development: | |
# <<: *defaults | |
# |
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
module ValidBrowser | |
# Browser restrictor | |
# | |
# You can choose whether to just display a warning, | |
# or disable access completely. | |
# | |
# You need to include ValidBrowser in application.rb | |
# You also need to install the UserAgent plugin - http://github.com/josh/useragent | |
# | |
# Example 1 - show warning: |
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
module AfterCommit | |
def self.included(base) | |
base.class_eval do | |
[:save, :save!].each do |method| | |
alias_method_chain method, :after_commit | |
end | |
end | |
base.define_callbacks :after_commit, :after_commit_on_create | |
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
require 'fileutils' | |
class Processor | |
LOG_DIR = File.join(Rails.root, 'log') | |
class Daemon | |
PID_DIR = File.join(Rails.root, 'tmp', 'pids') | |
class << self | |
def daemonize!(name) | |
fork do | |
Process.setsid |
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 | |
require File.dirname(__FILE__) + '/../config/environment' | |
def start_processor(queue) | |
puts "Starting #{queue} processor..." | |
klass = queue.to_s.camelize.constantize | |
klass.start!(true) | |
end | |
def stop_processor(queue) |
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
module ActiveRecord | |
class Base | |
private | |
def attributes_protected_by_default | |
default = [ self.class.primary_key, self.class.inheritance_column ] | |
default.concat ['created_at', 'created_on', 'updated_at', 'updated_on'] | |
default << 'id' unless self.class.primary_key.eql? 'id' | |
default | |
end | |
end |