Skip to content

Instantly share code, notes, and snippets.

View malachaifrazier's full-sized avatar
🏠
Working from home

Malachai malachaifrazier

🏠
Working from home
View GitHub Profile
@malachaifrazier
malachaifrazier / gemspec.sh
Last active September 15, 2023 21:55 — forked from smileart/gemspec.sh
gemspec cli tools
# deps and their versions in gemspec
cat name.gemspec | ag -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~"
# deps and their version on RubyGems
cat british.gemspec | ag -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~" | awk '{ print $1 }' | xargs gem info -r | ag '\(\d+\.\d+\.\d+\)'
# gemspec and current remote versions side-by-side
paste <(cat $(ls | ag gemspec) | ag -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~") <(cat $(ls | ag gemspec) | ag -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~" | awk '{ print $1 }' | xargs gem info -r | ag -o '(?<=\()(\d+\.\d+\.\d+)(?!>\))')
@malachaifrazier
malachaifrazier / gist:b3630cf7d4567f950c26330752dc0a6e
Created August 12, 2023 15:05 — forked from johanmeiring/gist:3002458
"git lg" alias for pretty git log
# From http://garmoncheg.blogspot.com/2012/06/pretty-git-log.html
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
@malachaifrazier
malachaifrazier / multichat.rb
Created July 30, 2023 20:33 — forked from collindonnell/multichat.rb
Simple Ruby TCP multi-user chat room
#!/usr/bin/env ruby
# frozen_string_literal: true
require "socket"
class Connection
def initialize(client:, server:)
@client = client
@server = server
end
namespace :db do
desc "Outputs any invalid data records"
task :invalid_records => :environment do
puts "\n** Testing record validating in #{Rails.env.capitalize} environment**\n"
ActiveRecord::Base.send(:subclasses).each do |model|
puts "#{model} records (#{model.count})"
next if model.count == 0
invalid = model.all.reject(&:valid?)
if invalid.size.zero?
@malachaifrazier
malachaifrazier / simple_form.rb
Created June 1, 2022 16:08
Default bootstrap 5 simpleform initializer file
# frozen_string_literal: true
#
# Uncomment this and change the path if necessary to include your own
# components.
# See https://github.com/heartcombo/simple_form#custom-components to know
# more about custom components.
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
#
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
@malachaifrazier
malachaifrazier / railsnew.md
Last active June 1, 2022 17:36
Rail 7 generators with my defaults

Rails new

rails new app-name -d postgresql -j esbuild --css bootstrap

New system tests

bin/rails g system_test quotes
```
** Invoke db:environment:set (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:environment:set
** Invoke db:schema:load (first_time)
** Invoke db:load_config
** Invoke db:check_protected_environments (first_time)
== Command ["bin/rails db:prepare"] failed ==
➜ railsdevs.com git:(main) ✗ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: db/migrate/20211028230858_create_active_storage_tables.active_storage.rb
modified: db/migrate/20211128095707_create_businesses.rb
@malachaifrazier
malachaifrazier / add_index_for_searchable_fields_in_developers.rb
Last active May 18, 2022 18:45
AddIndexForSearchableFieldsInDevelopers
class AddIndexForSearchableFieldsInDevelopers < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
ALTER TABLE developers
ADD COLUMN textsearchable_index_col tsvector
GENERATED ALWAYS AS (to_tsvector('simple', coalesce(hero, '') || ' ' || coalesce(bio, ''))) STORED;
SQL
add_index :developers, :textsearchable_index_col, using: :gin, name: :textsearchable_index
end
@malachaifrazier
malachaifrazier / bin-setup-fail-console-output.rb
Created May 18, 2022 17:04
`bin/setup` failed on fresh install
railsdevs.com git:(local) bin/setup
== Installing dependencies ==
https://github.com/Shopify/erb-lint.git is not yet checked out. Run `bundle install` first.
Bundler 2.3.12 is running, but your lockfile was generated with 2.3.4. Installing Bundler 2.3.4 and restarting using that version.
Fetching gem metadata from https://rubygems.org/.
Fetching bundler 2.3.4
Installing bundler 2.3.4
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/Shopify/erb-lint.git
Fetching https://github.com/pay-rails/pay.git