Skip to content

Instantly share code, notes, and snippets.

<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
@mwoods79
mwoods79 / rails_setup.rb
Created April 20, 2011 03:55
Rails template/initializer for new rails project original source: http://everydayrails.com/2011/02/28/rails-3-application-templates.html
# create rvmrc file
create_file ".rvmrc", "rvm gemset use #{app_name}"
gem "haml-rails"
gem "sass"
# hpricot and ruby_parser required by haml
gem "hpricot", :group => :development
gem "ruby_parser", :group => :development
gem "nifty-generators"
gem "simple_form"
@mwoods79
mwoods79 / Backbone.BaseModel.js
Created December 14, 2011 18:09
Unobtrusively make backbone always fire 'success' and 'error' events.
var _save = Backbone.Model.prototype.save;
var BaseModel = Backbone.Model.extend({
save: function(attrs, options) {
options || (options = {});
var success = options.success;
var model = this;
// success doesn't have an event so always trigger
options.success = function(resp, status, xhr) {
model.trigger('success', model, resp, xhr);
@mwoods79
mwoods79 / calculator.js
Created December 5, 2012 06:52
Functional Programming A Calculator In Javascript
// found this here, OMG http://net.tutsplus.com/tutorials/javascript-ajax/what-they-didnt-tell-you-about-es5s-array-extras
function calculate (calculation) {
//build an array containing the individual parts
var parts = calculation.match(
// digits |operators|whitespace
/(?:\-?[\d\.]+)|[-\+\*\/]|\s+/g
);
//test if everything was matched
if( calculation !== parts.join("") ) {
@mwoods79
mwoods79 / HolyCow.md
Created December 6, 2012 06:14
I stole this from RestKit, and I am so happy! :)

So you have an NSDictionary that looks like this.

{
    anonymous = true;
    "attendee_id" = 5796;
    "briefing_id" = 616;
    comments = "More Cookies please!";
    data =     (
                {
            "agenda_id" = 1200;
@mwoods79
mwoods79 / backbonerails.vim
Created December 7, 2012 22:05
Some bindings for backbone in rails.vim
" Set up some useful Rails.vim bindings for working with Backbone.js
autocmd User Rails Rnavcommand template app/assets/javascripts/backbone/templates -glob=**/* -suffix=.jst.ejs
autocmd User Rails Rnavcommand jmodel app/assets/javascripts/backbone/models -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jview app/assets/javascripts/backbone/views -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jcollection app/assets/javascripts/backbone/collections -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jrouter app/assets/javascripts/backbone/routers -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jspec spec/javascripts -glob=**/* -suffix=.coffee

If you need to add the ability change passwords in the "admin" panel of boilerplate.

Add the password and password_confirmation to the User Decorator

# app/decorators/inherited_resources/user_decorator.rb
module InheritedResources
  class UserDecorator < Decorator
  # ...
 
@mwoods79
mwoods79 / creditcards.md
Last active December 28, 2015 21:39
Suggested API

GET /users/:id/credit_card

{
  "credit_cards": [
    "token",
    "anotherToken"
  ]
}