# In your Gemfile
gem "localhost"
# Then, depending on your desired server
gem "falcon"
gem "puma"
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 'open3' | |
require 'reline' | |
class Reline::LineEditor | |
private def perform_completion(list, _just_show_list) | |
_preposing, target, _postposing = retrieve_completion_block | |
namespace = IRB.CurrentContext.io.retrieve_doc_namespace(target) | |
namespace = namespace.first if namespace.is_a?(Array) | |
if namespace.nil? || !('A'..'Z').include?(namespace[0]) | |
namespace = IRB.conf[:__MAIN__] |
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
<div data-controller="search"> | |
<div data-search-target="button"> | |
<div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search"> | |
<%= heroicon "magnifying-glass" %> | |
<span>Search</span> | |
<kbd>Cmd/Ctrl+K</kbd> | |
</div> | |
<dialog data-search-target="dialog"> | |
<article> |
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
# Maybe there's a way to support ActiveSupport::Concern's dependencies too? | |
# Although this doesn't use the module hierarchy, so `prepend` can't work. | |
class Concern < Module | |
def initialize(&block) = @block = block | |
def included(klass) = klass.class_eval(&@block) | |
end | |
module Kernel | |
def Concern(...) = Concern.new(...) | |
end |
In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal
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 AsyncMethodJob < ApplicationJob | |
queue_as :default | |
def perform(target:, method_name:, args:, queue_name: :default) | |
self.class.queue_as(queue_name) | |
# `target` could be either an instance or a class | |
target = target.constantize if target.is_a?(String) # Convert class name to class object if needed | |
target.send(method_name, *args) | |
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
# Unnecessary indexes slows down writes and consumes additional storage and memory. | |
# Just paste this snippet in your Rails console (bundle exec rails c). | |
# And it will print all redundant indexes that are already covered by another index on the table: | |
# Table `pages`: index `site_idx` (site_id) already covered by `site_slug_idx` (site_id,slug) | |
# Table `optins`: index `list_idx` (list_id) already covered by `list_active_idx` (list_id,active) | |
ActiveRecord::Base.connection.tables.map do |table| | |
indexes = ActiveRecord::Base.connection.indexes(table).select(&:valid).reject(&:where) |
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
# Leverages the BroadcastLogger introduced in Rails 7.1 to wrap the current | |
# logger in a new logger that broadcasts to both the current logger and $stdout | |
# | |
# (Announcement: https://rubyonrails.org/2023/9/29/this-week-in-rails) | |
# | |
# If the current logger already broadcasts to $stdout, it will not be wrapped, | |
# making it safe to call this method multiple times without knowing the current | |
# logging "sitch". | |
# | |
# Usage probably looks something like this: |
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
#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')" | |
# syntax = docker/dockerfile:1.4.0 | |
FROM node:20 | |
WORKDIR /root | |
RUN npm install sqlite3 |
So you've got a cool app in Ruby, and you want to share it with your friends, but they don't love Ruby as much as you.
What do you do? Package it up along with the Ruby runtime and give it to them. Simple right? Maybe not so.
Thankfully smarter cookies than me, have tackled the problem, here is a map of the current state of play
- Traveling-ruby
- Rb2exe revisted to use the updated traveling-ruby releases in this fork
NewerOlder