This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pty' | |
require 'io/console' | |
require 'logger' | |
class REPL | |
attr_reader :stdout, :stdin, :logger | |
# Number of bytes to read at a time. | |
READ_CHUNK_SIZE = 512 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/phlex_template_handler.rb | |
require "action_view" | |
require "phlex" | |
# Intercept unknown "capitalized" method calls (e.g., PageView(...)) in templates, | |
# look up a Phlex component class, instantiate it, and render it. | |
# Crucially, we re-bind the user’s block so that `self` is the component, not the ActionView context. | |
module PhlexDynamicMethodCalls | |
def method_missing(name, *args, **kwargs, &block) | |
# Only intercept method calls starting with an uppercase letter (e.g. "PageView", "MyComponent", etc.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'rspec' | |
end | |
require 'rspec/autorun' | |
class Scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Component | |
attr_writer :post | |
def initialize(session:, fun: "bags", deeze:) | |
@session = session | |
@fun = fun # Make sure we assign this, otherwise @fun would be nil | |
@deeze = deeze | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Stop the PostgreSQL service | |
echo "Stopping PostgreSQL service..." | |
brew services stop postgresql || echo "PostgreSQL service not running." | |
# Uninstall PostgreSQL | |
echo "Uninstalling PostgreSQL..." | |
brew uninstall --force postgresql postgresql@14 postgresql@13 || echo "PostgreSQL not installed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "pathname" | |
require "bundler" | |
path = Pathname.new("/Users/bradgessler/Projects/terminalwire/traveling-ruby/shared/gemfiles/20241122") | |
definition = Bundler::Definition.build(path.join("Gemfile"), path.join("Gemfile.lock"), nil) | |
definition.locked_gems.specs.each do |spec| | |
p spec.name, spec.version | |
puts "gem install --platform=ruby #{spec.name} -v '#{spec.version}'" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you prefer TrueClass and FalseClass returns for predicate methods, | |
# you can `include Boolean::Truther` into your class to automatically generate | |
# ¿-prefixed methods that return true or false. | |
# Define a module to automatically generate the ¿-prefixed methods | |
module Boolean | |
module Truther | |
def self.included(base) | |
base.extend(ClassMethods) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fizz | |
def self.tool(method_name) | |
puts "defining methods in ruby return a symbol, like #{method_name.inspect}" | |
end | |
end | |
class Buzz < Fizz | |
tool def hello | |
puts "Hi!" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveExchange | |
class Channel | |
def initialize(name:, server: ActiveExchange.server) | |
@server = server | |
@channel = name | |
@queue = Queue.new | |
@subscribe = false | |
end | |
def broadcast(message) |
NewerOlder