This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this code goes into .irbrc file in you home folder | |
require 'rubygems' | |
require 'wirble' | |
require 'awesome_print' | |
require 'hirb' | |
# color the ruby console | |
Wirble.init | |
Wirble.colorize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function number_incrementally { | |
i=0 | |
#echo "Prefix if any:" | |
#read prefix | |
#echo "Number starts at(default is 0):" | |
#read i | |
i=$1 | |
prefix=$2 | |
echo "Number Starts at $i with prefix as $prefix" | |
for f in *; do n="$prefix$i - $f"; mv "$f" "$n"; i=`expr $i + 1`;done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch | |
git_custom_status() { | |
local cb=$(current_branch) | |
if [ -n "$cb" ]; then | |
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set name of the theme to load. | |
# Look in ~/.oh-my-zsh/themes/ | |
# Optionally, if you set this to "random", it'll load a random theme each | |
# time that oh-my-zsh is loaded. | |
ZSH_THEME="gallois" | |
# Example aliases | |
alias zshconfig="mate ~/.zshrc" | |
# alias ohmyzsh="mate ~/.oh-my-zsh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
environment_id="ruby@gemset" | |
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \ | |
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then | |
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id" | |
[[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 - Lambda | |
lambda { | |
post :create, :document => FactoryGirl.attributes_for(:document) | |
}.should change { Document.count }.by(1) | |
# 2 - Expect | |
expect { | |
post :create, :document => FactoryGirl.attributes_for(:document) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model file | |
class User < ActiveRecord::Base | |
has_many :books | |
accepts_nested_attributes_for :books, :reject_if => lambda {|book| book[:name].blank? }, :allow_destroy => true | |
end | |
# :reject_if => it passes the whole hash passed from browser with book details into this Proc(lambda) and iterates over each book hash. The book record is not created if the condition given in the lambda block is satisfied. | |
# :allow_destroy => if set to true, then the book record that was passed from browser, while submitting User form, with a key-value pair :_destroy => 1 (or '1' or true or "true") will be destroyed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to get the Location from the response header. | |
response.header["Location"].should eq('/admin/clients/'+client.id+'/edit') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<fieldset> | |
<legend>Form header</legend> | |
<! this above fieldset legend should have the text explaining the forms purpose > | |
<label for="id_of_related_input_field">Text corresponding to input field</label> | |
<input id="id_of_related_input_field" type="..." /> | |
<! have label close to input, have for(label) and id(input) same for identification by screen reader, prefer this way over nesting input under label > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserDefined | |
module ActionController # :nodoc: all | |
def self.included(base) | |
base.send :helper_method, :user_method | |
end | |
private | |
def user_method | |
@user_defined ||= UserDefined.new( | |
:var => 'value', |
OlderNewer