Skip to content

Instantly share code, notes, and snippets.

@jmschneider
jmschneider / index.rb
Created December 19, 2024 17:48 — forked from gabriel-curtino/index.rb
Rails SQLite Global Index
# models/index.rb
# == Index Model
#
# The `Index` model manages full-text search indexes using SQLite's FTS5 (Full-Text Search) extension.
# It provides methods for adding, removing, and searching indexed items, as well as managing the underlying database schema.
#
# ### Key Features
# - **Adding Items**: Adds items to the index, ensuring any existing entries are first removed.
# - **Removing Items**: Removes items from the index based on their ID and class type.
@jmschneider
jmschneider / sqlite_full_text_search.rb
Last active July 31, 2025 04:39 — forked from gabriel-curtino/sqlite_full_text_search.rb
Rails SQLite Full Text Search (per table, at db level)
## SqliteFullTextSearch Concern
#
# The `SqliteFullTextSearch` concern provides a set of methods and triggers to enable full-text search capabilities for ActiveRecord models using SQLite's FTS5 extension.
#
# ### Key Features
# - **Full-Text Search Scope**: Adds a `search` scope to the model for performing full-text searches.
# - **Index Creation and Management**: Automatically creates and manages FTS5 tables and triggers for the model.
# - **Attribute Configuration**: Allows specifying attributes to include in the full-text search index.
# - **Trigger Management**: Sets up triggers to keep the search index up-to-date with model changes.
#
@jmschneider
jmschneider / AuthServiceProvider.php
Created September 27, 2017 13:29
Laravel WithPolicy Trait
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
// Alerts
@include alert-variant($background, $border, $text-color);
// Background Variant
@include bg-variant($parent, $color);
// Border Radius
@include border-top-radius($radius);
@include border-right-radius($radius);
@include border-bottom-radius($radius);