Skip to content

Instantly share code, notes, and snippets.

View bcardarella's full-sized avatar
⛵
Out sailing

Brian Cardarella bcardarella

⛵
Out sailing
View GitHub Profile

It All Starts With Templates

An Ember application starts with its main template. Put your header, footer, and any other decorative content in application.handlebars.

<header>
  <img src="masthead">
</header>

<footer>
@bcardarella
bcardarella / gist:3118576
Created July 15, 2012 20:50 — forked from lporras/gist:2403098
Using Backbone Views With Rails jQuery-ujs
var FormView = Backbone.View.extend({
el: '#form',
events: {
// Fired automatically when a file-type input is detected with a
// non-blank value. You can use this hook to implement a handler that
// will deal with those non-blank file inputs. Returning false will
// disallow standard form submission.
'ajax:aborted:file' : 'ajaxAbortedFile',
@bcardarella
bcardarella / uri.js
Created April 21, 2012 04:22 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
@bcardarella
bcardarella / config.ru
Created April 7, 2012 17:45 — forked from soveran/config.ru
Smaller Sinatra App
require 'sinatra'
get('/') { 'Hello world' }
def render_subject(context)
render subject, context
end
def render_content(context)
render content, context
end
private
require 'uri'
class IoraBot::Hangout < IoraBot::Observer
def matcher
/^(hangout|standup)(.*)$/mi
end
def handle(message, match_data)
person = message[:user][:name].split(' ')[0]
command = match_data[1]
if command == 'standup'
reply = "All: time for standup: #{link('iora_standup')}"
require 'benchmark'
def ifelse
if true
1
else
2
end
end
@bcardarella
bcardarella / gist:1161159
Created August 21, 2011 20:59 — forked from jasonm/gist:1161101
Links from #rcne 2011 backbone.js on rails fireside chat
@bcardarella
bcardarella / gist:1040967
Created June 22, 2011 19:43 — forked from theflowglenn/gist:1040942
Snippet from Rails 3 Client Side Validations JS to allow for AJAX spinner
// Set up the events for the form
form
.submit(function() { return form.isValid(settings.validators); })
// added loading toggle to handle the feedback spinner image (and changed 'beforeSend' to just 'before')
.bind('ajax:before', function() { $("#loading").toggle(); return form.isValid(settings.validators); })
.bind('ajax:success', function() { $("#loading").toggle(); })
// Callbacks
.bind('form:validate:after', function(eventData) { clientSideValidations.callbacks.form.after( form, eventData); })
.bind('form:validate:before', function(eventData) { clientSideValidations.callbacks.form.before(form, eventData); })
@bcardarella
bcardarella / hour.rb
Created June 10, 2011 05:07
User and hour model
class Hour < ActiveRecord::Base
belongs_to :user
validates_with PunchcardValidator #defined in config/initializers/punchclock_validator.rb
validates_presence_of :role, :message => "can't be blank"
validates_associated :user
validates_numericality_of :manual, :allow_nil => true
validates_presence_of :start_time, :if => :punchcard?
validates_presence_of :manual, :if => :manual?