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_relative 'enum' | |
| enum :Color do | |
| value :Red # 0 | |
| value :Green # 1 | |
| value :Blue, 5 # overwritten to 5 | |
| value :Yellow # 6 (5 + 1) | |
| def red? | |
| self == Color::Red |
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 'sequel' | |
| require 'stringio' | |
| require 'zlib' | |
| module Notes | |
| PATH = 'Library/Group Containers/group.com.apple.notes/NoteStore.sqlite' | |
| DB = Sequel.sqlite File.join Dir.home, PATH | |
| TRAILING_DIVIDOR = "\u001A\u0010\n" |
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 'fiber' | |
| class Enum | |
| class Yielder | |
| def initialize(&block) | |
| raise LocalJumpError, 'no block given' unless block_given? | |
| @block = block |
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
| ## | |
| # A standard Hash with default proc, which in this case sets the value to the key. | |
| default_value_to_key = Hash.new { |hash, key| hash[key] = key } | |
| default_value_to_key[:nope] | |
| #=> :nope | |
| ## | |
| # This is the same as the above proc with a Hash literal. | |
| another_value_to_key = {} | |
| another_value_to_key.default_proc = ->(hash, key) { hash[key] = key } |
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
| changes = {IRB::Color::BLUE => IRB::Color::YELLOW} | |
| IRB::Color.const_get(:TOKEN_SEQ_EXPRS).tap do |token_seq_exprs| | |
| changes.each do |old_color, new_color| | |
| token_seq_exprs.filter_map do |type, ((color, _), _)| | |
| color == old_color && type | |
| end.each do |matching_type| | |
| token_seq_exprs.dig(matching_type, 0)[0] = new_color | |
| 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
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| require 'async' | |
| require 'async/barrier' | |
| require 'async/http/client' | |
| require 'async/http/endpoint' | |
| require 'async/logger' | |
| require 'optionparser' |
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
| ## | |
| # Examples without block arguments | |
| def example_without_block(function) | |
| function.call + 'ay' | |
| end | |
| example_without_block ->{ 'ok' } | |
| #=> "okay" | |
| def example_explicit_block(&block) | |
| block.call + 'ay' |
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 'json' | |
| require 'optionparser' | |
| KEYWORDS = %i[color metadata glow_in_the_dark coats].freeze | |
| DEFAULTS = {coats: 3, glow_in_the_dark: true}.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
| # frozen_string_literal: true | |
| module Cistercian | |
| LINE = %w[■ ■ ■].freeze | |
| CENTER_DOT = ' ■ ' | |
| GLYPHS = [ | |
| [' ', | |
| ' ', | |
| ' '], | |
| ['■■■', |
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 Cistercian | |
| LINE = %w[■ ■ ■].freeze | |
| CENTER_DOT = ' ■ ' | |
| GLYPHS = [ | |
| [' ', | |
| ' ', | |
| ' '], | |
| ['■■■', |