Skip to content

Instantly share code, notes, and snippets.

View ispyropoulos's full-sized avatar

Ilias Spyropoulos ispyropoulos

View GitHub Profile
@justalever
justalever / validate_array_datatype.rb
Created January 3, 2020 03:08
Validate an array data type in Ruby on Rails using a custom validator - PostGresQL allows arrays as a DB type.
# Define the validator
# app/validators/array_validator.rb
class ArrayValidator < ActiveModel::EachValidator
def validate_each(record, attribute, values)
Array(values).each do |value|
options.each do |key, args|
validator_options = { attributes: attribute }
validator_options.merge!(args) if args.is_a?(Hash)
@thadeu
thadeu / README.md
Created September 25, 2019 21:50
Active Storage Remove Attachments

ActiveStorageRemove

Do you need remove files in the active_storage rails?

Use this files :)

require 'English'
namespace :db do # rubocop:disable Metrics/BlockLength
task :prevent_disparate_pg_dump_versions => :environment do
allowed_pg_dump_version = '9.6.10'.freeze
`pg_dump --version`
pg_dump_exit_status = $CHILD_STATUS.exitstatus
locally_installed_version = `pg_dump --version`.chomp[/(\d.*)/,1] rescue nil
@stevenharman
stevenharman / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Last active May 23, 2024 04:43
Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

@dansteele
dansteele / create_review_app_subdomain.rake
Last active September 15, 2022 23:45
Use a sub-subdomain on Heroku review apps with DNSimple. Run this task from your app.json in your postdeploy script.
namespace :staging do
desc 'create subdomain DNS record for Heroku review app'
task :publish_dns do
require 'dnsimple'
require 'platform-api'
STAGING_DOMAIN = 'mystagingdomain.com'.freeze
DNSIMPLE_ACCOUNT_ID = .freeze
heroku_app_name = ENV['HEROKU_APP_NAME']
subdomain = heroku_app_name.match(/.*(pr-\d+)/).captures.first
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active July 25, 2024 20:36
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@danieleggert
danieleggert / GPG and git on macOS.md
Last active July 21, 2024 18:21
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@dstagner
dstagner / gist:193207fed46acf5b5bae
Last active September 23, 2023 18:19
Ruby ISO8601 time in milliseconds

So you want to generate ISO8601 formatted timestamps in Ruby, but need resolution finer than a second?

First, make sure to require 'time' in order to get ISO8601 formatting. But that gets you this:

2.1.0 :001 > require 'time'
 => true 
2.1.0 :002 > Time.now.utc.iso8601
 => "2015-11-12T04:46:43Z" 
@TylerRick
TylerRick / action_mailer-dont_log_attachments.rb
Last active May 13, 2020 12:21
Override the version from the actionmailer gem in order to not log attachments.
ActionMailer::Base.class_eval do
class << self
protected
# Override the version from the actionmailer gem in order to not log attachments.
#
# Note: This depends on the patch from https://github.com/mikel/mail/pull/858, which adds
# parts.inspect_structure and fixes an issue with mail.without_attachments!
#