Skip to content

Instantly share code, notes, and snippets.

View andynu's full-sized avatar

Andrew Nutter-Upham andynu

View GitHub Profile
@andynu
andynu / llme.rb
Last active February 27, 2024 22:25
A little ollama client for pre-defined prompts.
#!/usr/bin/env ruby
require 'thor'
require 'uri'
require 'net/http'
require 'json'
# > llme joke
# Sure! Here's one:
#
@andynu
andynu / examples.md
Created February 1, 2024 16:50
Assorted rake tasks for orienting and evaluating the use of a rails app.

Overview:

rails stats:controllers  # Show basic controller usage stats
rails stats:models       # Show basic model usage stats
rails stats:trends       # show frequency trends for a date column; MODEL=x COLUMN=y
rails stats:unroutable   # Find routes that will raise a routing error when requested
rails stats:users        # Show basic details of users
@andynu
andynu / doc.rake
Created February 1, 2024 15:40
Run annotate and erd automatically when you db:migrate (rails)
namespace :doc do
desc 'generate yardoc docs in doc/app/index.html'
task :app do
`yard doc -o doc/app`
puts "see doc/app/index.html"
end
desc 'annotate models'
task :annotate do
run = ->(cmd){
@andynu
andynu / show_method_history.rb
Created August 26, 2022 18:56
Given a ruby file and method name shows you all the different versions across the git history.
#!/usr/bin/env ruby
# Given a file and method_name
# Show all the different implementations across the git history (first commit per implementation).
#
# show_method_history <file> <method_name> --html
#
# e.g. show_method_history test/test_helper.rb sign_in --html
#
# WARNING: the --html output just dumps html files into your current folder.
#
@andynu
andynu / gem-bisect
Last active August 17, 2022 06:36
Find the last version that passes the tests by doing a binary search through a range of versions
#!/usr/bin/env ruby
#
# Find the last version that passes the tests by doing
# a binary search through a range of versions
#
# Usage: gem-bisect <gem_name> [<from_version> [<to_version>]]
#
# Example
# ❯ gem-bisect rack-attack 6.3 6.6.1
# Checking versions 6.6.1, 6.5.0, 6.4.0, 6.3.1
#!/usr/bin/env ruby
require 'chronic'
require 'set'
if ARGV.empty?
ARGV.replace ['log/production.log']
end
# From facets gem
module Enumerable
# Add this to your config/initializers/ folder.
if Kernel.const_defined?('ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter')
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans = false
# Version 7.0.2 of activerecord-oracle_enhanced-adapter loads the types into
# a constant TYPE_MAP when the class is loaded
#
# This is so early in the process that there is no opertunity to change the
# default value of emulate_booleans, so that config is ineffective in that
@andynu
andynu / init.vim
Created June 10, 2022 19:02
A neo-vim config.
" .config/nvim/init.vim
" Plugins
call plug#begin(stdpath('config') . '/plugins')
Plug 'neovim/nvim-lspconfig'
Plug 'stevearc/aerial.nvim'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
@andynu
andynu / routes_check.rake
Last active June 1, 2022 01:40
Parses production logs and checks which routes are used out of all the routes that are defined.
desc 'Show basic controller usage stats'
task :controllers => :environment do
logfiles = Dir['log/%s.log*' % Rails.env].sort
logs_gz, logs_txt = logfiles.partition{|f| Pathname.new(f).extname == '.gz' }
results = `ag Started -A 1 #{logs_txt.join(' ')}`
unless logs_gz.empty?
results << `zcat #{logs_gz.join(' ')} |ag Started -A 1`
end
Event = Struct.new(:http_method, :uri_path, :client_ip, :requested_at_str, :controller_name, :controller_action, :format) do
def requested_at
@andynu
andynu / rfluff.rb
Created May 18, 2022 12:53
rfluff a way to list TODOS|XXX|HACK|etc /w optional vim quickfix formatting.
#!/usr/bin/ruby
#
# gather a few statistics and find all flagged comments
#
# Usage:
# rfluff [-qf] [tag] [tag] ...
#
# -qf outputs a vim compatible quickfix format, otherwise
# the output is human readable