Skip to content

Instantly share code, notes, and snippets.

View richsoni's full-sized avatar

Richard Soni richsoni

View GitHub Profile
@richsoni
richsoni / Backbone_Base_Model.md
Last active December 20, 2015 03:18
Tutorial on Models.Base, and how to make a child

Creating Models becomes much easier with the Base Model.

In this example I will walk through some of the default conventions and requirements for creating such a model.

@richsoni
richsoni / Backbone_Base_Collection.md
Created July 23, 2013 13:22
Tutorial on how to use Base collection for Backbone

Creating Collections becomes much easier with the Base Collection.

In this example I will walk through some of the default conventions and requirements for creating such a collection.

@richsoni
richsoni / base_view.js.coffee
Last active December 20, 2015 04:29
How to render validations in the base view
#actually renders the validations
#if you are using listenTo these arguments are automatically passed in
renderValidations: (model, errors)->
_.each errors, (error) =>
$el = if error.cid then @$("[data-id=#{error.cid}]") else @$el
selector = if error.nested_attr then "[data-nested-name=#{error.nested_attr}]" else "[name=#{error.name}]"
#validations are namespaced by model id for removal
$el.find(selector).after("<span class='#{model.cid}-validation label label-important'>#{error.errors.join(', ')}</span>")
@richsoni
richsoni / gcherry.sh
Created July 31, 2013 17:55
Alias to cherry pick either the last commit on the last branch or the last commit on a given branch
#!/bin/sh
gcherry(){
if [ $1 ];then
name=$1
else
name="@{-1}"
fi
echo "cherry picking $( git reflog $name -n 1 )"
git cherry-pick $( git reflog $name -n 1 | awk '{print $1}' )
@richsoni
richsoni / csv_split.sh
Created August 9, 2013 13:03
Cut Out Pieces Of A CSV in BASH
USAGE="Usage: csv_split file.csv (lines to be included use n..n as a range)"
if [ "$#" == 0 ]; then
echo "$USAGE"
exit 1
fi
filename=$1
shift
@richsoni
richsoni / pryrc
Created August 15, 2013 15:18
Pry History Walker
#usage _! (2 previous lines) _! 3 (3 previous lines)
def _!(num = 2)
line = Pry.history.to_a[-1-num]
puts "evaling #{line}"
unless line == '_!' or line == '_'
Pry.send(:eval, line)
end
end
@richsoni
richsoni / my_router.sh
Created August 16, 2013 14:02
Router IP Script for Mac OS X
route -n get default | grep gateway | awk '{print $2}'
@richsoni
richsoni / 1_Gemfile.rb
Last active December 21, 2015 07:19
Setup for testing Backbone in a rails app
#should only need to be done once
gem 'jasmine'
gem 'guard-jasmine'
gem "jasminerice", :git => 'https://github.com/bradphelan/jasminerice.git'
@richsoni
richsoni / browser_testing
Created August 19, 2013 15:53
Testing a backbone app with jasminerice in rails
localhost:[port]/jasmine
@richsoni
richsoni / 1view.coffee
Created August 26, 2013 17:11
Put your backbone zombies through the woodchipper
#keep tabs on your vent bindings. If you dont kill them they will slowly walk toward your app, and suck its brains (memory) out
#################
# INSTEAD OF
# App.Vent.bind('some_event', _.bind(some_callback, this))
# App.Vent.bind('other_event', _.bind(other_callback, this))
# Do
@bindGlobalEvents
some_event: 'someCallback'