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 July 24, 2024 19:33
Simple Template Rendering

Simple Template Rendering

I'm experimenting with a simple template rendering solution that leverages Ruby's native String formatting. It feels a little bit like Mustache templates. Note that this demo adds new "formatting specifiers" to support Rainbow color mechanics.

Tip

See the files below for the implementation... and note that this is simply a proof of concept (POC)

Usage

@hopsoft
hopsoft / db.rake
Last active July 5, 2024 14:52
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@hopsoft
hopsoft / README.md
Last active July 5, 2024 00:23
TurboBoost Commands generator example

TurboBoost Commands Generator

The next version of TurboBoost will ship with generators to help you get started with Commands quickly.

  1. View help for the generator
bin/rails g turbo_boost:command -h
Usage:
  bin/rails generate turbo_boost:command NAME [options]
@hopsoft
hopsoft / README.md
Last active June 29, 2024 07:43
TurboBoost Command generator

TurboBoost Command Generator

Run the Generator

➜  showcase git:(main) bin/rails g turbo_boost:commands:command Example
Where is your Commands directory located? (default: app/commands)
   identical  app/commands/application_command.rb
      create  app/commands/example_command.rb
@hopsoft
hopsoft / README.md
Last active June 20, 2024 09:27
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 / 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 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 / broadcastable.rb
Created November 22, 2021 19:46
Broadcastable model concern/mixin
# frozen_string_literal: true
module Broadcastable
extend ActiveSupport::Concern
def prepend_operation(options = {})
operation = {html: ApplicationController.render(partial: to_partial_path, locals: locals)}
operation.merge options
end