Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Marcus Shepherd marcusshepp

🎯
Focusing
View GitHub Profile
View rails_queries.rb
# rails 2.3.5
p = Promotion.find(:first, :conditions => ["subdomain = ?", "foobar"])
# to find based on multiple conditions based on multiple associations
User.find(:all, :include => [:contact, :promotion], :conditions => ['contacts.email = ? and promotions.id = ?', 'marcuss@hesonline.com', 22])
# to find last record in old rails apps, rails 2
p = Promotion.find(:all, :order => "id desc", :limit => 1) # newest first
# and in ascending order
p = Promotion.find(:all, :order => "id asc", :limit => 1) # oldest first
@marcusshepp
marcusshepp / ruby_env.sh
Last active Sep 8, 2017
Notes on Ruby Environment
View ruby_env.sh
# to install diff Ruby verison
rvm install ruby-1.8.7-head
# to force RVM to use a diff Ruby version by default
rvm --default use 1.8.7
# to create a new rvm enviornment
rvm use 1.8.7@foo --create
# to install the package that will interate over
@marcusshepp
marcusshepp / reset-file.sh
Created Aug 29, 2017
reset file back to commit hash
View reset-file.sh
git checkout c5f567 -- file1/to/restore file2/to/restore
@marcusshepp
marcusshepp / migrations.sh
Last active Aug 24, 2017
running migrations
View migrations.sh
# rails 3.2.19
ruby script/generate migration AddUserOptedIntoLeaderboard
rake db:migrate:up VERSION=20160617125737
# rails -v 1.2.3
rake db:migrate VERSION=213
@marcusshepp
marcusshepp / f-br.sh
Created Aug 24, 2017
finding branches
View f-br.sh
# to fetch (obtain references to) all origin branches
git fetch origin
# to see all branches
git branch -a
git branch -a | grep foo
@marcusshepp
marcusshepp / puts.rb
Created Aug 23, 2017
puts not working in rails project
View puts.rb
# puts string was not working, these are a few work arounds
def puts(s)
Rails.logger.info(s)
end
File.open("debug.txt", ""){|f|f.write('foo')}
raise "foo"
View show_untracked_files.sh
git ls-files --others --exclude-standard
@marcusshepp
marcusshepp / files-changed.sh
Created Aug 21, 2017
git diff list only names of files changed
View files-changed.sh
git diff --name-only
@marcusshepp
marcusshepp / no-whitespace.sh
Last active Aug 21, 2017
git diff without white space
View no-whitespace.sh
git diff -w # ignores whitespace differences
# note that this will see no difference in "asc" and "a s c"
git diff --ignore-space-at-eol # ignores all space at the end of line
# this is most likely what you want.
# these options also work with git show
git show 2ert4d9 --ignore-all-space
git show 2ert4d9 --ignore-space-change
@marcusshepp
marcusshepp / compare.sh
Last active Aug 9, 2017
compare local branch git log to remote branch
View compare.sh
git log @{u}..
# @{u} is a shortcut to the upstream branch that this current branch is tracking.
# .. specifies a range of commits.
# same as saying git log @{u}..HEAD
# comparing where HEAD is on this branch to where HEAD is on the remote tracked branch.s
# https://stackoverflow.com/questions/19474577/what-does-the-argument-u-mean-in-git/19474730#19474730