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 / fizzbuzz.markdown
Created February 22, 2016 07:59
Fizzbuzz in Elixir

Fizzbuzz in Elixir

Elixir is a beautiful language. Among its strength is its powerful pattern matching system which allows one to write very declarative, elegant code. FizzBuzz is a trivial problem often presented to new programmers or interviewees to determine baseline programming ability. Here is a solution Elixir:

defmodule FizzBuzz do
@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 / 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 / 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 / react-phantomjs.markdown
Created February 22, 2016 08:05
Running React on PhantomJS

Running React on PhantomJS

I ran into an issue getting a simple Capybara/Poltergeist feature test suite running against a site that used React.js. The following failure was bubbling up to RSpec.

Failures: