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 'fileutils' | |
| module FileUtils | |
| # Returns the full path to an executable command if it exists in the PATH. | |
| # | |
| # FileUtils.which('ruby') # => "/usr/bin/ruby" | |
| # FileUtils.which('matz') # => nil | |
| # |
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
| def uuid_v7 | |
| milliseconds = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) | |
| buffer = IO::Buffer.new(16) | |
| buffer.set_string([milliseconds].pack('Q>')[2..], 0) | |
| buffer.set_string(SecureRandom.bytes(10), 6) | |
| buffer.set_value(:U8, 6, buffer.get_value(:U8, 6) & 0x0F | 0x70) | |
| buffer.set_value(:U8, 8, buffer.get_value(:U8, 8) & 0x3F | 0x80) | |
| buffer.get_string.unpack('H8H4H4H4H12').join('-') | |
| 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 'securerandom' | |
| module NanoID | |
| ALPHABET = [*'A'..'Z', *'a'..'z', *'0'..'9', '_', '-'].freeze | |
| module_function | |
| def nano_id(alphabet: ALPHABET, size: 21) |
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
| Value = Data.define(:number) do | |
| def +(other) = with(number: number + other.number) | |
| private | |
| def coerce(number) = [Value.new(number), self] | |
| end | |
| 42 + Value.new(42) | |
| #=> #<data Value number=84> |
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
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| require 'optparse' | |
| require 'fileutils' | |
| require 'open3' | |
| module TerraformExecutor | |
| Config = Struct.new(:parallelism, :init, :vault, :tag, keyword_init: 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
| diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb | |
| index e756af61ea..555d1d4cd1 100644 | |
| --- a/lib/bundled_gems.rb | |
| +++ b/lib/bundled_gems.rb | |
| @@ -98,7 +98,7 @@ def self.warning?(name, specs: nil) | |
| # name can be a feature name or a file path with String or Pathname | |
| feature = File.path(name) | |
| # bootsnap expand `require "csv"` to `require "#{LIBDIR}/csv.rb"` | |
| - name = feature.delete_prefix(LIBDIR).chomp(".rb").tr("/", "-") | |
| + name = feature.delete_prefix(ARCHDIR).delete_prefix(LIBDIR).tr("/", "-") |
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
| ## | |
| # This is similar to your code to reproduce what it's doing | |
| def export_similar_to_your_code | |
| io = Zip::OutputStream.write_buffer do |stream| | |
| 'a'.upto 'z' do |char| | |
| stream.put_next_entry "#{char}.txt" | |
| stream << char * 42 | |
| end | |
| ensure | |
| stream.close_buffer |
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 Attributes < Module | |
| def initialize(**attributes) | |
| self.class.class_eval do | |
| define_method :included do |klass| | |
| klass.class_eval do | |
| attributes.each do |key, value| | |
| instance_variable_set "@#{key}", value | |
| singleton_class.class_eval { attr_accessor key } | |
| 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
| 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 |