Skip to content

Instantly share code, notes, and snippets.

View sumitasok's full-sized avatar

Sumit. M. Asok sumitasok

View GitHub Profile
@sumitasok
sumitasok / .irbrc
Created November 17, 2011 06:02
irb tricks
# 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
@sumitasok
sumitasok / bash_profile
Last active September 28, 2015 03:17
to number all files in a folder
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
@sumitasok
sumitasok / gallois.zsh-theme
Created March 28, 2012 11:19
my modified gallois.zsh-theme
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"
@sumitasok
sumitasok / gist:2357831
Created April 11, 2012 08:18
Oh-My-Zsh ~/.zshrc
# 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"
@sumitasok
sumitasok / .rvmrc
Created April 13, 2012 04:00
.rvmrc Project specific for Rails
#!/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
@sumitasok
sumitasok / lambda_expect.rb
Created April 24, 2012 07:18
Rspec Usage (Lambda, Expect)
# 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)
@sumitasok
sumitasok / user.rb
Created April 24, 2012 09:35
accepts_nested_attributes_for - Rails association management using single form submit.
# 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
@sumitasok
sumitasok / rspec_expecations_spec.rb
Created April 27, 2012 06:55
Rspec Expectations
# to get the Location from the response header.
response.header["Location"].should eq('/admin/clients/'+client.id+'/edit')
@sumitasok
sumitasok / form.html
Created May 16, 2012 11:48
Form fields getting Accessible
<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 >
@sumitasok
sumitasok / action_controller.rb
Created September 22, 2012 06:59
Module included
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',