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 | |
| ## | |
| # curl --request POST \ | |
| # --header "Accept: application/json" \ | |
| # --header "Content-Type: application/json" \ | |
| # --data "{\"run_request\":{\"language\":\"ruby\",\"version\":\"2.7.0\",\"code\":\"p 2 + 2\"}}" \ | |
| # https://carc.in/run_requests | |
| require 'net/http' |
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
| Tempfile.new('pry-binding').tap do |binding_chord| | |
| binding_chord << 'Pry.toplevel_binding = binding' | |
| binding_chord.close | |
| load binding_chord.path | |
| ensure | |
| binding_chord.unlink | |
| 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 | |
| class Enumerator | |
| class Memoized < Enumerator | |
| INTERRUPT = defined?(IRB::Abort) ? IRB::Abort : Interrupt | |
| private_constant :INTERRUPT | |
| def initialize(enum) | |
| @original_inspect = enum.inspect | |
| @enum = cloned(enum) |
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 Enumerator | |
| class Memoized < Enumerator | |
| INTERRUPT = defined?(IRB::Abort) ? IRB::Abort : Interrupt | |
| private_constant :INTERRUPT | |
| module Refinement | |
| refine Enumerable do | |
| def memoized |
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
| ## | |
| # zsh | |
| autoload colors && colors | |
| autoload -Uz compinit && compinit -i | |
| autoload -Uz add-zsh-hook | |
| setopt auto_cd cdablevars beep nomatch notify | |
| setopt completeinword extendedglob globdots prompt_subst interactivecomments | |
| setopt appendhistory sharehistory incappendhistory hist_ignore_space hist_ignore_all_dups |
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] = 100_000_000 | |
| IRB.conf[:EVAL_HISTORY] = 100_000_000 | |
| IRB.conf[:PROMPT_MODE] = :SIMPLE | |
| IRB.conf[:PROMPT][:SIMPLE][:PROMPT_C] = '| ' | |
| # Use a proc rather than function for context to get refinements working. |
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
| # For "fun," a DRY metaprogrammed version | |
| class Product | |
| ATTRIBUTES = %i[name price] | |
| ATTRIBUTES.each { |attribute| attr_reader attribute } | |
| def initialize(**keywords) | |
| missing = ATTRIBUTES - keywords.keys | |
| if missing.any? | |
| message = "missing keywords: #{missing}.map(&:inspect).join(', ')" |
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 BeforeAll < Module | |
| def initialize(before_method) | |
| @before_method = before_method | |
| end | |
| def prepended(base) | |
| base.instance_methods(false).each do |method_name| | |
| this_method = base.instance_method(method_name) | |
| before_method = @before_method | |
| define_method(method_name) do |*args, **kwargs, &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
| #!/usr/bin/env ruby | |
| File.open IO::NULL, 'w' do |dev_null| | |
| File.readlines('samples.txt', chomp: true).each do |sample| | |
| sample_speed = rand(0.1..1.0) | |
| cmd = "play -v 1 \"#{sample}\"" | |
| puts cmd | |
| if rand(2).zero? | |
| Process.detach spawn(cmd, err: :out, out: dev_null) |
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 TildeCount | |
| refine Enumerable do | |
| alias ~@ count | |
| end | |
| end | |
| using TildeCount | |
| ~[] | |
| #=> 0 |