Skip to content

Instantly share code, notes, and snippets.

View bradgessler's full-sized avatar

Brad Gessler bradgessler

View GitHub Profile
@bradgessler
bradgessler / gist:57c5df80d086edf38fa5cf6a58246113
Created November 2, 2024 06:52
Restart Postgres from a crashed Mac
# When macOS crashes and Postgres is running, it won't start if the `postmaster.pid` file is present.
# Careful. If you don't know what you're doing you can lose data.
# Use only on Postgres instances you don't care about or have done the work to look at the crashed data.
# Tail the logs
tail -f $(brew --prefix)/var/log/[email protected]
# Stop Postgres
brew stop postgres
@bradgessler
bradgessler / active_exchange.rb
Last active September 25, 2024 19:18
Terminalwire Rails Auth
module ActiveExchange
class Channel
def initialize(name:, server: ActiveExchange.server)
@server = server
@channel = name
@queue = Queue.new
@subscribe = false
end
def broadcast(message)
@bradgessler
bradgessler / active_exchange.rb
Last active September 12, 2024 19:26
ActionExchange
module ActiveExchange
class Channel
def initialize(name:, server: ActiveExchange.server)
@server = server
@channel = name
@queue = Queue.new
@subscribe = false
end
def broadcast(message)
@bradgessler
bradgessler / websocket.rb
Created August 26, 2024 16:12
Puma WebSocket handler
class Wrapper
include Logging
def initialize(driver, socket)
@driver = driver
@socket = socket
@queue = Queue.new
@closed = false
setup_driver
@bradgessler
bradgessler / table_component.rb
Created March 3, 2024 21:56
Playing around with a table component
TableComponent.new @items do |table|
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column("Name") { _1.name }
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column(:name)
# Emmits a `thead > th` with "Interview Times" and a `tbody > th` with the name of each item.
table.column("Name").th(class: "bg-read-100") { show(_1, :name) }
@bradgessler
bradgessler / move.rb
Created March 1, 2024 00:41
Rename symbols and objects in a Rails project
#!/usr/bin/env ruby
require 'fileutils'
require "active_support/all"
# Check for arguments
unless ARGV.length == 2
puts "Usage: #{$PROGRAM_NAME} <original_class_name> <new_class_name>"
exit
end
@bradgessler
bradgessler / phlex-pdf.rb
Last active February 23, 2024 23:44
Phlex::PDF
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "prawn"
gem "zeitwerk"
gem "matrix"
end
@bradgessler
bradgessler / test.rb
Created February 9, 2024 20:52
Super duper forms
require "bundler/inline"
gemfile do
source 'https://rubygems.org'
gem 'phlex'
end
class Field < Phlex::HTML
def template
@bradgessler
bradgessler / version.rb
Last active February 8, 2024 03:07
Upgrade a method in place
class Foo
# Define the original render method
def render
puts "Foo#render"
end
end
module Overrides
def self.prepended(klass)
klass.alias_method :base_render, :render
@bradgessler
bradgessler / component_helper.rb
Last active February 1, 2024 20:15
Component helper
module ComponentHelper
def component(name, *args, **kwargs, &block)
render componentize(name).new(*args, **kwargs), &block
end
private
def componentize(name)
"#{name.to_s.classify}Component".constantize
end
end