Skip to content

Instantly share code, notes, and snippets.

View virajkulkarni14's full-sized avatar
💻
Code on...

Viraj G. Kulkarni (विराज गु. कुलकर्णी) virajkulkarni14

💻
Code on...
View GitHub Profile
@virajkulkarni14
virajkulkarni14 / gist:7114358
Last active December 26, 2015 07:19 — forked from RaVbaker/gist:2967695
Important Ubuntu 12.04 todo for Rails dev setup

Ubuntu 12.04 Ruby on Rails Development Environment

I haven't set up an install guide for the latest ubuntu release, largely because the last set of instructions worked pretty closely with the latest and greatest Ubuntu, 12.04 Precise Pangolin, however when installing today, I found that there were enough differences in the way that I configure my setup to justify an update, so here it goes. Yes, I'm late to the party, but a quick google search didn't find anything that I felt was as complete for my requirements as my previous install guides, so here I go.

As always with my install guides, I have included here is just about everything you'll need (and then some) to get started with ruby on rails development with Ubuntu 12.04 as a platform. These are my settings and preferences, and this is certainly not the only way of doing things, so keep that in mind.

Step 1: Get the repos ready and run updates.

sudo apt-get update && sudo apt-get upgrade
# setup vagrant
gem install vagrant
vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
mkdir my_vagrant_test
cd my_vagrant_test
vagrant init lucid32
vim Vagrantfile
vagrant up
vagrant ssh
@virajkulkarni14
virajkulkarni14 / _index.md
Created October 23, 2013 08:53 — forked from ambethia/_index.md
Extremely nifty and handy deployment notes
@virajkulkarni14
virajkulkarni14 / mass_assignment_authorizer.rb
Last active December 29, 2015 23:58 — forked from phaex/gist:919326
Rails mass assignment sanitizer
# based on Railscast 237, http://railscasts.com/episodes/237-dynamic-attr-accessible
private
# take care of attr_accessible based on user role
def mass_assignment_authorizer
if accessible == :all
# original hack, doesn't work with AR attribute type
# self.class.protected_attributes
# This hack should work as well with AR attribute type
ActiveModel::MassAssignmentSecurity::BlackList.new {:id}
@virajkulkarni14
virajkulkarni14 / PostsController.rb
Last active December 29, 2015 23:59 — forked from dhh/gist:1975644
Related to mass assignment and params sanitization
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@virajkulkarni14
virajkulkarni14 / gist:8770075
Last active March 14, 2018 12:02 — forked from kinopyo/gist:5682347
Conceptual Differences between Ruby's to_s and to_str methods

Concept

(The blockquote style does not look so well so I just pasted directly, but these are all quoted from the links in the bottom of this page)

You should not implement to_str unless your object acts like a string, rather than just having a string representation. The only core class that implements to_str is String itself.

[to_i and to_s] are not particularly strict: if an object has some kind of decent representation as a string, for example, it will probably have a to_s method… [to_int and to_str] are strict conversion functions: you implement them only if you object can naturally be used every place a string or an integer could be used.

to_str is used by methods such as String#concat to convert their arguments to a string. Unlike to_s, which is supported by almost all classes, to_str is normally implemented only by those classes that act like strings. Of the built-in classes, only Exception and String implement to_str

#!/bin/bash
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo chown -R mongodb:mongodb /var/lib/mongodb/
sudo service mongodb start
sudo rm /var/lib/mongodb/mongod.lock
sudo chown -R mongodb:mongodb /var/lib/mongodb/
sudo service mongodb start