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 zsh | |
version=3.4.0 | |
brew install gmp jemalloc libffi libyaml openssl@3 readline zlib | |
command -v rustc >/dev/null 2>&1 || brew install rust | |
mkdir -p "$HOME/src" | |
cd "$HOME/src" | |
curl "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-$version.tar.xz" | tar -x | |
cd "ruby-$version" |
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 Integer | |
def each_digit(base = 10, &block) | |
raise Math::DomainError, 'out of domain' if negative? | |
raise TypeError, "wrong argument type #{base.class} (expected Integer)" unless base.respond_to?(:to_int) | |
radix = base.to_int | |
raise ArgumentError, 'negative radix' if radix.negative? | |
raise ArgumentError, "invalid radix #{radix}" if radix < 2 | |
return enum_for(__method__, base) unless block_given? |
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
without = %w[b c] | |
without_regexp = Regexp.union(without) | |
split_index = 7 | |
dropped = split_index.pred | |
str = 'abcdaba123abcd' | |
pos = str | |
.each_grapheme_cluster | |
.with_index | |
.lazy |
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 'json' | |
class Waffle | |
def initialize(toppings:, syrup:) | |
@toppings = toppings | |
@syrup = syrup | |
end | |
class << self | |
def json_create(object) |
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 Integer | |
def stream(by: 1) | |
Enumerator.new Float::INFINITY do |yielder| | |
int = self | |
loop do | |
fed = yielder.yield(int) | |
int += fed if fed | |
int += by | |
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
require 'dry-struct' | |
require 'dry-types' | |
require 'dry-validation' | |
class WordTally | |
class Args < Dry::Struct | |
module Types | |
include Dry.Types() | |
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 Caesar | |
def initialize(rot: 13, lower: [*'a'..'z'], upper: [*'A'..'Z']) | |
@rot = rot | |
@book = book(lower:, upper:) | |
end | |
def cipher(message) = message.gsub(/[a-zA-Z]/, @book) | |
alias_method :call, :cipher | |
private |
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
# 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 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 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) |
NewerOlder