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
| COUNTRY_LETTERS = 'A'.upto('Z').with_index(127462).to_h.freeze | |
| def country_emoji(iso) | |
| COUNTRY_LETTERS.values_at(*iso.chars).pack('U*') | |
| end | |
| country_emoji('GB') | |
| #=> "🇬🇧" |
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
| string = 'numbers: one two three # en fin' | |
| caption = string[/\A\w*/] | |
| content = string[/(?<=:).*(?=#)/].split | |
| caption | |
| #=> "numbers" | |
| content | |
| #=> ["one", "two", "three"] |
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 'tuple_space' | |
| class Cache | |
| def initialize | |
| @memory = TupleSpace.new(reaper_period_in_secs: 10, expires_in_secs: 60) | |
| end | |
| def get(request) | |
| @memory[request] | |
| 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
| class Xco | |
| attr_accessor :reaper | |
| def initialize | |
| @reaper = Automaton.new self | |
| @reaper.start | |
| end | |
| class Automaton | |
| def initialize(source, function: :reap, interval: 1) |
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 IterateString | |
| refine String do | |
| def iterate(count, &block) | |
| Enumerator.produce(self, &block).first(count) | |
| end | |
| end | |
| end | |
| using IterateString |
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 'irb/completion' | |
| require 'irb/ext/save-history' | |
| IRB.conf[:SAVE_HISTORY] = 1_000_000 | |
| IRB.conf[:PROMPT_MODE] = :SIMPLE |
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 MultipleInstancesOfState | |
| attr_accessor :state | |
| def initialize(state:) | |
| @state = state | |
| end | |
| def foo | |
| @state.reverse! | |
| 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
| git clone --depth 1 --single-branch --branch guild https://github.com/ko1/ruby.git ruby-isolates-src | |
| cd ruby-isolates-src | |
| autoconf | |
| ./configure --prefix=$HOME/.rubies/ruby-guilds # chruby | |
| # ./configure --prefix=$HOME/.rvm/rubies/ruby-guilds # RVM | |
| # ./configure --prefix=$HOME/.rbenv/versions/3.0.0/ruby-guilds # rbenv | |
| make -j2 | |
| make install |
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 'time' | |
| module FixStrptime | |
| refine Time.singleton_class do | |
| def strptime(date, format, now=self.now) | |
| d = Date._strptime(date, format) | |
| raise ArgumentError, "invalid date or strptime format - `#{date}' `#{format}'" unless d | |
| if seconds = d[:seconds] | |
| if sec_fraction = d[:sec_fraction] | |
| usec = sec_fraction * 1000000 |
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 'benchmark/ips' | |
| Benchmark.ips do |ips| | |
| words = [*'a'..'all'].freeze | |
| separator = '-' | |
| ips.report('map & join') { words.map { |word| separator + word }.join } | |
| ips.report('join & prepend') { words.join(separator).prepend(separator) } |