Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@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
@songjiz
songjiz / _form.html.erb
Last active August 8, 2023 10:05
Toggle password visibility with stimulus controller
<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) %>
@nikhgupta
nikhgupta / application_presenter.rb
Last active March 14, 2023 21:17
Rails PORO Decorator - Supports ActiveAdmin
class ApplicationPresenter
attr_reader :model
delegate_missing_to :@model
delegate :helpers, to: 'ActionController::Base'
delegate :url_helpers, to: 'Rails.application.routes'
delegate :to_param, :to_json, :to_query, :to_yaml, :to_enum, to: :@model
delegate :model_name, :model_name_const, :model_name_underscore, to: :class
def initialize(model)
@BrianSigafoos
BrianSigafoos / README.md
Last active February 23, 2023 19:58
Rails module to manage Stripe subscriptions from Stripe Checkout

Stripe CLI

  • Install the Stripe CLI with: brew install stripe/stripe-cli/stripe
  • Login to our Stripe account: stripe login
  • Listen for Stripe webhooks using Latest API version and forward to:
    • yarn stripe:listen, which does:
    • stripe listen --latest --forward-to http://localhost:3000/webhook_events/stripe
  • Replay events locally with stripe trigger <event type>:
  • stripe trigger checkout.session.completed
@IanVaughan
IanVaughan / unused_routes.rb
Created August 27, 2020 11:15
Find unused rails routes
# frozen_string_literal: true
Rails.application.eager_load!
unused_routes = {}
# Iterating over all non-empty routes from RouteSet
Rails.application.routes.routes.map(&:requirements).reject(&:empty?).each do |route|
name = route[:controller].camelcase
next if name.start_with?('Rails')
@pashagray
pashagray / pubsub.rb
Created July 16, 2020 06:31
Simple example of pubsub pattern
module Publisher
def subscribe(subscribers)
@subscribers ||= [] # if @subscribers is nil, we initialize it as empty array, else we do nothing
@subscribers += subscribers
end
def broadcast(event, *payload)
@subscribers ||= [] # @subscribers is nil, we can't do each on it
@subscribers.each do |subscriber|
# If event is :item_added occured with payload item itself
@tangentus
tangentus / some_view.html.erb
Last active March 31, 2023 19:26
A PoC of a Stimulus ViewComponent
<%= render StimulusComponent.new controller: "test" do |component| %>
<button <%= component.action :click, :test, :test %>>Hello, Stimulus Component!</button>
<% end %>