Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / pg_arrays.rb
Created February 23, 2016 16:45
PostgreSQL ARRAY
# migrate
add_column :doges, :friends, :text, array: true, default: []
# add an index
add_index :doges, :friends, using: :gin
# create a Doge
Doge.create(name: "Doge", friends: ["snoop", "snoopy"])
# any Doge contains a friend snoop
@teeparham
teeparham / gdcop.sh
Last active December 11, 2015 01:28
Inspect all ruby files in the current commit with rubocop
alias gdcop="git diff --name-only | grep '\.rb' | tr '\n' ' ' | sed 's/,$/\n/' | xargs rubocop"
# $ git status
# On branch master
# Your branch is up-to-date with 'origin/master'.
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: History.md
@teeparham
teeparham / f.rb
Created December 3, 2015 17:38
Functional Ruby
# define a closure x that exposes function y
x = -> {
y = -> { puts "y" };
{ y: y }
}
# invoke public function y on x
x.()[:y].()
# alternately
@teeparham
teeparham / CSS-only-Custom-Radio-Buttons.markdown
Last active August 29, 2015 14:20
CSS only Custom Radio Buttons
@teeparham
teeparham / key.asc
Last active July 25, 2016 18:43
PGP Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQENBFShyekBCACpo9IikwAsume4AUBmqvzPn1vUNjuoicGFwg5QiDJgPo6yLcLL
6XiMtkKxOxyWVsss4DAhvvT1AirfEvvB1WZSf6Fvy/SzZCkwyO3pZmuvb/pCqwGM
zLuafm/629IjIp5MtI2JvTpihs0KBVypv9GYzJqNO5+u407jwOqzsNU2idnNzwhz
gVv69aQXDQY6k5YGR0ZLSDZ7Imd7ERWOjJRsZ2uABfaB1tyMPfjBqaYYvi93RylM
f5BOZkCZPSXD6wtqjxd7qBRW6BrjpwGF94dXQBVF3+59UMQT8u6tvBZNNqlYEuN2
O4dbjx6FmRlGsLdsc/OFOcIlTHuiyke4kdCbABEBAAG0IVRlZSBQYXJoYW0gPHBh
cmhhbWV0ZXJAZ21haWwuY29tPokBOAQTAQIAIgUCVKHJ6QIbAwYLCQgHAwIGFQgC
@teeparham
teeparham / self.rb
Created February 9, 2015 18:10
Why you should use implicit self in ruby
class X
# implicit self
def get
value
end
# explicit self does not work when you call a private method
def get_self
self.value
end
@teeparham
teeparham / _example_output.txt
Last active August 29, 2015 14:07 — forked from tomafro/example output
Find ActiveRecord columns without indexes
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
@teeparham
teeparham / rdoc2md.rb
Last active November 7, 2023 00:47
Convert rdoc to markdown
require 'rdoc'
converter = RDoc::Markup::ToMarkdown.new
rdoc = File.read(ARGV[0] || 'README.rdoc')
puts converter.convert(rdoc)
# ruby rdoc2md.rb > README.md
# ruby rdoc2md.rb ABC.rdoc > abc.md
@teeparham
teeparham / cleanup_pg.sh
Last active January 2, 2016 17:39
Check postgres disk usage and vacuum
# TL/DR; run `vacuum full` on your postgres databases
# auto-vacuuming is on by default but the thresholds are fairly high
http://www.postgresql.org/docs/9.3/static/sql-vacuum.html
http://www.postgresql.org/docs/9.3/static/routine-vacuuming.html
# ---> autovacuum & track_counts are on by default. In postgresql.conf:
# track_counts = on
# autovacuum = on
@teeparham
teeparham / upgrade_nokogiri.sh
Created November 22, 2013 17:33
upgrade libxml2 and nokogiri, OSX
brew upgrade libxml2
brew cleanup
gem unin nokogiri
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2/ --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28/ --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include/ --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib/
bundle install nokogiri
# same as above, but readable:
# bundle config build.nokogiri