Skip to content

Instantly share code, notes, and snippets.

View dbackeus's full-sized avatar

David Backeus dbackeus

View GitHub Profile
@dbackeus
dbackeus / disappeared_parent.rb
Created August 4, 2011 09:24
Disappeared parent in Mongoid after_destroy
class Parent
include Mongoid::Document
embeds_many :children
before_create :create_children
before_destroy :destroy_children
private
def create_children
3.times { children.build }
end
@dbackeus
dbackeus / api.rb
Created June 18, 2011 15:53
Streamio RubyGem Example
require "streamio"
# Configure it
Streamio.configure do |config|
config.username = "your_account_name"
config.password = "your_api_private_key"
end
# Create a Video
video = Streamio::Video.create :file => File.new("path/to/an/awesome.movie")
@dbackeus
dbackeus / videos_public_show.json
Created May 17, 2011 13:12
Videos#public_show
{
"aspect_ratio_multiplier":1.7777777777777777,
"created_at":"2011-02-09T16:13:41Z",
"duration":21.9,
"plays":34,
"progress":1.0,
"state":"ready",
"tags": ["Teaser", "System-Demo"],
"title":"Streamio 20th Century Fox Teaser",
"updated_at":"2011-02-10T14:37:52Z",
@dbackeus
dbackeus / uploads_list.json
Created May 10, 2011 13:27
Uploads#index
[
{
"account_id":"4c57f3975412901427000005",
"tags":["Community"],
"title":"SpringCampaign",
"id":"4dc938f154129008fe000002"
}
]
{
"account_id":"4c57f3975412901427000005",
"tags":["Community"],
"title":"SpringCampaign",
"id":"4dc938f154129008fe000002"
}
@dbackeus
dbackeus / payex.rb
Created March 1, 2011 11:46
Simple helper module to help communicate with payex.
module Payex
mattr_accessor :account_number
mattr_accessor :encryption_key
MD5_CHECK_FIELDS = {
"pxorder/pxorder.asmx/Initialize7" => [:accountNumber, :purchaseOperation, :price, :priceArgList, :currency, :vat, :orderID, :productNumber, :description, :clientIPAddress, :clientIdentifier, :additionalValues, :externalID, :returnUrl, :view, :agreementRef, :cancelUrl, :clientLanguage],
"pxagreement/pxagreement.asmx/CreateAgreement3" => [:accountNumber, :merchantRef, :description, :purchaseOperation, :maxAmount, :notifyUrl, :startDate, :stopDate],
"pxagreement/pxagreement.asmx/DeleteAgreement" => [:accountNumber, :agreementRef],
"pxorder/pxorder.asmx/Complete" => [:accountNumber, :orderRef],
"pxagreement/pxagreement.asmx/AutoPay2" => [:accountNumber, :agreementRef, :price, :productNumber, :description, :orderId, :purchaseOperation],
@dbackeus
dbackeus / lost_reference.rb
Created January 17, 2011 10:58
Embedded document lose reference to parent when parent fails to save
class Account
include Mongoid::Document
embeds_many :memberships
field :name, :type => String
validates_presence_of :name
end
@dbackeus
dbackeus / mongoid_validations.rb
Created January 11, 2011 14:06
Mongoid 2.0 rc validates stuff like there's no tomorrow
class Account
include Mongoid::Document
references_many :videos
end
class Video
include Mongoid::Document
referenced_in :account
source 'http://rubygems.org'
gem 'rails'
# Essential
gem "devise"
gem 'bson_ext'
gem 'mongoid', ">= 2.0.0.beta"
gem 'mongoid_grid', :require => "mongoid/grid"
gem 'SystemTimer'
@dbackeus
dbackeus / sv.formtastic.yml
Created November 3, 2010 11:38
Basic formtastic translation to swedish.
sv:
formtastic:
:yes: Ja
:no: Nej
create: Skapa
save: Spara
submit: Skicka
required: Obligatorisk