Skip to content

Instantly share code, notes, and snippets.

View fractaledmind's full-sized avatar

Stephen Margheim fractaledmind

View GitHub Profile
@joeldrapper
joeldrapper / fingerprinting.rb
Created January 10, 2024 14:30
Rails request fingerprinting concern
# frozen_string_literal: true
module Fingerprinting
def full_fingerprint
generate_fingerprint(
ip_fingerprint,
browser_fingerprint
)
end
@fractaledmind
fractaledmind / test_sqlite3_busy_timeouts.rb
Created January 4, 2024 21:05
This test script demonstrates how the busy_timeout holds the GVL while retrying, while a busy_handler timeout will release the GVL between retries
require 'sqlite3'
require 'minitest/autorun'
puts "info: gem version: #{SQLite3::VERSION}"
puts "info: sqlite version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
puts "info: threadsafe?: #{SQLite3.threadsafe?}"
class TestCase < Minitest::Test
def setup
@hopsoft
hopsoft / README.md
Last active March 29, 2024 18:06
ActiveRecord ETL

ActiveRecord ETL

I created this to help me run benchmarks/comparisons against Universal ID, but it could serve as the foundation for a robust ETL data pipeline... and it's less than 70 LOC right now! 🤯 🚀

It handles the extract and transform parts of an ETL process and supports the following options:

  • only - specify which attributes to include
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "sqlite3"
gem "enumerable-statistics"
end
require "benchmark"
@hopsoft
hopsoft / Dockerfile
Created September 7, 2023 14:36
Ruby + SQLite Dockerfile
FROM ruby:3.2.2-alpine
# ============================================================================================================
# Install system packages
# ============================================================================================================
RUN apk add --no-cache --update \
bash \
build-base \
curl \
gcompat \
@kaspth
kaspth / themed_form_with.rb
Last active June 14, 2023 14:21
A pitch to have the ability to go between several form builders in a form, focused on Bullet Train's themed field partials.
# Provide a BulletTrain::Theme::FormBuilder, with extensions to
# go between Rails standard form helpers and BulletTrain's themed versions seamlessly.
# With standard Rails:
# form_with model: Post.new do |form|
# form.themed.text_field # Use BulletTrain theming on just one field
#
# form.themed.fields do # Need a nested section of fields but themed?
# end
# end
@virolea
virolea / url_validator.rb
Last active February 16, 2023 17:01
Rails Custom URL validator
# Use this validator like this
#
# class User < ApplicationRecord
# validates :profile_link, url: true
# end
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless valid_url?(value)
record.errors.add(attribute, :invalid_url)

OpenBSD logo     Rails logo     Falcon logo


Choose OpenBSD for your Unix needs. OpenBSD -- the world's simplest and most secure Unix-like OS. A safe alternatve to the frequent vulnerabilities and overengineering of Linux and related software (NGiNX & Apache (httpd-asiabsdcon2015.pdf), OpenSSL, iptables/nftables, systemd, BIND, Postfix, Docker etc.)

OpenBSD -- the cleanest kernel, the cleanest userland and the cleanest config

@jaredcwhite
jaredcwhite / turbo_transitions.js
Created September 13, 2022 15:49
Nice transitions using Turbo
document.addEventListener("turbo:visit", () => {
let main = document.querySelector("main");
if (main.dataset.turboTransition == "false") return;
let [movement, scale] = ["-12px", "0.99"];
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
[movement, scale] = ["-6px", "1"]
};
import { Controller } from '@hotwired/stimulus'
import autoAnimate from '@formkit/auto-animate'
export default class extends Controller {
connect () {
autoAnimate(this.element)
}
}