Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Bartlett cbartlett

View GitHub Profile
View gist:513fb2f80e5668b7da0c3b91bdea17b9
git log --author="Colin" --no-merges --pretty=format:"%Cgreen%cs%C(cyan) %h%Creset %s" --after="2021-08-01"
@cbartlett
cbartlett / exception_tree.rb
Created Oct 7, 2019
Prints out a list of the all the ruby exceptions in your app
View exception_tree.rb
# thanks to http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy/
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
end
@cbartlett
cbartlett / app.json
Created Feb 28, 2019
dumping a database in review apps
View app.json
{
"name": "some_app_name",
"scripts": {
"postdeploy": "[ \"$RAILS_ENV\" != \"TEST\" ] && pg_dump $PRODUCTION_DATABASE_URL | psql $DATABASE_URL && bundle exec rake db:migrate"
},
"env": {
"PRODUCTION_DATABASE_URL": { "required": true },
"SOME_VAR": { "required": true },
"RELEASE_STAGE": "review",
},
View gist:505152c4b06aa309d74b7c3902be72a4
[aria-label^="Suggested reply"] {
display: none;
}
@cbartlett
cbartlett / remove.sh
Created Oct 20, 2018
Remove unused local git branches
View remove.sh
git branch --merged master | grep -v ^\* | xargs git branch -d
@cbartlett
cbartlett / upsert.rb
Created Sep 2, 2018
ActiveRecord upsert extension
View upsert.rb
module Upsert
extend ActiveSupport::Concern
class_methods do
def upsert(key, attributes)
begin
create(attributes)
rescue ActiveRecord::RecordNotUnique => e
where(key => attributes[key]).
first.tap do |obj|
View gist:1b9042fcb93aecd187915d59e6b07462
.card-short-id {
display: inline !important;
padding: 0 4px;
margin-right: 4px;
background-color: #E2E4E6 ;
color: #929292 ;
}
@cbartlett
cbartlett / convert_repo.sh
Created Jul 8, 2018
Convert Ruby hash syntax
View convert_repo.sh
find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;
@cbartlett
cbartlett / pr.md
Created Apr 29, 2017 — forked from piscisaureus/pr.md
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@cbartlett
cbartlett / pr.md
Created Apr 29, 2017 — forked from piscisaureus/pr.md
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: