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 ruby | |
require 'benchmark' | |
Benchmark.bm(20) do |b| | |
n = 10_000 | |
string = ('A' * n) + 'x' | |
b.report('String#include?(...))') do |
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 ruby | |
require 'optparse' | |
USAGE = "usage: #{$0} [options] GITHUB_REPO_URL [FILE]" | |
optparser = OptionParser.new do |opts| | |
opts.banner = USAGE | |
opts.separator '' |
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 bash | |
set -e | |
shopt -s globstar | |
github_user="FIXME" | |
orig_repo="FIXME" | |
new_repo="FIXME" | |
branch="main" |
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
begin | |
require 'bundler/inline' | |
rescue LoadError => error | |
abort error.message | |
end | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'therubyracer' | |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'socket' | |
Benchmark.bm(20) do |b| | |
n = 10_000_000 | |
def positional_args(one,two,three,four,five) | |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'strscan' | |
module Inflector | |
def self.gsub_camelize(name) | |
name = name.to_s.dup | |
# sourced from: https://github.com/dry-rb/dry-inflector/blob/c918f967ff82611da374eb0847a77b7e012d3fa8/lib/dry/inflector.rb#L329-L334 |
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
lib LibC | |
fun fork : PidT | |
fun wait(Int *) : PidT | |
fun waitpid(PidT, Int *, Int) : PidT | |
end | |
puts "Before fork" | |
pid = LibC.fork |
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 ruby | |
require 'benchmark' | |
require 'zlib' | |
Benchmark.bm(12) do |b| | |
n = 10_009_000 | |
str1 = 'A' | |
str2 = 'A' |
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 'resolv' | |
puts "Normal behavior:" | |
dns = Resolv::DNS.new | |
p dns.getaddresses('twitter.com') | |
# => [#<Resolv::IPv4 104.244.42.1>, #<Resolv::IPv4 104.244.42.193>] | |
puts "With search: option:" | |
dns = Resolv::DNS.new(search: ['.']) | |
p dns.getaddresses('twitter.com') |
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
$ cat test.rb | \irb | |
Switch to inspect mode. | |
true if 0...1 | |
(irb):1: warning: integer literal in conditional range | |
(irb):1: warning: integer literal in conditional range | |
nil | |
true if 1..2 | |
(irb):2: warning: integer literal in conditional range | |
(irb):2: warning: integer literal in conditional range | |
nil |