Skip to content

Instantly share code, notes, and snippets.

View jarednorman's full-sized avatar
☹️
not actually grumpy

Jared Norman jarednorman

☹️
not actually grumpy
View GitHub Profile
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)
@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.
@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 / 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

Keybase proof

I hereby claim:

  • I am jarednorman on github.
  • I am creepywizard (https://keybase.io/creepywizard) on keybase.
  • I have a public key ASDrvCBc_NJVOP2fq5tqB-E9BN7ZtNAlWHZy5gnMbqORsAo

To claim this, I am signing this object:

@jarednorman
jarednorman / webpack-rails-3.markdown
Created February 22, 2016 08:16
Webpack with Rails Part 3: Rake vs RSpec

Webpack with Rails Part 3: Rake vs RSpec

In part 2 we set up a Rake task to run webpack, ensuring that most deploy systems would build our entries for us.

I missed that we needed the webpack Rake task to be run before feature tests too. Without this, we need to run the task manually before running our test suite to avoid erroneous failures due to the assets not being up to date. Running Rake tasks from anywhere in your application in relatively easy, but we

@jarednorman
jarednorman / webpack-rails-2.markdown
Last active February 19, 2017 20:48
Webpack with Rails Part 2: Precompile Harder

Webpack with Rails Part 2: Precompile Harder

Note: This article is more generally about how to add dependencies to a Rake task, and why you might want to do that.

If you followed my previous article on webpack and Rails, you might have built yourself a trendy little React app. Then you tried to deploy it, and that didn't work, did it?

@jarednorman
jarednorman / webpack-rails-1.markdown
Last active May 13, 2020 18:24
Webpack with Rails Part 1

Webpack with Rails Part 1

I don't like Sprockets, but it's the easiest and best choice for lots of Ruby on Rails projects. When looking for a better way to manage my JavaScript assets and an improved developer story, my current tool of choice is webpack. While I wish Rails supported drop-in asset pipelines the way that Phoenix does, it's not hard to use webpack with Rails.

@jarednorman
jarednorman / teamocil-rails.markdown
Created February 22, 2016 08:08
Teamocil Makes Your Life Better: Rails Edition

Teamocil Makes Your Life Better: Rails Edition

I've never worked for a product company, and I have lots of personal projects. Because of this, I find myself jumping between different projects constantly. I manage this by keeping up to date Teamocil profiles for each project I work on, and using a development tools that fit completely inside of a tmux session (with the exception of my web browser, of course.)

There are lots of kinds of projects where your tools can't all run inside of

@jarednorman
jarednorman / setting-up-lua.markdown
Created February 22, 2016 08:07
Setting up a Lua/C Application

Setting up a Lua/C Application

My first exposure to Lua was in highschool. When I started seriously programming in tenth grade, it was in C (though I'd had some exposure to C++ as early as elementary school.) Being a nerdy teenager, all I wanted to do was make games, and I quickly discovered that doing everything in pure C had some downsides, and that embedding a scripting language within your application was commonplace for reasons that I have no intention of explaining here. I assume you already want to embed Lua in your C application, else why would you be reading this.