Skip to content

Instantly share code, notes, and snippets.

View cmaujean's full-sized avatar

Christopher Maujean cmaujean

  • Mostly here, but sometimes elsewhere
View GitHub Profile
@cmaujean
cmaujean / image_decorator.rb
Created September 5, 2011 19:46
S3 for uploaded images, and automatic watermarking in Spree 0-60-stable
# app/models/image_decorator.rb
Image.class_eval do
has_attached_file(
:attachment,
:storage => :s3,
:bucket => ENV['S3_BUCKET']
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
@cmaujean
cmaujean / confirm.html.erb
Created August 16, 2011 01:30
Sending html email in spree w/pdf attachment:
<%# app/views/order_mailer/confirm.html.erb %>
<html>
<head>
<style type="text/css">
* {
font-size: 12px;
}
h2 {color: #00704a; font-family:Arial, Helvetica, sans-serif; font-size: 16px;}
.yellow_tr {
@cmaujean
cmaujean / domain_scam_email.txt
Created August 12, 2011 05:48
Caught in the wild, an example of the Chinese Domain Name Scam
From: Robert Zhang <robert.zhang@yiguannetwork.com>
Date: 2011/8/12
Subject: RE: Internet Domain Name & Keyword
To: our_client@example.com
Dear Our Client,
Based on your company having no relationship with them, we have
suggested they should choose another name to avoid this conflict but
@cmaujean
cmaujean / order_mailer.rb
Created August 3, 2011 19:37
0.60 order mailer override
require 'order_invoice'
class OrderMailer < ActionMailer::Base
helper "spree/base"
def confirm_email(order, resend = false)
send_the_mail(order, "Confirmation", "confirm", resend)
end
def shipped_email(order, resend = false)
Order.class_eval do
attr_accessor :ship_notified
# order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
state_machine :initial => 'cart', :use_transactions => false do
event :next do
transition :from => 'cart', :to => 'address'
transition :from => 'address', :to => 'delivery'
transition :from => 'delivery', :to => 'payment'
@cmaujean
cmaujean / console_output.txt
Created July 26, 2011 19:42
State machine overrides
>> Gateway.current.payment_profiles_supported?
=> false
>> Gateway.all
=> [#<Gateway::AuthorizeNetCim id: 3, type: "Gateway::AuthorizeNetCim", name: "Credit Card", description: "Authorize.net CIM ", active: true, environment: "production", created_at: "2010-03-08 20:29:39", updated_at: "2011-07-26 18:27:11", deleted_at: nil, display_on: "">]
>> Gateway.current
=> #<PaymentMethod::Check id: 4, type: "PaymentMethod::Check", name: "COD", description: "Cash on delivery.", active: true, environment: "production", created_at: "2010-07-21 20:03:14", updated_at: "2010-10-15 09:09:59", deleted_at: nil, display_on: "">
>>
# Updates the +payment_state+ attribute according to the following logic:
#
# paid when +payment_total+ is equal to +total+
# balance_due when +payment_total+ is less than +total+
# credit_owed when +payment_total+ is greater than +total+
# failed when most recent payment is in the failed state
#
# The +payment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
def update_payment_state
if round_money(payment_total) < round_money(total)
@cmaujean
cmaujean / refinery-output.txt
Created July 20, 2011 21:49
refinerycms refinery-app
1.9.2@refinery-app expelliarmus:~/workzone/projects master! $ refinerycms refinery-app
Running: "/Users/cmaujean/.rvm/rubies/ruby-1.9.2-p180/bin/ruby" -S bundle install
Fetching source index for http://rubygems.org/
Installing rake (0.9.2)
Using abstract (1.0.0)
Using activesupport (3.0.9)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.9)
Using erubis (2.6.6)
@cmaujean
cmaujean / Gemfile
Created July 16, 2011 22:38
my gemfile for 0.60.1
source 'http://rubygems.org'
gem 'rails'
gem 'aws-s3', :require => 'aws/s3'
gem 'dynamic_form'
gem 'heroku'
gem 'memcache-client'
gem 'prawn'
gem 'prawnto'
# Content Manager
# – can access overview, reports, events, faq, snippets, and pages.
class ContentAbility
include CanCan::Ability
def initialize(user)
if user.has_role?(:content)
can :manage, :all
cannot :manage, Product
cannot :manage, Configuration