Skip to content

Instantly share code, notes, and snippets.

View justincaldwell's full-sized avatar

Justin Caldwell justincaldwell

View GitHub Profile
require 'lockfile'
def timestamp
Time.now.strftime('%x %X')
end
begin
Lockfile.new('cron_mail_fetcher.lock', :retries => 0) do
config = YAML.load_file("#{RAILS_ROOT}/config/mailer_daemon.yml")
config = config[RAILS_ENV].to_options
class PhotoEmail < ActiveRecord::Base
belongs_to :doctor
belongs_to :kase
belongs_to :photo_email_status
has_many :photos
# Creates a new PhotoEmail from and incoming email
require 'mms2r'
class IncomingMailHandler < ActionMailer::Base
# Receive and process emails
def receive(email)
mms = MMS2R::Media.new(email)
photos = get_images_from_email(mms)
pemail = PhotoEmail.create_from_mail_handler(email, mms)
logit "Processing email from #{pemail.sender} with subject #{pemail.subject} "
require 'mime/types'
require 'RMagick'
class Photo < ActiveRecord::Base
establish_connection 'portal'
set_table_name 'photos'
belongs_to :kase
belongs_to :doctor
@justincaldwell
justincaldwell / time_bomb_diffuser.rb
Created September 21, 2011 22:41
Fix for ad_server time bomb.
#!/usr/bin/env ruby
require File.dirname(__FILE__) + "/../ad_server_dependencies.rb"
class StatKeyFix
# This fixes ad stats that were incorrectly keyed in redis
# according to ContentCacheAdvertisement#id instead of the
# expected ContentInstance#id. The issue only affected ads
# with a ContentCacheAdvertisement.id greater than 100,000
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-http'
require 'nokogiri'
class ReactorMulti < Goliath::API
def response(env)
def yield_with_default(name, content = nil, &block)
if content_for?(name)
content_for(name)
else
block_given? ? capture(&block) : content
end
end
@justincaldwell
justincaldwell / pre-commit
Created June 12, 2012 22:11
Pre commit hook to check syntax - Add to ./git/hooks/pre-commit
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
staged_files = `git diff --cached --name-only`.split
ruby_files = staged_files.select{|s| s =~ /\.rb$/}
ruby_files.each do |file|
playlist = Playlist.create(name: 'My Playlist', org_id: Org.find_by_slug('vidpresso').id)
# Create a bunch of entries in your dev database by sending a bunch of posts to air
# Now you can move those to the newly created playlist
playlist.entries << Entry.limit(5).order('id desc')
# Make sure Foreman is started (foreman start -f Procfile.development)
# And playback the playlist
@justincaldwell
justincaldwell / gist:3499546
Created August 28, 2012 16:06
Postgres setup
sudo apt-get install postgresql-9.1 postgresql-contrib-9.1 libpq-dev
sudo su postgres
psql
(from psql console)
create user ccpz with password 'ccpz';
create database ccpz OWNER ccpz ENCODING 'UTF8';
ALTER USER ccpz WITH SUPERUSER;
\q