Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@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 %>
require "open-uri"
module Imports
class PageCrawler
attr_reader :current_page, :pages, :crawled
attr_accessor :follow_patterns, :ignore_patterns
def initialize(start_url, max_depth: 3, max_pages: 1000)
@max_depth, @max_pages = max_depth, max_pages
@sakkas-zendesk
sakkas-zendesk / README.md
Last active June 28, 2023 20:24
Manage your symlinks in your dotfiles or anywhere [Ruby]

How to

You might need to modify default path for your symlink sources and destinations as per your preferences.

# Where we keep the original files which we track in Git
SRC_BASE = HOME + "/.dotfiles/symlinker/files/"
# Where we place them by default, if there is no override
DST_BASE = HOME + "/"
@muhammadyana
muhammadyana / rails-softdeleteable.rb
Created May 9, 2020 07:25
Ruby on Rails Soft Deleteable
module SoftDeletable
extend ActiveSupport::Concern
included do
scope :deleted, ->{ where.not(deleted_at: nil) }
scope :without_deleted, ->{ where(deleted_at: nil) }
scope :with_deleted, ->{ unscope(where: :deleted_at) }
default_scope { without_deleted }
end
@dhh
dhh / tracker_blocking.rb
Last active June 30, 2024 14:35
Current list of spy pixels named'n'shamed in HEY, as of April 23, 2020
module Entry::TrackerBlocking
extend ActiveSupport::Concern
included do
has_many :blocked_trackers
end
email_service_blockers = {
"ActiveCampaign" => /lt\.php(.*)?l\=open/,
"AWeber" => "openrate.aweber.com",