Skip to content

Instantly share code, notes, and snippets.

View jarednorman's full-sized avatar
🏄‍♂️
wish I was surfing

Jared Norman jarednorman

🏄‍♂️
wish I was surfing
View GitHub Profile
@jarednorman
jarednorman / fzfgem.vim
Last active May 6, 2018 21:27
Search for a gem in the current project, and then search for (and open) a file within it (from Vim, requires fzf.vim)
" Gem search
function! GemSearch()
call fzf#run(fzf#wrap({'source': "bundle list | sed '1d;$d' | cut -d ' ' -f 4", 'sink': {gem -> GemFileSearch(gem)}}))
endfunction
function! GemFileSearch(gem)
let gemdir = substitute(system("bundle show " . a:gem), '\n\+$', '', '')
call fzf#run(fzf#wrap({'source': 'rg --files ' . gemdir . ' --color never | sed -e "s#^' . gemdir . '/##"', 'dir': gemdir}))
endfunction
@jarednorman
jarednorman / player.rb
Created July 1, 2018 00:39
The Elo handling from PorkChop, without the other stuff in the model. (Original source: https://github.com/PorkChopClub/porkchop/blob/master/app/models/player.rb)
class Player < ActiveRecord::Base
BASE_ELO = 1000
has_many :elo_ratings
after_save :record_rating
attr_writer :elo
def elo
elo_ratings.most_recent_rating || BASE_ELO
end
@jarednorman
jarednorman / README.md
Created December 5, 2021 21:11
Using Shrine with Solidus
  1. First, configure Shrine. I'll leave this exercise to the reader as it's very dependent on how you'll be storing your files (on a server, on S3, etc.)

  2. Define an alternate attachment module (instead of the ActiveStorage or Paperclip one):

    module ShrineImageAttachment
      extend ActiveSupport::Concern
    
      included do
        # FIXME: Use whatever store you have defined that you want to use for product images. To avoid caching issues, I recommend using some kind of public store.
module OpenGraph
class << self
def fetch_data(url)
html = Nokogiri::HTML(body(url))
{
title: find_meta("og:title", html) || html.title.presence,
description: find_meta("og:description", html),
image: find_meta("og:image", html),
site_name: find_meta("og:site_name", html)