Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
oojikoo-gist / backbonejs_handson.md
Last active August 29, 2015 14:14 — forked from riseshia/backbonejs_handson.md
backbone: handson

Backbone.js handsOn

  • Ruby : 2.2.0
  • Rails : 4.1.7
  • backbone-on-rails : 1.1.2.0
  • jQuery : 1.11.2

Preparing

Create App

@oojikoo-gist
oojikoo-gist / registrations_controller.rb
Last active August 29, 2015 14:15 — forked from jwo/registrations_controller.rb
rails: devise reset api
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@oojikoo-gist
oojikoo-gist / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@oojikoo-gist
oojikoo-gist / rsync.md
Created February 12, 2015 01:55
vagrant: rsync config

rsync set for vagrant

As of Vagrant 1.5, you can use RSync shared folders which will provide a dramatic increase in disk I/O between the host and guest. To use RSync for shared folders, simply add the following to your

Vagrantfile:

config.vm.synced_folder ".", "/vagrant", type: "rsync"
@oojikoo-gist
oojikoo-gist / vagrant_nfc_configuration.md
Created February 12, 2015 02:04
vagrant: nfs config

If you are running on OS X or a Linux that supports NFS folders,

you can also use NFS shared folders.

Vagrantfile:

config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.network "private_network", ip: "192.168.50.1"
@oojikoo-gist
oojikoo-gist / overwrite_get_set_methods.md
Last active August 29, 2015 14:15
rails: how to overwrite get and set methods

ActiveRecord: override how we access field

def length=(minutes)
  self[:length] = minutes * 60
end

def length
 self[:length] / 60
@oojikoo-gist
oojikoo-gist / rails_association.md
Created February 12, 2015 02:38
rails: associations

Using Associations

Quick quiz, hotshot: suppose users have a “status”: active, inactive, pensive, etc. What’s the right association?

class User < ActiveRecord::Base
  belongs_to :status  # this?
  has_one :status     # or this?
end
@oojikoo-gist
oojikoo-gist / custom_associations.md
Created February 12, 2015 02:53
rails: custom association on a model
belongs_to :primary_status, :model => 'Status', :foreign_key => 'primary_status_id'
belongs_to :secondary_status, :model => 'Status', :foreign_key => 'secondary_status_id'
@oojikoo-gist
oojikoo-gist / view_with_erb.md
Last active August 29, 2015 14:15
rails: run code in a view using ERB

Run code in a view using ERB:

  • <% ... %>: Run the code, but don’t print anything. Used for if/then/else/end and array.each loops. You can comment out sections of HTML using <% if false %> Hi there <% end %>. You get a free blank line, since you probably have a newline after the closing %>.

  • <%- ... %>: Run the code, and don’t print the trailing newline. Use this when generating XML or JSON when breaking up .rhtml code blocks for your readability, but don’t want newlines in the output.

  • <%= ... %>: Run the code and print the return value, for example: <%= @foo %> (You did remember the @ sign for controller variables passed to the view, right?). Don’t put if statements inside the <%=, you’ll get an error.

  • <%= h ... %>: Print the code and html escape the output: > becomes >. h() is actually a Ruby function, but called without parens, as Rubyists are apt to do.

@oojikoo-gist
oojikoo-gist / ubuntu-recover-grub.md
Created February 18, 2015 08:12
ubuntu: recover grub

sudo update-grub