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 | |
# Author: @keithrbennett (Github) | |
# Illustrates how to respond to Unix signals in a Ruby program, using SIGUSR1 and SIGUSR2 | |
# for user-defined signals, and SIGINT for trapping Ctrl-C. | |
require 'awesome_print' | |
require 'json' | |
require 'yaml' |
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 | |
require 'nokogiri' | |
def process_example(message, xml_text, use_noblanks_option) | |
puts message | |
puts "XML text: #{xml_text.inspect}" | |
doc = Nokogiri::XML(xml_text) { |config| use_noblanks_option ? config.noblanks : config } | |
puts 'Resulting XML document:' | |
puts doc.inspect; puts; puts |
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 | |
REPO_URLS = %w{ | |
https://github.com/rubyforgood/casa | |
https://github.com/rubyforgood/cep-backend | |
https://github.com/rubyforgood/cep-ui | |
https://github.com/rubyforgood/circulate | |
https://github.com/rubyforgood/human-essentials | |
https://github.com/rubyforgood/shelter-assist |
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 | |
module M | |
class << self | |
attr_accessor :foo | |
end | |
end | |
class C1 | |
def call |
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 | |
# Run in directory containing `compar.c`, e.g. from https://github.com/ruby/ruby/blob/master/compar.c. | |
require 'etc' | |
WORDS = Ractor.make_shareable File.readlines('/usr/share/dict/words').map(&:chomp).map(&:downcase).sort | |
TRY_COUNT = Etc.nprocessors | |
puts "Measuring first sequentially on main ractor and then with #{TRY_COUNT} ractors:\n\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
#!/usr/bin/env ruby | |
# strip-zero-width-spaces.rb | |
# | |
# Removes Unicode "\u200B" zero width spaces; useful for copying source code from O'Reilly learning books | |
# | |
# Usage: | |
# | |
# strip-zero-width-spaces.rb < original_file > new_stripped_file |
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 | |
def bsearch(array, search_value) | |
lower_bound = 0 | |
upper_bound = array.length - 1 | |
n = 0 | |
while lower_bound < upper_bound | |
n += 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
#!/usr/bin/env ruby | |
# -------------------------------------------------------------------------------- | |
# test_iteration_constructs.rb | |
# | |
# Illustrates differences in behavior of some iteration constructs. | |
# @keithrbennett, 2021-02-01 | |
# | |
# Output is: | |
# |
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 | |
# git-project-url | |
# | |
# Outputs to stdout the project URL corresponding to a git remote URL. | |
# | |
# Example: | |
# | |
# (`open` is for Mac, use `xdg-open` on Linux, `start` on Windows) | |
# open $(git-project-url) # Opens 'origin' project page ('origin' is default) |
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 | |
require 'amazing_print' | |
require 'etc' | |
require 'set' | |
require 'shellwords' | |
require 'yaml' | |
raise "This script requires Ruby version 3 or later." unless RUBY_VERSION.split('.').first.to_i >= 3 |