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
# IN ENVIRONMENT.RB, ADD THESE LINES AFTER THE BOOT SECTION AND BEFORE THE INITIALIZER BLOCK | |
# (e.g. on line 13 of most environment.rb's): | |
if Gem::VERSION >= "1.3.6" | |
module Rails | |
class GemDependency | |
def requirement | |
r = super | |
(r == Gem::Requirement.default) ? nil : r | |
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
def pay(bet) | |
`curl -s http://roulette.engineyard.com` =~ /13/ ? bet * 35 : 0 | |
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 'open-uri' | |
def pay(bet) | |
URI.parse('http://roulette.engineyard.com').read =~ /13/ ? bet * 35 : 0 | |
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
<? | |
$response = file_get_contents("http://elections.raisethehammer.org/api/election/1"); | |
$decoded = json_decode($response); // requires PHP >= 5.2.0 | |
?> | |
<? foreach($decoded->candidates as $candidate): ?> | |
<?= $candidate->name ?><br /> | |
<? endforeach; ?> |
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
LEGEND: * (layout) ! (interior) | |
application_layout | |
header * | |
left menu * | |
search | |
flash messages * | |
right content box (what height?) ! | |
footer * |
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
has_attached_file :video, | |
:url => ":class/:id/:style/:basename.:extension", | |
:path => ":class/:id/:style/:basename.:extension", | |
:storage => :s3 # this is redundant if you are using S3 for all your storage requirements | |
validates_attachment_presence :video | |
has_attached_file :thumbnail, :styles => {:thumb => "162x161#"} # adjust the thumb style as needed |
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 Paperclip | |
# The Attachment class manages the files for a given attachment. It saves | |
# when the model saves, deletes when the model is destroyed, and processes | |
# the file upon assignment. | |
class Attachment | |
def self.default_options | |
@default_options ||= { | |
:url => "/system/:class/:attachment/:id/:style/:basename.:extension", | |
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension", |
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 AddVideoFields < ActiveRecord::Migration | |
def self.up | |
add_column :videos, :thumbnail_file_name, :string | |
add_column :videos, :thumbnail_content_type, :string | |
add_column :videos, :thumbnail_file_size, :integer | |
add_column :videos, :thumbnail_updated_at, :datetime | |
add_column :videos, :video_file_name, :string | |
add_column :videos, :video_content_type, :string | |
add_column :videos, :video_file_size, :integer | |
add_column :videos, :video_updated_at, :datetime |
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
# don't forget to turn off forgery protection: | |
# protect_from_forgery :except => [:swfupload, :encode_notify] | |
# if you're not using swfupload, code like this would be in your create and update methods | |
# all you really need to ensure is that after @video.save, you run @video.encode! | |
def swfupload | |
@video = Video.new(params[:video]) | |
@video.swfupload_file = params[:Filedata] | |
# if we're in production, test should be nil but otherwise we're going to want to encode | |
# videos using Zencoder's test setting so we're not spending cash to do so |
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 Zencoder | |
include HTTParty | |
headers "Accept" => "application/json", "Content-Type" => "application/json" | |
base_uri 'https://app.zencoder.com/api' | |
default_params :api_key => "YOUR-API-KEY-GOES-HERE" | |
format :json | |
attr_accessor :job_id | |
attr_reader :errors | |
attr_reader :output_url |