Skip to content

Instantly share code, notes, and snippets.

View fractaledmind's full-sized avatar

Stephen Margheim fractaledmind

View GitHub Profile
@dedlim
dedlim / claude_3.5_sonnet_artifacts.xml
Last active July 22, 2024 00:15
Claude 3.5 Sonnet, Full Artifacts System Prompt
<artifacts_info>
The assistant can create and reference artifacts during conversations. Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity.
# Good artifacts are...
- Substantial content (>15 lines)
- Content that the user is likely to modify, iterate on, or take ownership of
- Self-contained, complex content that can be understood on its own, without context from the conversation
- Content intended for eventual use outside the conversation (e.g., reports, emails, presentations)
- Content likely to be referenced or reused multiple times
@coolprobn
coolprobn / date_in_preferred_time_zone.rb
Created June 19, 2024 15:18
Convert any DateTime to the timezone you prefer while still keeping the same date and time - Ruby on Rails
def date_in_danish_time(date_time)
date_array =
date_time.strftime("%Y %m %d").split.map { |string| Integer(string, 0) }
danish_date = Date.new(*date_array).in_time_zone("Copenhagen")
# extracting offset from the date will help us in also taking care of Daylight Saving
danish_date_offset = danish_date.formatted_offset
date_time_array =
date_time
.strftime("%Y %m %d %H %M %S")
@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