Skip to content

Instantly share code, notes, and snippets.

@anklos
anklos / rspec_test.rb
Created June 7, 2011 01:41
rspec mock and stub
server = mock_model(UI::Server)
server.stub!(:id).and_return(1)
server.stub!(:name).and_return('t1')
server.stub!(:ip_address).and_return('10.1.1.1')
server.stub!(:agent).and_return('Storage Cruiser')
UI::Server.stub!(:find_by_server_id).and_return(server)
get 'new'
response.should render_template('server_hbas/_new')
@anklos
anklos / gist:1011552
Created June 7, 2011 02:12
vim settings
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" github vim plugins
@anklos
anklos / gist:1030662
Created June 17, 2011 01:01
git config
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto
@anklos
anklos / gist:1041999
Created June 23, 2011 06:09
safe sql condiiton
conditions = ["user.login = ? and user.password = ?", params[:login], params[:password]]
@user = find(:conditions => conditions)
@anklos
anklos / gist:1042006
Created June 23, 2011 06:16
DB Performance improvement -- N+1
#if a Person that has_many Friends
friends = Person.find(:all, :conditions => 'friend_conditions', :include => :address)
#it wont load sql query again to search address
@friend_addresses = person.friends.collect {|friend| friend.address.street}
@anklos
anklos / gist:1075351
Created July 11, 2011 05:32
show git branch
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\w\$(parse_git_branch) $ "
@anklos
anklos / gist:1369168
Created November 16, 2011 03:35
find and replace strings
find ./ | xargs perl -pi -e 's/applicationX/applicationY/g'
@anklos
anklos / tasks.rb
Created June 11, 2012 23:33
simple callbacks
module Callbacks
def self.included(base)
base.class_eval do
extend ClassMethods
include InstanceMethods
end
end
module ClassMethods
def define_callback(callback_name)
#borrow from https://github.com/apotonick/hooks
#changes:
#remove block call support
#extend ActiveSupport::Concern into module to support nested module dependency
#add ability to pass multiple call_back methods params to a trigger
#for example: after_failed :job1, :job2..
require 'active_support/concern'
module Hooks
@anklos
anklos / .vimrc
Created June 27, 2013 06:08
.vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" github vim plugins