Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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: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
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 / 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';
?>
@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 / myapp.js
Created March 2, 2012 16:20
Underscore.js errors
MYAPP = {
fetchTemplate: function(path, done) {
window.JST = window.JST || {};
// Should be an instant synchronous way of getting the template, if it
// exists in the JST object.
if (JST[path]) {
return done(JST[path]);
}
@andrewpthorp
andrewpthorp / app.js
Created March 12, 2012 18:17
PGExternalScreen Error
function resultHandler(result){
alert(result);
}
function errorHandler(error){
alert("ERROR: "+ error);
}
$(document).on("deviceready", function(){
PGExternalScreen.setupScreenConnectionNotificationHandlers( resultHandler, errorHandler );