Skip to content

Instantly share code, notes, and snippets.

View Merovex's full-sized avatar

Ben W Merovex

  • Gainfully Employed
  • In a hidden bunker under a non-descript building
  • 20:17 (UTC -05:00)
View GitHub Profile
@Merovex
Merovex / censorable.rb
Created November 11, 2024 15:14
A simple Rails Concern to add sensoring to content (remove profanity)
PROFANITY_LIST = [
"aclit", "adick", "aids", "alabama porch monkey", "anal intruder",
"anal invader", "analicker", "anus", "4r5e", "5h1t", "5hit", "a55",
"anal", "ar5e", "arrse", "arse", "ass", "as$", "ass bandit", "ass clown",
"ass face", "ass fucker", "ass hole", "ass load", "ass much", "ass out",
"ass packer", "ass reamer", "ass whacker", "ass wipe", "assbandit",
"assclown", "asscrack", "assed out", "assface", "assfucker", "asshole",
"asslicker", "assload", "assmunch", "assout", "asspacker", "assreamer",
"asswhacker", "asswipe", "baby batter", "babybatter", "ball breaker",
"ball buster", "baller", "balling", "bat shit", "batshit", "bearded clam",
@Merovex
Merovex / encrypt_to_slug.rb
Created August 9, 2024 09:45
Takes a number (like an id) and one-way encrypts to a slug (needs to be stored in database)
require 'digest'
SLUG_DEFAULT = 4
SAFESTRING = "BDFGHJKLMNPQRTVWXYZbdfghjkmnpqrtvwxyz26789".freeze
def encrypt_to_slug(number, size: SLUG_DEFAULT, alphabet: SAFESTRING)
non_numeric_set = alphabet.gsub(/[0-9]/, '') # Characters without digits
# Step 1: Hash the number (using SHA256)
hash = Digest::SHA256.digest(number.to_s)
@Merovex
Merovex / infinite-scroll-example.md
Last active August 6, 2024 11:11
Rails/Stimulus Infinite Scroll with Pagy circa Summer 2024

In the Controller:

@pagy, @activities = pagy(Activity.order(created_at: :desc).includes(:user, :trackable), limit: 4)
respond_to do |format|
  format.html
  format.json { render json: { entries: render_to_string(partial: "activities/activity", collection: @activities, formats: [ :html ]), pagination: view_context.pagy_nav(@pagy) } }
end
[data-color='blue'][data-color-scheme='light'] {
--primary: #445E91;
--surface-tint: #445E91;
--on-primary: #FFFFFF;
--primary-container: #D8E2FF;
--on-primary-container: #001A42;
--secondary: #575E71;
--on-secondary: #FFFFFF;
--secondary-container: #DBE2F9;
--on-secondary-container: #141B2C;
@Merovex
Merovex / send_to_kindle.rb
Created April 15, 2024 11:25 — forked from wndxlori/send_to_kindle.rb
When you have a whole LOT of ebooks to send to your Kindle
#!/Usr/bin/env ruby
require 'mail'
require 'fileutils'
# Check if a command line argument is provided
if ARGV.length < 1
puts "Usage: ruby send_to-kindle.rb <directory containing epub files>"
exit 1
@Merovex
Merovex / slug.rb
Created August 21, 2022 14:58
Create random slug
# frozen_string_literal: true
module Slug
extend ActiveSupport::Concern
def self.included(base)
base.extend ClassMethods
base.before_create :set_slug
end
def to_param
zucchini zoology zoologist zoo zone zombie zither zipper zinc ziggurat zero zephyr zen zebrafish zebra zampone yurt yoyo youth yourself youngster young yolk yoke yogurt yoga yin yew yesterday yellowjacket yellow yeast year yawl yarn yarmulke yard yang yam yak yahoo yacht xylophone wrong writing writer wrist wrinkle wriggler wrestler wrench wren wrecker wreck wrapping wrapper wraparound wrap wound worth worshiper worship worry worm world workshop workplace workout working workhorse workforce worker workbench work wording word woolens wool woodwind woodshed woodland woodchuck wood wont wonder wombat woman wolf wok witness withdrawal witchhunt witch wit wisteria wish wiseguy wisdom wiring wiretap wire winter winner wink wingtip wingman wing winery wine windshield windscreen window windchime windage wind win willow willingness will wildlife wildflower wilderness wildebeest wild wife width widow widget wick whorl wholesaler wholesale whole white whistle whisper whiskey whisker whirlwind whirlpool whip whey whelp w
@Merovex
Merovex / Gemfile
Created January 24, 2021 04:02 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@Merovex
Merovex / Gemfile
Created January 24, 2021 04:02 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
CREATE TABLE `states` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;