Skip to content

Instantly share code, notes, and snippets.

View fractaledmind's full-sized avatar

Stephen Margheim fractaledmind

View GitHub Profile
@fractaledmind
fractaledmind / compile_sqlite.sh
Last active September 8, 2023 13:18
Shell script to install and compile project-local SQLite
#!/usr/bin/env sh
cd ../vendor
mkdir -p sqlite/bin
mkdir -p sqlite/lib
mkdir -p sqlite/include
# ============================================================================================================
# Compile and install sqlite3 (for performance turning and build customizations)
# SEE: https://www.sqlite.org/compile.html
@fractaledmind
fractaledmind / index.css
Created September 7, 2023 12:23
Minimal requirements for linked headings in a BridgetownRB site
[aria-hidden="true"] {
visibility: hidden;
}
.anchor {
text-decoration: none;
}
h2:hover .anchor,
h3:hover .anchor,
@fractaledmind
fractaledmind / active_record_sqlite3adapter.rb
Last active September 26, 2023 18:06
A Rails initializer to enhance the SQLite adapter to allow for pragmas to be configured in the /config/database.yml file
module RailsExt
module SQLite3Adapter
# Perform any necessary initialization upon the newly-established
# @raw_connection -- this is the place to modify the adapter's
# connection settings, run queries to configure any application-global
# "session" variables, etc.
#
# Implementations may assume this method will only be called while
# holding @lock (or from #initialize).
#
@fractaledmind
fractaledmind / sqlite-where-iif-test.rb
Created August 4, 2023 13:44
A reproducible bug script demonstrating that WHERE IIF doesn't behave as expected.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "sqlite3"
@fractaledmind
fractaledmind / litearray.rb
Created August 4, 2023 13:30
An executable Ruby script sandbox demonstrating how to implement "tag columns" for a SQLite database.
# frozen_string_literal: true
# require "bundler/inline"
#
# gemfile(true) do
# source "https://rubygems.org"
#
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
#
# gem "rails"
@fractaledmind
fractaledmind / litekiq.rb
Last active August 9, 2023 08:27
An executable Ruby script sandbox to explore the concept of a SQLite-backed, process-embedded job backend
# frozen_string_literal: true
# require "bundler/inline"
#
# gemfile(true) do
# source "https://rubygems.org"
#
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
#
# gem "sqlite3"
# /lib/rails_ext/generated_attribute.rb
# Here, we patch the GeneratedAttribute class to add `richer_text` as a field type, which behaves much the same as the `rich_text` type.
# We will patch the Model generator as well to tweak the ActiveRecord model generated when this type is used
require 'rails/generators/generated_attribute'
module Rails
module Generators
class GeneratedAttribute
import { Controller } from "@hotwired/stimulus"
// use with Rails' `time_Tag` helper like so:
// <%= time_tag campaign.starts_at, campaign.starts_at.to_formatted_s(:short), data: { controller: "localized-time", localized_time_type_value: "datetime-short" } %>
export default class extends Controller {
static targets = [ ]
static values = {
type: String,
style: { type: String, default: 'medium' },
locale: { type: String, default: 'default' },
@fractaledmind
fractaledmind / paper_trail_bug_patch.rb
Created April 6, 2023 08:40
This is the patch used to get around the bug reported with this gist: https://gist.github.com/fractaledmind/7574eaeb00dff6b9afd7778a7e024c19
# We need to patch PaperTrail to deal with Campaign having a `serialize` field that also has an `attribute` definition with a `default` value set for the attribute, as well as a database-level `default` set as well. For whatever all the reasons, PaperTrail tries to serialize the database-default, which is already a string. This throws an `ActiveRecord::SerializationTypeMismatch` error, as it is expecting the valued being serialized to be an `Array`. In this case, we can solve our problem by simply catching this error and checking of the value is already serialized.
module PaperTrail
module AttributeSerializers
class CastAttributeSerializer
private
def serialize(attr, val)
AttributeSerializerFactory.for(@klass, attr).serialize(val)
rescue ActiveRecord::SerializationTypeMismatch => error
if val.is_a?(String) && YAML.load(val)
@fractaledmind
fractaledmind / paper_trail_serialization_bug_report.rb
Created April 6, 2023 08:38
This bug report script demonstrates a bug with PaperTrail when the ActiveRecord model has both database and model defaults for a serialized field
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "activerecord", "~> 7.0.0"