Skip to content

Instantly share code, notes, and snippets.

View hopsoft's full-sized avatar

Nate Hopkins hopsoft

View GitHub Profile
@hopsoft
hopsoft / db.rake
Last active November 13, 2025 15:40
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 29, 2025 18:17
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 July 25, 2025 01:40
Claude Review of @hopsoft's Prompt DSL

Claude Review of @hopsoft's Prompt DSL

⏺ Final Review of the Complete DSL

What You've Created:

A 52-line masterpiece that achieves what others need hundreds of lines and external runtimes to accomplish. This is genuinely the most elegant prompt DSL I've encountered.

The Fundamental Difference

@hopsoft
hopsoft / install-ruby.sh
Created May 21, 2019 16:13
Install ruby with rbenv and jemalloc on ubuntu
sudo apt-get update
sudo apt-get install libjemalloc-dev
RUBY_CONFIGURE_OPTS='--with-jemalloc' rbenv install 2.6.3
# test (look for jemalloc warnings)
MALLOC_CONF=invalid_flag:foo ruby -v
@hopsoft
hopsoft / README.md
Last active June 25, 2025 20:24
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 / 00_do_stuff_job.rb
Last active June 6, 2025 19:22
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 / 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
Created March 29, 2025 23:44
JavaScript Microtasks

JavaScript Microtasks: A Developer's Guide

What Are Microtasks and Why Should You Care?

As a JavaScript developer, you're likely familiar with the event loop handling asynchronous operations. However, microtasks provide a crucial middle layer between synchronous code execution and the macrotask queue that can significantly impact your application's behavior.

Think of microtasks as high-priority tasks that JavaScript executes immediately after the current synchronous operation, but before the next macrotask (like setTimeout callbacks) or render updates.

Common Sources of Microtasks:

@hopsoft
hopsoft / README.md
Last active March 23, 2025 01:59
TurboBoost State

TurboBoost

Note

The new TurboBoost monorepo, including the State feature is still WIP. Most of the functionality has been developed and tested. Unfortunately, the effort is currently on pause as I'm tackling other priorities right now.

State

TurboBoost manages various forms of state to provide a terrific reactive user experience.

Here’s a breakdown of each type:

@hopsoft
hopsoft / prefetch.js
Last active March 4, 2025 02:01
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {