Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@Stylesproline
Stylesproline / README.md
Created December 9, 2021 07:53
Awesome-Selfhosted
@KonnorRogers
KonnorRogers / flash_component.rb
Last active March 31, 2023 19:20
A view component for using Shoelace alerts
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",
@fuksito
fuksito / callable_service.rb
Created August 10, 2021 07:34
CallableService Concern for Rails
# 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:
@AndreaBarghigiani
AndreaBarghigiani / table_component.html.erb
Created July 30, 2021 06:04
Simple Table with ViewComponents
<table class="<%= classes %>">
<thead class='bg-gray-300 font-medium'>
<% head %>
</thead>
<tbody>
<% body %>
</tbody>
</table>
@dalezak
dalezak / cacheable.rb
Last active March 14, 2023 21:39
Rails Cacheable Concern
# 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
@existentialmutt
existentialmutt / modal_component.html.erb
Last active March 31, 2023 19:22
Modal ViewComponent
<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>
@amirrajan
amirrajan / main.rb
Last active March 5, 2025 22:40
Gauntlet written in DragonRuby Game Toolkit
class Game
attr_gtk
def tick
defaults
render
input
calc
end
@fractaledmind
fractaledmind / jobbable_concern.rb
Created March 1, 2021 09:09
This concern allows model instances to run async jobs that depend on them. Calling #async_method_name will trigger the MethodNameJob
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)
#! /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
@stevecrozz
stevecrozz / r-png.rb
Created February 23, 2021 23:24
Ruby PNG Reader
require 'zlib'
module RImage
class InvalidSignature < Exception
end
class InvalidChecksum < Exception
end
class RImage