Skip to content

Instantly share code, notes, and snippets.

View luizkowalski's full-sized avatar
:shipit:
bug fixes and performance improvements

Luiz Eduardo Kowalski luizkowalski

:shipit:
bug fixes and performance improvements
View GitHub Profile
@luizkowalski
luizkowalski / update.rb
Last active August 30, 2024 18:46
Check if there are any new images available for Kamal accessories
#!/usr/bin/env ruby
# frozen_string_literal: true
# Lives in .kamal/update
require "json"
require "net/http"
require "uri"
require "yaml"

In my application every time I send a newsletter to a User, I create a NewsletterDelivery record. I frequently want to be able to query, for each user, what is the most recent newsletter delivery record. This is called a "last n per group" query and a LATERAL JOIN is the best way to do it imo. But the query I've been using (and I've told people to use, and seen blogged about) is not very good, because the conditions don't get pushed down into the subselect which means that the query ends-up lateral-joining all the records before it applies the conditions for the association.

Instead of doing subselect_table.* the better query does association.id AS assocation_id, subselect_table.id, subselect_table.title, .... and enumerates over all of the columns. This allows the association query, which Active Record tacks on at the end as WHERE association_id = $1 or WHERE association_id IN ($1, $2, $3, ...) to be pushed down c

@joeldrapper
joeldrapper / keymap.json
Last active November 20, 2024 12:14
My Zed Config
[
{
"context": "Editor",
"bindings": {
"alt-up": "editor::SelectLargerSyntaxNode",
"alt-down": "editor::SelectSmallerSyntaxNode",
"ctrl-cmd-up": "editor::MoveLineUp",
"ctrl-cmd-down": "editor::MoveLineDown"
}
}
@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>
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
require "bundler/inline"
gemfile do
gem "rails"
gem "sqlite3"
end
require "active_record"
require "action_controller"
require "rails"
@mediafinger
mediafinger / single_page_rails_app.ru
Created April 25, 2024 17:15
Single Page Rails App example / template
# filename: single_page_rails_app.ru
# RUN via: `rackup single_page_rails_app.ru`
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rack", "2.2.9"
gem "rails", "~> 7.1"
@AliOsm
AliOsm / .env
Last active February 23, 2025 12:41
Deploy Rails, GoodJob, PostgreSQL, Redis, Memcached, Meilisearch, and ChromaDB on the same server using Kamal.
KAMAL_REGISTRY_PASSWORD=dckr_pat_xXXxx_x0xXxXx-xX-XXX0xX0x-x
RAILS_MASTER_KEY=00x00xxx000xxx000000xx0x000x0x00
POSTGRES_PASSWORD=xXxxx0xXXx0
MEILI_MASTER_KEY=xXxxx0xXXx0
BLAZER_DATABASE_URL=postgres://service:{POSTGRES_PASSWORD}@service-name-postgres:5432/service_production
@SAMURAii-7
SAMURAii-7 / prettier-setup.md
Last active September 24, 2024 21:41
Setup Prettier with ESLint and Tailwind CSS

Steps to setup Prettier with ESLint and Tailwind CSS

Install required packages

npm install prettier prettier-plugin-tailwindcss eslint-config-prettier

OR

yarn add prettier prettier-plugin-tailwindcss eslint-config-prettier
@bradgessler
bradgessler / oauth_google_controller.rb
Last active September 14, 2023 13:57
OAuth Google controller
class OAuth::GoogleAuthorizationsController < ApplicationController
CLIENT_ID = Rails.application.credentials.google.client_id
CLIENT_SECRET = Rails.application.credentials.google.client_secret
SCOPE = "openid email profile"
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth")
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token")
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo")
before_action :validate_state_token, only: :show