Skip to content

Instantly share code, notes, and snippets.

View cmthakur's full-sized avatar
🎯
Focusing

Chandra M. Thakur cmthakur

🎯
Focusing
View GitHub Profile
@cmthakur
cmthakur / application.rb
Last active August 29, 2015 14:26 — forked from basti/application.rb
Local Rails 4 assets precompilation using Capistrano 3 and rsync
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@cmthakur
cmthakur / rbac rails
Created July 18, 2015 11:03
RBAC with cancan
# Let’s consider an example. We will add the models as they are required. Right now the basic application has models User, Role and Permission. The relationship is as shown
Role #the model to save the role
:name # the role name
:has_many :users
:has_and_belongs_to_many :permissions
User
:name # user name
:email # user email
@cmthakur
cmthakur / programming interview questions
Last active August 29, 2015 14:24
Programming Interview Questions
_Originally published in June 2008_
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last [job](http://www.tobi.com/), I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
## What to expect
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.
@cmthakur
cmthakur / _flash_messages.html.erb
Last active August 29, 2015 14:18 — forked from roberto/_flash_messages.html.erb
How to add flash message in Rails 4
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> alert-dismissable fade in">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<%= message %>
</div>
<% end %>

How to install PhantomJS on Ubuntu

Version: 1.9.7

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
#!/bin/bash -ex
# Assumes:
# homebrew
# chruby
# ruby-install
# postgres.app
# this bit might not be necessary, but can't hurt
brew upgrade ruby-install
# Capistrano configuration
#
# require 'new_relic/recipes' - Newrelic notification about deployment
# require 'capistrano/ext/multistage' - We use 2 deployment environment: staging and production.
# set :deploy_via, :remote_cache - fetch only latest changes during deployment
# set :normalize_asset_timestamps - no need to touch (date modification) every assets
# "deploy:web:disable" - traditional maintenance page (during DB migrations deployment)
# task :restart - Unicorn with preload_app should be reloaded by USR2+QUIT signals, not HUP

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
ssh-add ~/.ssh/id_rsa
@cmthakur
cmthakur / string with hash to hash
Created March 27, 2014 09:48
Change a given string that contains hash inside it to a hash object. Similar to eval(string_with_hash)
def convert_to_hash(string)
string.gsub(/[{}:]/,'').split(', ').inject({}) do |hash, str_value|
splitted_value = str_value.split('=>')
splitted_value.delete('')
key,value = splitted_value
if splitted_value.count > 2
new_str = str_value.split(key)
new_str.delete('')
value = convert_to_hash(new_str.last.to_s)