Skip to content

Instantly share code, notes, and snippets.

View djgraham's full-sized avatar
:shipit:
Oh hello!

David Graham djgraham

:shipit:
Oh hello!
View GitHub Profile
# 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 {
<?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.
*/
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
#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"
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}"
@djgraham
djgraham / option.rb
Created March 31, 2010 12:42 — forked from caius/option.rb
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
@djgraham
djgraham / campaignmonitor_cron.rb
Created April 12, 2010 23:31
Example of getting a list of unsubscribed users from Campaign Monitor using the gnumarcelo / campaigning gem, when you already know your list_ids..
# 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...
# 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
CACHE = MemCache.new(:namespace => "cheese")
CACHE.servers = '127.0.0.1:11211'
@djgraham
djgraham / email.rb
Created June 24, 2010 13:24
Parsing multipart message bodies with Tmail in ruby
# 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...