Skip to content

Instantly share code, notes, and snippets.

View toddsiegel's full-sized avatar

Todd Siegel toddsiegel

  • Solera Software, Inc.
  • Denver, CO
  • 10:10 (UTC -06:00)
View GitHub Profile
@toddsiegel
toddsiegel / generator.rb
Created September 30, 2021 22:42
Rails Generators: Turn off I don't use
# config/initialers/generators.rb
# This config will not generate the following:
# - per model view helpers, or stylesheets
# - scaffold.scss
# - jbuilder templates, which I only occasionally use
# - controller tests, which I don't really use. I do system tests instead.
Rails.application.config.generators do |g|
@toddsiegel
toddsiegel / Elasticsearch Cheatsheet.md
Last active February 9, 2024 16:53
Elasticsearch Cheatsheet

Introspection

List all indicies

The v query params shows the heading in the response

GET /_cat/indices?v

List indicies with wildcard

GET /_cat/indices/profiles*?v
@toddsiegel
toddsiegel / cookbook.md
Created January 4, 2022 23:18
Ruby Cookbook

CSVs

Generate a CSV

csv = CSV.generate(headers: true, force_quotes: true) do |row|
  row << ['ID', 'Name',  'Email']
  people.each do |person|
    row << [person.id, person.name, person.email]
  end
end
csv = "#{csv}" # Add BOM if people are going open this in Excel
@toddsiegel
toddsiegel / capybara.md
Last active January 11, 2022 16:08
Capybara Cheatsheet

Forms

Fill in inputs by name

# e.g.
# <table>
#   <tbody>
#     <tr>
#      <td><input name="foo" type="text" /></td>
#      <td><input name="bar" type="text" /></td>
# 
@toddsiegel
toddsiegel / histogram.sql
Last active February 5, 2024 19:00
PostgreSQL Histogram
-- this groups by 5 to keep the length down
select length(username) as length,
count(*) as count,
repeat('*'::text, (COUNT(length(username))::int / 5) + 1) AS histogram
from users
where username is not null
group by length(username)
order by length;
@toddsiegel
toddsiegel / gist:9be4ba387c30674a3ce733d5f6cef379
Created August 9, 2024 19:58
One file ActiveRecord script
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'sqlite3', '~> 1.4'
gem 'activerecord', '7.1.3.4'
end
require 'sqlite3'