Skip to content

Instantly share code, notes, and snippets.

require 'hoptoad_notifier/capistrano'
task :production do
set :rails_env, "production"
end
task :staging do
set :rails_env, "staging"
end
class Comment
include MongoMapper::Document
key :poll_id, Integer, :required => true, :index => true
key :name, String, :required => true
key :email, String, :required => true
key :body, String, :required => true
timestamps!
def poll
@r38y
r38y / user.rb
Created February 16, 2010 21:43
# two-step processing of avatars.
class User < ActiveRecord::Base
has_attached_file :avatar,
:default_url => "/images/:attachment/:style-missing.gif",
:styles => { :medium => "200x200#",
:thumb => "55x55#" },
:storage => 's3',
:s3_credentials => File.join(RAILS_ROOT, 'config', 'app_config.yml'),
:bucket => APP_CONFIG[:bucket],
:path => APP_CONFIG[:path],
class TwitterSettingsController < ApplicationController
ssl_required :edit, :enable, :oauthorized
before_filter :require_user
def edit
end
def enable
@request_token = oauth_consumer.get_request_token(:oauth_callback => oauthorized_twitter_url)
session[:oauth_token] = @request_token.token
class LabeledFormBuilder < ActionView::Helpers::FormBuilder
%w[text_field password_field select file_field text_area].each do |method_name|
define_method(method_name) do |field_name, *args|
content = ''
error = object.errors.on(field_name)
row_classes = 'form-row'
row_classes += ' error' unless error.blank?
label_classes = 'form-label'
label_classes += ' align' if %w|file_field select|.include?(method_name)
content += @template.content_tag(:div, :class => row_classes) do
@r38y
r38y / gist:366080
Created April 14, 2010 17:23
MongoDB init.d script for Ubuntu 8.04 LTS
# since there is no deb package for Ubuntu 8.04 LTS, this is what I had to do
# download latest stable version of mongodb and move to /usr/local/mongodb
# add "export PATH=$PATH:/usr/local/mongodb/bin" to /etc/profile
# make directories for the data /db/mongodb/master and /db/mongodb/slave
# chown those directories to the user you want
# move this script to /etc/init.d/mongodb
# chmod +x /etc/init.d/mongodb
# update-rc.d mongodb defaults
RETVAL=0
<h2>Who We Are</h2>
<p>Hi! I am <a href="/r38y">Randy</a> and this is <a href="/tikaro">John</a>. We are the creators of Lose It or Lose It! We're overweight and don't want to be anymore!</p>
<h2>Why We Created Lose It or Lose It</h2>
<p>Let me (Randy) start with a little bit of my history. I think many of you will find it a familiar story.</p>
<p>In 1999 - 2000, I was a senior in high school and I weighed 245 lb. I have been overweight for as long as I can remember, but this is the first weight I can actually remember. I wanted to fix it, but I don't remember really trying that hard.</p>
@r38y
r38y / rewrite_macro.rb
Created May 8, 2010 18:40
How I test refraction in rspec
# Macros I use for testing refraction redirections. It can be used thusly:
# it_should_permanently_redirect('http://loseitorloseit.test/stats', 'http://loseitorloseit.test/people')
# it_should_temporarily_redirect('http://loseitorloseit.test/stats', 'http://loseitorloseit.test/people')
module RewriteMacro
module ExampleGroupMethods
def it_should_permanently_redirect(start_point, end_point)
it "should permanently redirect #{start_point} to #{end_point}" do
env = Rack::MockRequest.env_for(start_point, :method => 'get')
app = mock('app')
From bb2a78858cffa7c6937642986e9aca1a4f862c0d Mon Sep 17 00:00:00 2001
From: Ilya Grigorik <[email protected]>
Date: Thu, 10 Jun 2010 00:46:48 -0400
Subject: [PATCH] async rails3
---
Gemfile | 6 ++++++
app/controllers/widgets_controller.rb | 6 ++++++
app/models/widget.rb | 2 ++
config.ru | 1 +
StoriesController#manage (NameError) "`@ge der' is not allowed as an instance variable name"
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:290:in `instance_variable_get'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:290:in `read_key'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:233:in `[]'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:189:in `to_mongo'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:188:in `each_pair'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:188:in `to_mongo'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/object/misc.rb:54:in `tap'
/usr/lib/ruby/gems/1.8/gems/mongo_mapper-0.8.2/lib/mongo_mapper/plugins/keys.rb:187:in `to_mongo'