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 / 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:
@dpaluy
dpaluy / run.sh
Created May 29, 2023 17:00
Deploy Rails application to FlyIO
bundle add dockerfile-rails
bin/rails g dockerfile
brew add flyctl
flyctl launch
fly open
@dpaluy
dpaluy / example.rb
Last active May 7, 2023 23:57
Hierarchical logger
# Let's see the logger in practice. Imagine, we want to
# perform some actions on each project assigned to a
# specific user (whose ID is in params[:id]).
logger. log ("Find user") do
user = User.find (params [:id])
logger.log("Found #{user.email]")
logger.log("Iterate over projects") do
user.projects.find_each do |project|
logger.log(project.name) do
@dpaluy
dpaluy / rails-docker.sh
Created May 7, 2023 23:47
Rasil Dockerfile + FlyIO
bundle add dockerfile-rails
bin/rails g dockerfile
brew add flyctl
flyctl launch
fly open
@dpaluy
dpaluy / http_debug.rb
Created April 29, 2023 03:46
Debug Net HTTP
module Net::HTTPWithDebug
def initialize(*args)
super
set_debug_output(STDERR)
end
end
Net::HTTP.prepend(Net::HTTPWithDebug)