Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'json'
class Repo
def initialize(name)
@name = name
end
# lib/image_validator.rb
module ImageValidator
def validates_image(attr_name)
validates_attachment_presence attr_name
validates_attachment_content_type attr_name,
:content_type => Settings.paperclip.image_content_types
validates_attachment_size attr_name, :in => 1..1.megabyte
end
end
@croaky
croaky / gist:2401393
Created April 16, 2012 20:43 — forked from kevinzen/gist:2400225
Advice on DRYing this test up?
FIREFOX_FIXTURES = [
{
browser: 'Firefox',
gecko_version: '20101203',
os: 'Intel Mac OS X 10.6',
platform: 'Macintosh',
raw: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
version: '3.6.13'
},
{
@croaky
croaky / preamble.md
Created April 15, 2012 23:32
Preamble to apprentice trail maps

Breakable toy

Start a breakable toy:

  • A Rails app.
  • Something you're passionate about.
  • Work on it every week.
  • Stick to a style guide.
  • Push the code to Github.
@croaky
croaky / time_formats.rb
Created April 5, 2012 13:36
This goes in config/initializers
{
:stylish => "%l%P, %B %d", # 9am, April 13
:long_date => "%a, %b %d, %Y", # Fri, Apr 13, 1982
:longer_date => "%B %d, %Y %H:%M %Z", # April 13, 1982 9:18
:classy => "%B %d, %Y - %I:%M %p", # April 13, 2010 - 9:18am
:index => "%Y/%m/%d %H:%M", # 1982/04/13 9:18
:birthdate => "%a, %b %d, %Y", # Friday, Apr 13, 1982
:standard => "%B %d, %Y", # April 13, 1982
:abbr_month => "%b", # Apr
:abbr_month_day => "%b %d", # Apr 13
@croaky
croaky / deploy.md
Created April 3, 2012 18:35
Heroku staging deployment process with additional Github staging remote

Periodically use pgbackups to pull latest production data.

Merge master into staging

git checkout master
git reset --hard origin/master
git pull
git checkout staging

git reset --hard origin/staging

@croaky
croaky / developer_trail_maps.md
Created March 23, 2012 14:42
A trail map shows different paths someone can take. Everyone starts at different places and wants to go different places. Pick the ones that make sense for you.

Structure

  • Have a breakable toy side Rails project. It anchors your learning. Apply new skills/techniques here.
  • Put the code in Github. Give mentors access to the project. They'll review your code.
  • Understand the code review process and other style guidelines.
  • Deploy your breakable toy to Heroku.
  • Set learning goals weekly (e.g. X chapters of the Pickaxe, X Railscasts/week).
  • Keep a text document (using vim) to record interesting commands/concepts/things you've learned.
  • Review the text document daily for comprehension.
@croaky
croaky / README.md
Created March 18, 2012 18:43
Typical README for a thoughtbot Rails app that is deployed to Heroku

Rails app

is a Rails 3.1 app running on Ruby 1.9.2 and deployed to Heroku's Cedar stack. It has an RSpec and Cucumber test suite which should be run before commiting to the master branch.

Running tests

Create aliases:

@croaky
croaky / HOW_TO.md
Created March 16, 2012 05:43 — forked from michaeldauria/gist:2048022
Migrate from Copycopter 1.0 (hosted by thoughtbot) to Copycopter 2.0 (open source, deploy your own instance)

Use the latest version of the copycopter_client gem:

gem 'copycopter_client', '2.0.0'

Export your published drafts from copycopter.com:

RAILS_ENV=production bundle exec rake copycopter:export

This will create a config/locales/copycopter.yml file.

@croaky
croaky / single_recipient_smtp.rb
Created March 15, 2012 06:32
Set staging environment email to go to a single email address you control in order to not accidentally send production email addresses staging data.
module SingleRecipientSmtp
def self.included(clazz)
clazz.class_eval do
cattr_accessor :single_recipient_smtp_settings
end
end
def perform_delivery_single_recipient_smtp(mail)
mail.to = single_recipient_smtp_settings[:to]
mail.cc = nil