Skip to content

Instantly share code, notes, and snippets.

View karthiks's full-sized avatar
😄
Playing with GraphQL

Karthik Sirasanagandla karthiks

😄
Playing with GraphQL
View GitHub Profile
@karthiks
karthiks / address_spec.rb
Created October 21, 2011 17:27
leveraging Subject in RSpec - 4
describe Address do
describe "#validations" do
#The line below can be omited if we were to not use Factory and use Address.new and innermost 'describe' block is Address implicitly.
subject { Factory.build :address }
%w(:city :state :country).each do |attr|
it "must have a #{attr}" do
subject.send("#{attr}=",nil)
should_not be_valid #should is called on a subject by default. Thus this line uses implicit subject :address marked above
@karthiks
karthiks / address_spec.rb
Created October 21, 2011 17:36
The marriage of Shoulda with RSpec - Preview
describe Address do
describe "#validations" do
it { should validate_presence_of(:city) }
it { should validate_presence_of(:state) }
it { should validate_presence_of(:country) }
end
end
@karthiks
karthiks / class_method.rb
Created October 22, 2011 07:46
Ruby Quiz - object calling class method
#! ruby class_method.rb
class Test
def self.my_freakin_class_method
puts "In class method"
end
def my_freakin_instance_method
puts "In instance method"
end
@karthiks
karthiks / bash_aliases_jruby
Created October 27, 2011 03:11
Bash Aliases - JRuby
alias jcons='jruby -S script/console'
alias jspec='jruby -S script/spec'
alias jserv='jruby -S script/server'
@karthiks
karthiks / bash_aliases_ror
Created October 27, 2011 03:16
Bash Aliases - RoR
findrb() {
find . -iname "*.rb" -print0 | xargs -0 egrep -n --color "$@"
}
findyml() {
find . -iname "*.yml" -print0 | xargs -0 egrep -n --color "$@"
}
findrake() {
find . -iname "*.rake" -print0 | xargs -0 egrep -n --color "$@"
@karthiks
karthiks / bash_aliases_svn
Created October 27, 2011 03:19
Bash Aliases - SVN
alias svnpee="svn pe svn:externals ."
alias svnpei="svn pe svn:ignore ."
alias svnpge="svn pg svn:externals ."
alias svnpgi="svn pg svn:ignore ."
@karthiks
karthiks / bash_aliases_bash
Created October 27, 2011 03:24
Bash Aliases - Bash
alias ff="find . -name $* | grep -v .git"
alias cls='clear; reset'
alias ls='ls -G'
alias lstop='ls -Fhalts | head'
alias lstime='ls -Fhalts'
alias ll='ls -alG'
alias cp='cp -p'
alias findbrokenlinks='find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)'
alias clearlogs='rm -vrf log/*.log'
alias clearcov='rm -vrf coverage coverage.data'
@karthiks
karthiks / bash_aliases_tomcat
Created October 27, 2011 03:25
Bash Aliases - Tomcat
alias start_tomcat="env 'CATALINA_OPTS=-Xms1024m -Xmx1024m ${TOMCAT_OPTS}' ${TOMCAT_HOME}/bin/startup.sh"
alias stop_tomcat="${TOMCAT_HOME}/bin/shutdown.sh"
alias clean_tomcat="rm -rf ${TOMCAT_HOME}/work ${TOMCAT_HOME}/temp ${TOMCAT_HOME}/logs/*"
alias log="tail -f ${TOMCAT_HOME}/logs/*"
@karthiks
karthiks / pre-commit
Created October 27, 2011 03:28 — forked from holysugar/pre-commit
git pre-commit warning to trailing whitespaces
#!/bin/sh
function error() {
echo "'$1' has trailing spaces.\n" >&2
}
git diff --cached --name-only | (while read f; do
ERROR=0
if grep -n '[[:space:]]$' "$f" ; then
error $f
@karthiks
karthiks / environment.rb
Created November 25, 2011 03:26
Rails - NO pluralizing of table names
# config/environment.rb
# This will prevent Rails from pluralizing the table names
ActiveRecord::Base.pluralize_table_names = false