Skip to content

Instantly share code, notes, and snippets.

View andrewpthorp's full-sized avatar
🎯

Andrew Thorp andrewpthorp

🎯
View GitHub Profile
@andrewpthorp
andrewpthorp / index.html
Created February 3, 2012 20:11
addthis
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
</div>
<script>
var addthis_config = {
services_compact: 'twitter, facebook',
services_exclude: 'print'
}
@andrewpthorp
andrewpthorp / index.php
Created January 4, 2012 19:11
My tiny MVC for PHP
<?php
// Default Values
ini_set('display_errors', 1);
// Load Application
require 'application/wildfire.php';
?>
class Message < ActiveRecord::Base
before_save :check_active_message
def check_active_message
if self.active
Message.where(:active => true).first.update_attributes(:active => false)
end
end
@andrewpthorp
andrewpthorp / gist:1370624
Created November 16, 2011 16:51
JS Namespaces
// Is there a name for this pattern? I would love some resources to read about pros/cons using it.
var FOO = FOO || {};
FOO.ui = {};
FOO.ui.prep_links = function(){
// Some Vars
@andrewpthorp
andrewpthorp / gist:1301835
Created October 20, 2011 18:08
ActiveRecord models in helpers
module SomeHelper
def metrics(account)
opens = ContactSnapshot.opens(account, Time.zone.now-30.days, Time.zone.now).size
content_tag :ul do
content_tag :li, "#{opens} Opens."
end
@andrewpthorp
andrewpthorp / gist:1298468
Created October 19, 2011 14:32
RSpec have_selector, which is more appropriate?
# First
content.should have_selector("a.current", :content => "Remove")
# Second
content.should have_selector("a.current", "Remove")
# Which one would you prefer, and why?
@andrewpthorp
andrewpthorp / gist:1267926
Created October 6, 2011 16:53 — forked from benmanns/gist:1267915
Preference for helper specs?
# Option 1:
# Use content to separate the helper from the spec
it "should have something" do
content = helper.some_helper_method
content.should have_tag('a', :text => 'foo')
end
# Option 2:
# Combine helper call and spec
@andrewpthorp
andrewpthorp / gist:1267848
Created October 6, 2011 16:23
Preference for helper specs?
# Option 1:
# Use content to separate the helper from the spec
it "should have something" do
content = helper.some_helper_method
content.should have_tag('a', :text => 'foo')
end
# Option 2:
# Combine helper call and spec
@andrewpthorp
andrewpthorp / gist:1200961
Created September 7, 2011 15:57
Nesting tags
emails = []
recipient.contact.emails.each do |email|
emails << content_tag(:li) do
form.radio_button(:email, email.address, :class => "radio-button")
form.label(:email, nil, :value => email.address) do
"<span>#{email.location}</span>"
end
end
end
emails.join
class BrandIdentity < ActiveRecord::Base
has_one :library_asset, :dependent => :destroy, :as => :asset
end