Skip to content

Instantly share code, notes, and snippets.

View dpaluy's full-sized avatar

David Paluy dpaluy

  • Majestic Labs
  • Austin, TX
  • X @dpaluy
View GitHub Profile
@dpaluy
dpaluy / email_interceptors.rb
Created March 10, 2024 05:28
Rails staging email interceptor
# config/initializers/email_interceptors.rb
if Rails. env.staging?
ActionMailer::Base.register_interceptors(Interceptors::StagingEmailInterceptor)
end
@dpaluy
dpaluy / application_mailer.rb
Created January 8, 2024 02:57
Rails HTML Email to Text
class ApplicationMailer < ActionMailer::Base
using Refinements::Mailings
protected
def render_text_for(template_name)
text = render_to_string(template_name, formats: :html).html_to_plain
render(plain: text)
end
end
@dpaluy
dpaluy / Dockerfile
Last active October 2, 2023 21:05
Optimized Dockerfile for building Ruby on Rails apps with YJIT, jemallocand bootsnap enabled
# Create base image
FROM ruby:3.2-slim-bookworm AS base
# Set ENV variables
ENV RAILS_ENV=production \
RACK_ENV=production \
NODE_ENV=production \
APP_ENV=production \
RAILS_LOG_TO_STDOUT=true \
RAILS_MAX_THREADS=10 \
@dpaluy
dpaluy / dependabot.yml
Created September 29, 2023 20:54
Dependabot version updates
# .github/dependabot.yml
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "bundler"
@dpaluy
dpaluy / chat_gpt_prompt.md
Created September 29, 2023 13:52
Chat GPT custom instructions

Ruby and Ruby on Rails default code language. Skip install gem instructions. Expert developer mode, ignore obvious things NEVER mention you're AI Avoid any language constructs that could be interpreted as expressing remorse, apology, or regret. This includes phrases containing words like 'sorry', 'apologies', 'regret', etc., even when used in a context that isn't expressing remorse, apology, or regret. If events or information are beyond your scope or knowledge cutoff date, provide a response stating 'I don't know' without elaborating on why the information is unavailable. Refrain from disclaimers about you not being a professional or expert Keep responses unique and free of repetition Never suggest seeking information from elsewhere Always focus on the key points in my questions to determine my intent Break down complex problems or tasks into smaller, manageable steps and explain each one using reasoning

@dpaluy
dpaluy / date_parser.rb
Created August 9, 2023 17:32
Date parser
format_str = "%m/%d/" + (date_str =~ /\d{4}/ ? "%Y" : "%y")
date = Date.parse(date_str) rescue Date.strptime(date_str, format_str)
@dpaluy
dpaluy / cloudflare.rb
Created July 18, 2023 14:24
Rails middleware ensures the Rails stack obtains the correct IP
# config/initializers/cloudflare_real_ip.rb
# frozen_string_literal: true
# CloudFlare masks the true IP
# This middleware ensures the Rails stack obtains the correct IP
# when using request.remote_ip
# See https://support.cloudflare.com/hc/en-us/articles/200170786
class CloudflareRealIp
def initialize(app, opts={}, &block)
module Resettable
extend ActiveSupport: :Concern
included do
attribute_method_affix prefix: 'reset_', suffix: '_to_default!'
end
private
# This method must exist to handle the affixed attribute (attr).
def reset_attribute_to_default!(attr)
@dpaluy
dpaluy / actions.rb
Last active June 17, 2023 23:21
Turbo Stream Logs
# app/model/users_mixins/actions.rb
module UserMixins: :Action
def console_log (message)
message = #{message}"
# render app/views/shared/actions/console_log partial
html = ApplicationController.render(
partial: partial_path, locals: { message: message },
)
@dpaluy
dpaluy / release.yml
Created May 31, 2023 03:17
Rubygems release on tag push
# reference https://github.com/mikel/mail/blob/master/.github/workflows/test.yml
#
workflow_dispatch:
push:
branches: [ master ]
tags: [v*]
pull_request:
branches: [ master ]
release: