Skip to content

Instantly share code, notes, and snippets.

View andrewtimberlake's full-sized avatar

Andrew Timberlake andrewtimberlake

View GitHub Profile
Prawn::Document.generate "test.pdf" do
stroke_horizontal_rule
text "Some text\nwith a line break"
stroke_horizontal_rule
move_down 10
stroke_horizontal_rule
text "Some <b>bold</b> text<br />with a line break"
stroke_horizontal_rule
end
- has_attachment :content_type => :image,
- :thumbnails => {
- :thumb => [80,80],
- :small => '320x320>'
- },
- :storage => :s3,
- :s3_access => :private
+
+ has_attached_file :photo,
+ :styles => {
class ChangePhotoFromAttachmentFuToPaperclip < ActiveRecord::Migration
def self.up
#Reorganise the actual photos on AWS to suit the RWS/Paperclip schema
#Rename attachement_fu columns to paperclip convention
rename_column :photos, :filename, :photo_file_name
rename_column :photos, :content_type, :photo_content_type
rename_column :photos, :size, :photo_file_size
#Remove non-paperclip columns
remove_column :photos, :width
require 'right_aws'
namespace :utils do
namespace :attachments do
task :initialize_s3 => :environment do
s3_config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../config/amazon_s3.yml'))
s3_config = s3_config[RAILS_ENV].to_options
@s3 = RightAws::S3.new(s3_config[:access_key_id], s3_config[:secret_access_key])
end
@andrewtimberlake
andrewtimberlake / tabalize_array.rb
Created December 31, 2008 09:52
Will add a method to Array to print out a pretty text table of a multi-dimensional array
class Array
def tabalize(headings, justifications = nil, out = STDOUT)
raise ArgumentError.new('only works on an array of arrays') if size > 0 && ![0].is_a?(Array)
raise ArgumentError.new('headings, justifications and array elements must all have the same number of elements') if size > 0 && (headings.size != [0].size) && (!justifications.nil? && (headings.size != justifications.size))
sizes = Array.new(headings.size, 0)
headings.each_with_index do |h,i|
sizes[i] = [sizes[i], h.to_s.length].max
end
each do |row|
row.each_with_index do |e, i|