Skip to content

Instantly share code, notes, and snippets.

View m3talsmith's full-sized avatar

Michael Christenson II m3talsmith

View GitHub Profile
@m3talsmith
m3talsmith / stripul.sass
Created June 20, 2011 19:50
strip styling from ul
ul
padding: 0
margin: 0
list-style: none none
@m3talsmith
m3talsmith / sample_authorize_spec.rb
Created June 27, 2011 21:18
A sample model spec
context '#authorize' do
before do
@user = Factory.create :user, is_active: true
end
it 'is not active' do
@user.update_attribute :is_active, false
User.authorize(@user.login, @user.password).should_not be
end
@m3talsmith
m3talsmith / is_admin.rb
Created June 27, 2011 21:47
is admin through memberships
class Member
# ...
class << self
# ...
def is_admin?(organization, user)
member = first(:conditions => {:organization_id => organization.id, :user_id => user.id})
return false unless member
return member.role == 'admin'
end
# ...
undefined method `entries' for #<String:0x000001044e31f8>
/Users/m3talsmith/Development/bulletin-builder/app/models/organization.rb:229:in `create_parishes_from_feed'
/Users/m3talsmith/Development/bulletin-builder/app/models/organization.rb:215:in `block in create_or_update_all_parishes'
@m3talsmith
m3talsmith / bulletin.rb
Created July 8, 2011 05:10
Possible embedded heirarchy
class Bulletin
include Mongoid::Document
embeds_many :sections
end
@m3talsmith
m3talsmith / bulletin.rb
Created July 8, 2011 05:28
Possible embedded heirarchy
class Bulletin
include Mongoid::Document
has_and_belongs_to_many :sections
end
@m3talsmith
m3talsmith / gist:1138813
Created August 11, 2011 02:47
remote file for paperclip
property = Property.find(email.subject)
email_body = email.parts.first.body.parts.present? ? email.parts.first.body.parts.first.body.decoded : email.parts.first.body.decoded
drive_report = property.drive_report ? property.drive_report : DriveReport.new(:property => property)
drive_report.description = email_body
drive_report.save
if email.has_attachments?
# -- Image Mail Header Notes --
@m3talsmith
m3talsmith / image_url_to_paperclip.rb
Created August 15, 2011 19:10
Paperclip image from image url
def store_image(url, image_name)
host = url.split('/')[2]
path = "/#{url.split('/')[3..-1].join('/').gsub(/\?.*$/, '')}"
image_path = "#{Rails.root}/tmp/downloads/#{image_name}"
Net::HTTP.start(host) do |http|
response = http.get(path)
open(image_path, 'wb') do |file|
file.write(response.body)
end
@m3talsmith
m3talsmith / rvmrc
Created August 23, 2011 23:19
default system rvmrc
rvm_project_rvmrc=1
rvm_archflags="-arch x86_64"
rvm_install_on_use_flag=1
@m3talsmith
m3talsmith / gist:1218645
Created September 15, 2011 05:59
test error
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user", :js => true do
visit new_user_registration_path