Skip to content

Instantly share code, notes, and snippets.

@carlosramireziii
carlosramireziii / attached_validator.rb
Last active April 10, 2024 11:11
A validator and RSpec matcher for requiring an attachment using Active Storage
class AttachedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :attached, options) unless value.attached?
end
end
@colinpetruno
colinpetruno / backfill_active_storage.rake
Last active September 28, 2018 19:20
Postgres Paperclip to ActiveStorage Rake Task
namespace :backfill do
task active_storage: :environment do
require 'open-uri'
def key(instance, attachment)
SecureRandom.uuid
# Alternatively:
# instance.send("#{attachment}_file_name")
end
@dommmel
dommmel / blob_authenticatable.rb
Last active July 12, 2023 01:01
Devise authentication for Rails' ActiveStorage
# Rails controller concern to enable Devise authentication for ActiveStorage.
# Put it in +app/controllers/concerns/blob_authenticatable.rb+ and include it when overriding
# +ActiveStorage::BlobsController+ and +ActiveStorage::RepresentationsController+.
#
# Optional configuration:
#
# Set the model that includes devise's database_authenticatable.
# Defaults to Devise.default_scope which defaults to the first
# devise role declared in your routes (usually :user)
#
@william8th
william8th / .tmux.conf
Last active June 18, 2025 17:58
Tmux open new pane in same directory
# Set the control character to Ctrl+Spacebar (instead of Ctrl+B)
set -g prefix C-space
unbind-key C-b
bind-key C-space send-prefix
# Set new panes to open in current directory
bind c new-window -c "#{pane_current_path}"
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
@hauleth
hauleth / pg_graph.sh
Created April 17, 2018 17:22
Script to generate DOT graph of dependencies between tables in PostgreSQL
#!/bin/sh
psql -qX "$@" <<EOF
\t on
\timing off
\echo 'Digraph F{'
\echo 'ranksep=1.0; size="18.5, 15.5"; rankdir=LR;'
SELECT
@palkan
palkan / factory_doctor.rb
Created March 27, 2017 15:42
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@phansch
phansch / yardoc_cheatsheet.md
Last active June 15, 2025 19:55 — forked from chetan/yardoc_cheatsheet.md
Improved YARD cheatsheet
@spalladino
spalladino / Makefile
Created November 23, 2016 15:40
Proof of concept of Ruby extension written in Crystal
testruby.bundle: testruby.cr
crystal testruby.cr --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o testruby.bundle
irb: testruby.bundle
irb -rtestruby -I.
clean:
rm -rf .crystal testruby.bundle
@assimovt
assimovt / Dockerfile
Last active January 31, 2024 18:30
Dockbit Dev environment
FROM ruby:2.3
MAINTAINER [email protected]
# Install app dependencies
RUN apt-get update -qq && apt-get install -y \
build-essential \
libpq-dev \
unzip \
telnet \
vim \
@dcode
dcode / GitHub Flavored Asciidoc (GFA).adoc
Last active May 26, 2025 06:38
Demo of some useful tips for using Asciidoc on GitHub

GitHub Flavored Asciidoc (GFA)