Skip to content

Instantly share code, notes, and snippets.

View gamecreature's full-sized avatar
🎢

Rick Blommers gamecreature

🎢
View GitHub Profile
@gamecreature
gamecreature / Capfile
Last active September 28, 2021 12:24
A snippet for deploying to multiple servers at once
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# -8<-------8<-------8<-------8<-------8<-------8<------
@gamecreature
gamecreature / turbo_stream_helpers_concern.rb
Created August 6, 2021 14:49
Chain turbo-stream responses from controllers (and auto append flash messages)
#
# What does this do:
#
# Normal: (Basic library usage, without this helper)
# --------------------------------------------------
# render turbo_stream: [
# turbo_stream.replace(:flash, partial: 'shared/flash'),
# turbo_stream.replace(:object, partial: 'partial/name', locals: { object: object } )
# turbo_stream.replace(:object2, partial: 'partial/name'2, locals: { object2: object2 } )
# ]
# Use it by including it directly in the unix-ruby script
def run_script_once
emails = %w[info@example.com]
path = "#{$0}.pid"
if File.exists?(path)
pid = IO.read(path).to_i
begin
if Process.getpgid(pid)
@gamecreature
gamecreature / schema_validations.rb
Last active November 3, 2020 11:00
Schema_validations concern for rails, replacement for the schema_validations gem (Compatible with Rails 6.1)
# Schema Validations Concern - simple basic replacement for https://github.com/SchemaPlus/schema_validations
#
# Warning, uniqueness validators are NOT Added
#
# Constraints:
# - null: false => validates ... presence: true
# - limit: 100 => validates ... length: { maximum: 100 }
#
# Data types:
# - :boolean => :validates ... inclusion: { in: [true, false] }
@gamecreature
gamecreature / keybase.md
Created January 19, 2020 15:27
Keybase

Keybase proof

I hereby claim:

  • I am gamecreature on github.
  • I am gamecreature (https://keybase.io/gamecreature) on keybase.
  • I have a public key ASBZnzJJo6X4cy5Ftg2Hq68ULyE-TxgkagXk9z1fw5HSFAo

To claim this, I am signing this object:

@gamecreature
gamecreature / pundit_extension_helper.rb
Created May 21, 2019 10:23
Pundit Helper to invoke different resolve method in Pundit scope class
module PunditExtensionHelper
# this method is the same as the pundit_scope method
# the difference is, it doesn't invoke the resolve method
def policy_scoper(scope_in, method = :resolve)
scope = scope_in.is_a?(Array) ? scope_in.last : scope_in
policy_scope_class = Pundit::PolicyFinder.new(scope).scope!
return unless policy_scope_class
begin
@gamecreature
gamecreature / find_email_addresses.rb
Created May 31, 2016 08:32
Find emailadresses in an Maildir directory tree and send them to STDOUT
#!/usr/bin/env ruby
#
# EMAIL extractor from Maildir (mbox files)
#
# extracts all emailadresses from a IMAP directory tree
chars = %w{ | / - \\ }
def find_email_addresses(base_folder)