Skip to content

Instantly share code, notes, and snippets.

View Odaeus's full-sized avatar

Andrew France Odaeus

View GitHub Profile
@Odaeus
Odaeus / application_controller.rb
Last active June 15, 2021 09:34
Alternative to Rails' sharing of instance variables between controller and views.
class ApplicationController < ActionController::Base
# Creates an accessor which is exposed to the view
def self.view_accessor(*names)
attr_accessor *names
helper_method *names
end
end
@Odaeus
Odaeus / 1 original_webhook_handler.ex
Last active April 15, 2021 15:32
Elixir module refactoring pattern
# Original
defmodule Service.WebhookHandler do
def register_webhook(name) do
case Registry.register(webhook_id(name), __MODULE__) do
{:ok, _pid} -> :ok
error -> error
end
end
@Odaeus
Odaeus / application_controller.rb
Last active October 11, 2019 23:55
Simple Presenter Pattern
class ApplicationController < ActionController::Base
# ...
concerning :Presenters do
included do
helper_method :present
end
def present(record_or_array, klass)
if record_or_array.respond_to?(:map)
@Odaeus
Odaeus / fill.svg
Last active January 21, 2019 14:06
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
env:
browser: true
es6: true
extends: 'eslint:recommended'
parserOptions:
sourceType: module
rules:
indent:
- error
- 4
@import "globals";
custom-element {
--custom-var: $primaryColour;
}
require "yaks"
Book = Struct.new(:title, :author)
book = Book.new("Leviathan Wakes", "James A Corey")
class BookMapper < Yaks::Mapper
type "book"
attributes :title
require "yaks"
Book = Struct.new(:title, :author)
book = Book.new("Leviathan Wakes", "James A Corey")
class BookMapper < Yaks::Mapper
type :book
attributes :title
@Odaeus
Odaeus / packages.md
Last active December 15, 2015 10:19
Packages for running Ruby on Rails on Ubuntu

Minimal for gem compilation

  • build-essential

Common for gems

  • libxml2
  • libxml2-dev (for nokogiri)

Ruby compilation

  • libreadline6
@Odaeus
Odaeus / a_rspec_output.txt
Created March 12, 2013 15:40
Discourse craziness
44) User previous_visit_at first time another call right after still has no value
Failure/Error: let(:user) { Fabricate(:user) }
NoMethodError:
undefined method `first' for nil:NilClass
# ./lib/pretty_text.rb:122:in `block in markdown'
# <internal:prelude>:10:in `synchronize'
# ./lib/pretty_text.rb:119:in `markdown'
# ./lib/pretty_text.rb:175:in `cook'
# ./app/models/user.rb:424:in `cook'
# /home/andrew/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:429:in `_run__4302418198468556500__save__3765986560144774874__callbacks'