Skip to content

Instantly share code, notes, and snippets.

(map
(fn [n] (cond (= (mod n 15) 0) "FizzBuzz"
(= (mod n 3) 0) "Fizz"
(= (mod n 5) 0) "Buzz"
:else n))
(range 1 101))
class WordFilter
def initialize(*ng_words)
@ng_words = ng_words
end
def detect(message)
message =~ /#{@ng_words.join('|')}/
end
def censor(message)
class WordFilter
attr_reader :words
attr_accessor :censor_message
def initialize(*words)
@words = words
@censor_message = "censored"
end
def detect(message)
Session.pre_send_message_timeline_status do |sender, e|
result = e.text.scan( /http:\/\/movapic\.com\/pic\/\w+/)
if result.size > 0
params = result.first.split('/')
e.text = e.text + " http://image.movapic.com/pic/m_#{params.last}.jpeg"
end
end
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :login, :null => false
t.string :name, :null => false
t.string :crypted_password
t.string :salt
t.timestamps
end
end
Rails.configuration.middleware.use RailsWarden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = SessionsController
end
class Warden::SessionSerializer
def serialize(record)
[record.class, record.id]
end
class User < ActiveRecord::Base
has_many :receipts
include Authentication
include Authentication::ByPassword
validates_presence_of :login
validates_length_of :login, :within => 3..40
validates_uniqueness_of :login
class SessionsController < ApplicationController
def new
end
def create
authenticate!
redirect_to dashboard_path
end
def destroy
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :development, :test do
gem 'rspec','>=2.0.0.beta.20'
gem 'rspec-rails','>=2.0.0.beta.20'
gem 'ZenTest'
gem 'autotest'
--format nested
--color
--drb