Skip to content

Instantly share code, notes, and snippets.

@staltz
staltz / introrx.md
Last active May 10, 2024 12:08
The introduction to Reactive Programming you've been missing
@pixelhandler
pixelhandler / autosavemodel.coffee
Created May 23, 2014 00:11
Auto save an Ember.js model (DS.Model)
get = Ember.get
App.BaseModel = DS.Model.extend
autoSave: (->
if get(@, 'isDraft') and !(get @, 'isNew') and isReallyDirty @
Ember.run.debounce @, '_doAutoSave', 12000
).observes 'isDirty'
_doAutoSave: ->
@t2
t2 / application.rb
Created December 12, 2011 02:13
Formatting Rails form elements for Twitter Bootstrap error validation
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe