Skip to content

Instantly share code, notes, and snippets.

@tomholford
tomholford / classifier.rb
Created June 7, 2018 17:19
even / odd classifier using proc
f = proc do |p|
Hash.new.merge(
->{ p.odd? }.call => 'odd',
->{ p.even? }.call => 'even'
).fetch(true)
end
=> #<Proc:0x00007ff91188af38@(irb):1>
> f[1]
=> "odd"
@tomholford
tomholford / external_link_to.md
Last active October 19, 2019 02:52
Rails link_to helper for external links that open a new tab
@tomholford
tomholford / newface.sh
Created April 24, 2020 03:30
Get a new neural-net generated face jpg via This Person Does Not Exist
curl https://thispersondoesnotexist.com/image -o ~/$(date +%s).jpg
@tomholford
tomholford / README.md
Created May 15, 2020 01:42
Extend Rails application layouts

extends

An elegant way to nest Rails layouts.

Example Usage

# devise.html.erb
<%= extends :application do %>
 
@tomholford
tomholford / install_pg_gem.md
Last active April 18, 2024 20:37
Install postgresql gem `pg` on macOS

Installing pg gem on macOS

If you're trying to install the postgresql gem pg and it is failing with the following error message:

Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: ~/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.2.3/ext
~/.rbenv/versions/3.0.0/bin/ruby -I ~/.rbenv/versions/3.0.0/lib/ruby/3.0.0 -r ./siteconf20210125-97201-pycpo.rb extconf.rb