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
# WARNING! Far from incomplete, very experimental! | |
# Attempt to grab the body of the message. | |
# looks in "base" message and if its multipart, go one level deep.. | |
# if not a multipart message return the body alone | |
# | |
def self.get_multipart_body(mail) | |
types = mail.parts.collect(&:content_type) | |
if types.include?("multipart/alternative") | |
m_part = mail.parts.find { |
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
<?php | |
/* Wordpress proof of concept - | |
Loop through posts in a particular category, outputting the first three latest as | |
"Latest" pages/posts. | |
Then use the rest as "archived" posts | |
David Graham, November 2009. | |
*/ |
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 Notifier < ActionMailer::Base | |
def set_email_parameters(booking) | |
# set your global instance variables here that could be used in the email subject or body | |
end | |
def parse_subject(subject) | |
ERB.new(subject).result(binding) | |
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
#overlapping dates check validations | |
validate :start_date_must_be_before_end_date | |
validate :overlapping_dates | |
private | |
def start_date_must_be_before_end_date | |
if start_date > end_date | |
errors.add_to_base "Start date must be before end date" |
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 Option < ActiveRecord::Base | |
attr_accessor :view_type, :comments_count, :expires_at_date, :expires_at_time | |
before_save :set_expires_at | |
after_save :set_reference, :set_default_room_allocation_name, :set_room_allocation_dates | |
private | |
def set_reference | |
self[:reference] = "OPT#{"%05d" % id}" |
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 Option < ActiveRecord::Base | |
attr_accessor :view_type, :comments_count, :expires_at_date, :expires_at_time | |
before_save :set_expires_at | |
after_save :set_reference, :set_default_room_allocation_name, :set_room_allocation_dates | |
private | |
def set_reference | |
self[:reference] = "OPT%05d" % id |
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
# This script contacts Campaign Monitor, and goes through each of the three main lists looking for "unsubscribed" people. | |
# User accounts are then "unsubscribed" if they've done it at CM.. | |
# | |
# | |
# Run through script/runner... | |
# I know this could probably be made much nicer but it is a first attempt :) | |
# | |
# | |
# put in the constants set in environment of our api list ids | |
lists = { CAMPAIGN_MONITOR_LIST_ONE => "Type1" } # add more here, LIST_ID => User Type... |
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
# I wrote this as a method for formatting group numbers to go into a pdf holiday voucher.. | |
# its messy but it works.. | |
# | |
# Results: | |
# X adult(s), Y child(ren) and Z infant(s) | |
# | |
# rules: - | |
# - pluralization hacks in case of 1 of each of them. | |
# - only show children and infants if they're > 0 | |
# - at least one adult is always present |
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
CACHE = MemCache.new(:namespace => "cheese") | |
CACHE.servers = '127.0.0.1:11211' |
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
# the usual disclaimers apply, this may or may not work for you, and it's rather hacky, but works for me(tm) :) | |
# first parse the mail | |
mail = TMail::Mail.parse(params[:email]) | |
# parse the mail (as below) | |
email.body = Email.get_multipart_body(mail) | |
# in your model... |
OlderNewer