Skip to content

Instantly share code, notes, and snippets.

View ashwin47's full-sized avatar
๐Ÿ’œ

Ashwin M ashwin47

๐Ÿ’œ
View GitHub Profile
@peterc
peterc / CONVENTIONS.md
Last active April 20, 2025 21:22
CONVENTIONS.md file for AI Rails 8 development
  • You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use rails new first to generate all of the boilerplate files necessary.
  • Create an app in the current directory with rails new .
  • Use Tailwind CSS for styling. Use --css tailwind as an option on the rails new call to do this automatically.
  • Use Ruby 3.2+ and Rails 8.0+ practices.
  • Use the default Minitest approach for testing, do not use RSpec.
  • Default to using SQLite in development. rails new will do this automatically but take care if you write any custom SQL that it is SQLite compatible.
  • An app can be built with a devcontainer such as rails new myapp --devcontainer but only do this if requested directly.
  • Rails apps have a lot of directories to consider, such as app, config, db, etc.
  • Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
  • Guard against incapable browsers accessing controllers with `allo
@julianrubisch
julianrubisch / _search.html.erb
Created June 7, 2024 10:02
Sitepress Pagefind Integration
<div data-controller="search">
<div data-search-target="button">
<div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search">
<%= heroicon "magnifying-glass" %>
<span>Search</span>
<kbd>Cmd/Ctrl+K</kbd>
</div>
<dialog data-search-target="dialog">
<article>
@fractaledmind
fractaledmind / router.rb
Created February 19, 2024 09:12
A singleton class for Rails apps to generate URLs easily from anywhere in their app.
# frozen_string_literal: true
module Router
class << self
include Rails.application.routes.url_helpers
def default_url_options
Rails.application.config.action_controller.default_url_options || {}
end
@georgekettle
georgekettle / PhlexMailerLayout.rb
Last active March 3, 2025 08:47
Phlex Mailer layout
You'll need to update the following variables:
- ENV['APP_NAME']
- ENV['COMPANY_ADDRESS']
- ENV['HOST']
Make sure you have app/assets/images/logo.svg for this line:
helpers.image_url('logo.svg')
And also update the CSS variables to match your color scheme:
:root {
@mabenson00
mabenson00 / cheatsheet.rb
Last active April 18, 2025 17:46
Rails Postgres ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@HenrySpartGlobal
HenrySpartGlobal / deploy-new-bot.yml
Last active September 27, 2024 08:32
Auto Deployment of Discord Bot with Systemd and GitHub Actions
# Author: Henry Koleoso
# Put these two files in .github/workflows/
# Prerequisites:
# SSH Key pair - Private key in GitHub Secrets, Public key in /root/.ssh/authorized_keys on your server
# Discord Bot token - In GitHub Secrets or Environment Variables.
# This file is the workflow that handles the initial setup of your Discord bot.
# This job should be run only ONCE. Changes in 'create-systemctl-service' are appended to the systemd.service file, not overwritten so the file will be invalid!
# If you make a mistake, and need to run this job more than once, navigate to /etc/systemd/system
const official = require("gatsby-remark-embedder/dist/transformers/Twitter")
const Twitter = require("twitter-lite")
// Memoized twitter client instance
let twitterClient = null
async function getAppClient() {
if (twitterClient) {
return twitterClient
}
@lazaronixon
lazaronixon / _form.html.erb
Last active March 28, 2025 10:19
Dropzone.js + Stimulus + Active Storage + CSS Zero (2025)
<%= form_with(model: billboard) do |form| %>
<%= tag.div class: "dropzone", data: { controller: "dropzone", dropzone_param_name_value: "billboard[images][]", dropzone_url_value: rails_direct_uploads_url, dropzone_accepted_files_value: "image/*", dropzone_max_files_value: 3, dropzone_max_filesize_value: 0.300 } do %>
<div class="dz-default dz-message flex flex-col items-center">
<%= image_tag "upload.svg", size: 28, class: "colorize-black", aria: { hidden: true } %>
<h5 class="font-semibold mbs-4">Drop files here or click to upload.</h5>
<p class="text-sm text-subtle">Upload up to 10 files.</p>
</div>
<% end %>
<div class="inline-flex items-center mbs-2 mie-1">
@npearce
npearce / install-docker.md
Last active April 9, 2025 22:24
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start

Testing Rails ActionMailer and AWS SES

I added two verified email addresses to AWS SES so that I could send emails from/to them while in the SES Sandbox.

UserMailer

class UserMailer < ApplicationMailer
  default from: '[email protected]'