This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlashComponent < ViewComponent::Base | |
extend Dry::Initializer | |
# notice, warning, and error can be set by default in redirect_to. | |
# For additional flashes, you must do flash[:type] = "message" | |
ICONS = { | |
primary: "info-circle", | |
success: "check2-circle", | |
info: "gear", | |
warning: "exclamation-triangle", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Forms::BaseForm | |
include ActiveModel::Validations | |
def initialize(attrs={}) | |
attrs ||= {} | |
attrs.each do |k,v| | |
self.send("#{k}=", v) ### Use send so that it checks that attr_accessor has already defined the method so its a valid attribute | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usually service classes have only one purpose and thus should have only one public method that triggers action | |
# This module simplifies the common approach: | |
# | |
# SomeService.new(a, b, c).call | |
# | |
# To: | |
# | |
# SomeService.call(a, b, c) | |
# | |
# Requirements for class: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="<%= classes %>"> | |
<thead class='bg-gray-300 font-medium'> | |
<% head %> | |
</thead> | |
<tbody> | |
<% body %> | |
</tbody> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails concern that tracks and purges cache keys to avoid using Rails.cache.delete_matched since its very costly on Redis. | |
# | |
# @countries = Country.query_cached('countries:index', "limit:#{@limit}", "offset:#{@offset}") do | |
# query.limit(@limit).offset(@offset).all.to_a | |
# end | |
module Cacheable | |
extend ActiveSupport::Concern | |
included do | |
before_save :purge_cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="modal fade" id="<%= dom_id %>" role="dialog" tabindex="-1"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<% if header %> | |
<div class="modal-header"> | |
<%= header %> | |
<%- if header_close_btn %> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
<i class="fa fa-times-circle"></i> | |
</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game | |
attr_gtk | |
def tick | |
defaults | |
render | |
input | |
calc | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jobbable | |
extend ActiveSupport::Concern | |
# This concern allows model instances to run async jobs that depend on them. | |
# Calling #async_method_name will trigger the MethodNameJob | |
PREFIX = "async_" | |
included do | |
def method_missing(method_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# adapted from https://gist.github.com/gabehollombe/064a90351c204381832d749ca6b569e0 | |
# but it actually edits a file! | |
# `editor.rb [filename]` | |
# arrows, letters, backspace... Just the basics. | |
require 'curses' | |
include Curses | |
include Curses::Key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="field" data-controller="toggle-password-visibility" data-toggle-password-visibility-visible-icon-class="mdi-eye-off"> | |
<%= form.label :password, class: 'label'%> | |
<div class="control"> | |
<div class="field has-addons has-addons-right"> | |
<div class="control is-clearfix has-icons-left has-icons-right"> | |
<span class="icon is-left"> | |
<i class="mdi mdi-onepassword mdi-24px"></i> | |
</span> | |
<%= form.password_field :password, class: ['input', { "is-danger": sign_in.errors.key?(:password) }], data: { 'toggle-password-visibility-target': 'password' }, required: true %> | |
<% if sign_in.errors.key?(:password) %> |