This file contains hidden or 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 ArrayIndices | |
| refine Array do | |
| def indices(...) | |
| positions = [] | |
| offset = 0 | |
| while (position = self[offset..].index(...)&.+(offset)) | |
| positions << position | |
| offset = position.succ | |
| end |
This file contains hidden or 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
| # frozen_string_literal: true | |
| require 'active_model' | |
| require 'active_support/inflector' | |
| require 'csv' | |
| class CSVFileModel | |
| class RecordNotFound < StandardError | |
| def message = 'Record not found.' | |
| end |
This file contains hidden or 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
| #/|\ ^._.^ /|\-*-shaREABle-cONStaNt_vaLUe:LITEral;🦇;fRozEN_StRING-Literal:tRUE-*-/|\ ^._.^ /|\# | |
| FROZEN = %w[❄️] | |
| p FROZEN.frozen? | |
| #=> true | |
| p FROZEN.all?(&:frozen?) | |
| #=> true |
This file contains hidden or 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
| # frozen_string_literal: true | |
| source 'https://rubygems.org' | |
| gem 'trenni' |
This file contains hidden or 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
| # frozen_string_literal: true | |
| ## | |
| # A Rack app that streams a simple HTML page. | |
| module App | |
| PRETEND_TO_WAIT_FOR_IO = proc do | |
| sleep 2 | |
| 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.' | |
| end | |
| HEADERS = {'content-type' => 'text/html; charset=utf-8'}.freeze |
This file contains hidden or 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 Class | |
| def new(...) | |
| warn 'Overriding Class#new' | |
| instance = allocate | |
| instance.send(:initialize, ...) | |
| instance | |
| end | |
| end |
This file contains hidden or 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
| # frozen_string_literal: true | |
| module Kernel | |
| def Binary(string, exception: true) | |
| hex = string.b | |
| hex.gsub!(/#[^#]*$\R*/, '') | |
| hex.gsub!(/"[^"]*"/) do |quotes| | |
| quotes[1..-2].unpack1('H*') | |
| end | |
| hex.delete!("\s\t") |
This file contains hidden or 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
| # frozen_string_literal: true | |
| class RingBuffer | |
| Nothing = Data.define | |
| EMPTY = Nothing.new | |
| attr_reader :size | |
| def initialize(capacity:) | |
| @capacity = capacity |
This file contains hidden or 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
| # frozen_string_literal: true | |
| require 'curses' | |
| require 'singleton' | |
| module Isene | |
| class ColorRegistry | |
| include Singleton | |
| attr_reader :colors |
This file contains hidden or 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 'zlib' | |
| path = 'example.rb' | |
| ## | |
| # Compile and cache Ruby binary to disk. | |
| binary = RubyVM::InstructionSequence.compile_file(path).to_binary | |
| binary_path = "#{path}.yarb.gz" | |
| Zlib::GzipWriter.open(binary_path) do | |
| _1.write(binary) |