Skip to content

Instantly share code, notes, and snippets.

View hopsoft's full-sized avatar

Nate Hopkins hopsoft

View GitHub Profile
@hopsoft
hopsoft / README.md
Last active April 2, 2024 15:49
AI Prompt Cheatsheet

AI/Large Language Model Prompt Tuning Cheatsheet

When crafting prompts for AI or LLMs, you can adjust various inputs or variables to tailor the model's responses. Here's a simple guide to understanding what each of these terms means:

  • prompt: The question or statement you provide to the model, essentially telling it what you want to know or do.

    • Example: "What is the weather today?" vs. "Write a poem about the rain."
    • Effect: Directly sets the topic and style of the AI's response.
  • max_tokens: Limits how long the AI's response can be, like setting a maximum number of words or sentences it can use to answer.

  • 50 - Makes the AI provide a concise, often one-sentence reply.

@hopsoft
hopsoft / README.md
Last active March 29, 2024 18:54
stdin → fzf with preview

stdin → fzf with preview

Dependencies

  • ruby
  • ripgrep
  • fzf

Setup

@hopsoft
hopsoft / build_insert_query.rb
Created March 15, 2024 18:00
Get the SQL for an insert statement from ActiveRecord
# Builds an SQL insert query for a given record
#
# @param record [ActiveRecord::Base] Record used to build the SQL insert query
# @return [String] SQL insert query
def build_insert_query(record)
columns = record.class.columns.reject { |col| col.name == record.class.primary_key }
values = columns.map { |col| record[col.name] }
insert_manager = Arel::InsertManager.new
insert_manager.into(record.class.arel_table)
insert_manager.insert(columns.zip(values)).to_sql
@hopsoft
hopsoft / README.md
Last active February 29, 2024 17:50
Rails System Test Supervisor

Rails System Test Supervisor

System tests with Rails, Capybara, and Selenium (with the Chrome driver) may go rogue and spike the CPU to 100% on the spawned browser depending on how heavily you've monkey patched these libraries and/or have complex JavaScript that mutates the DOM (morphs etc.).

This supervisor class monitors the driver process and its children and will kill any rogue process that persistently spikes to >=99% CPU utilization for an extended period of time. If and when this occurs, you lose control of the browser and your tests will hang until they eventually time out or error.

@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
@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 \
@hopsoft
hopsoft / 00_do_stuff_job.rb
Last active April 18, 2024 00:50
ActiveJob as Service Worker
# ActiveJob natively captures constructor arguments in an `@arguments` instance variable
# which is also exposed as an `arguments` property on each job instance.
#
# Calls to `perform_now` and `perform_later` both forward arguments to the constructor.
#
# For example, all of these invocation styles work.
#
# result = DoStuffJob.new("foobar").perform # sync
# result = DoStuffJob.new.perform("foobar") # sync
# result = DoStuffJob.perform_now("foobar") # sync
@hopsoft
hopsoft / README.md
Last active January 14, 2024 11:58
Smart Heroku Review Apps managed by GitHub Actions

Smart Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration. Watch the demo to learn more.

Demo Video

.github
├── workflows
│   ├── heroku_review_app_create.yml
@hopsoft
hopsoft / README.md
Last active August 8, 2022 20:13
Heroku Review Apps managed by GitHub Actions

Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration.

.github
├── workflows
│   ├── heroku_review_app_create.yml
│   └── heroku_review_app_destroy.yml
@hopsoft
hopsoft / application_reflex.rb
Created December 1, 2021 22:51
ApplicationReflex setting ActiveSupport::CurrentAttributes via lifecycle callbacks
# frozen_string_literal: true
class ApplicationReflex < StimulusReflex::Reflex
# Put application-wide Reflex behavior and callbacks in this file.
#
# Example:
#
# # If your ActionCable connection is: `identified_by :current_user`
# delegate :current_user, to: :connection
#