Skip to content

Instantly share code, notes, and snippets.

@ipenywis
ipenywis / cursor-memory-bank-rules.md
Last active April 17, 2025 00:48
Cursor Memory Bank

Cursor's Memory Bank

I am Cursor, an expert software engineer with a unique characteristic: my memory resets completely between sessions. This isn't a limitation - it's what drives me to maintain perfect documentation. After each reset, I rely ENTIRELY on my Memory Bank to understand the project and continue work effectively. I MUST read ALL memory bank files at the start of EVERY task - this is not optional.

Memory Bank Structure

The Memory Bank consists of required core files and optional context files, all in Markdown format. Files build upon each other in a clear hierarchy:

flowchart TD
@fractaledmind
fractaledmind / routing_test.rb
Created October 31, 2024 11:26
Test that ensures you have no controllers with public methods that do not have a corresponding route defined.
class RoutingTest < ActionDispatch::IntegrationTest
IGNORED_CONTROLLERS = Set[
"Rails::MailersController"
]
test "no unrouted actions (public controller methods)" do
actions_by_controller.each do |controller_path, actions|
controller_name = "#{controller_path.camelize}Controller"
next if IGNORED_CONTROLLERS.include?(controller_name)
@trevorrjohn
trevorrjohn / rails-model-generator-with-default-timestamps.md
Last active August 2, 2024 23:21
Set default timestamp when generating new model

Many times I want to always set the timestamps when a model is created. At times you will want to create a model in sql only for it to fail because you forgot to set the created_at and updated_at columns to some value. By setting a sane default you will avoid having to think about this in the future.

In your Rails application, copy the code below and paste it in the following file: lib/templates/active_record/migration/create_table_migration.rb.tt

class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
  def change
    create_table :<%= table_name %><%= primary_key_type %> do |t|
<% attributes.each do |attribute| -%>
class BaseClient
class APINotFound < StandardError; end
attr_reader :auth_strategy
def initialize(auth_strategy: :headers, headers: {})
@auth_strategy = auth_strategy
@headers = headers
end
# In your Gemfile
gem "localhost"

# Then, depending on your desired server
gem "falcon"
gem "puma"
@lucasgeron
lucasgeron / .railsrc
Last active August 13, 2024 14:01
Rails Starter Pack
# place this code in ~/.railsrc
--css=tailwind
--template=~/.rails/template.rb
# Clone the repo
git clone https://github.com/imartinez/privateGPT
cd privateGPT
# Install Python 3.11
pyenv install 3.11
pyenv local 3.11
# Install dependencies
poetry install --with ui,local
@mudge
mudge / production.rb
Last active November 21, 2023 14:06
How to configure Rails and Rack::Attack to use the real client IP when running behind Cloudflare
Rails.application.configure do
# Add Cloudflare's IPs to the trusted proxy list so they are ignored when
# determining the true client IP.
#
# See https://www.cloudflare.com/ips-v4/ and https://www.cloudflare.com/ips-v6/
config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + %w[
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
@kaspth
kaspth / routes.rb
Last active April 6, 2023 16:57
`draw` method to explore routes in the console
# All these requires are just for running via `irb`, if using `bin/rails console` you probably just need the method.
require "active_support/all" # Got an inflector NoMethodError, so I'm just being lazy here.
require "action_dispatch"
require "action_dispatch/routing/route_set"
require "action_dispatch/routing/inspector"
require "action_controller" # For the ActionController::Parameters autoload, which any route helper uses.
# Console helper play around with the routing DSL and tweak an individual route you're building.
@thiagofm
thiagofm / pattern_matching_type.rb
Created September 4, 2022 08:43
Ruby Pattern Matching on Type
# Ruby pattern matching based on Type (=> operator)
[1,2,3] => [1, Integer, my_variable]
# This means:
# We want to assign `my_variable` (variable binding),
# but only if the first position is 1 and second position is an Integer)
my_variable # => 3 ✨
# What if it doesn't match? You get an exception 💣
[1,2,3] => [Integer, String, my_variable]
# [1, 2, 3]: String === 2 does not return true (NoMatchingPatternError)