Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
preparing to release ruby-install 0.9.0 soon, and ronin 2.0.0 on Feb 1st

Postmodern postmodern

:shipit:
preparing to release ruby-install 0.9.0 soon, and ronin 2.0.0 on Feb 1st
View GitHub Profile
@postmodern
postmodern / benchmark.rb
Created February 23, 2023 02:23
Micro-benchmark for `value != nil` vs. `!value.nil?`
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
Benchmark.bm do |b|
n = 1_000_000
value1 = 1
value2 = nil
@postmodern
postmodern / benchmark.rb
Last active February 14, 2023 21:22
Ruby micro-benchmark for static vs. dynamic dispatch
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
class StaticDispatch
def dispatch
if rand > 0.5
method1
else
@postmodern
postmodern / Gemfile
Created October 17, 2022 21:21
Testing infinite responses with HEAD requests
View Gemfile
source 'https://rubygems.org/'
gem 'sinatra', '~> 2.0'
gem 'webrick'
gem 'thin'
gem 'puma'
gem 'unicorn'
@postmodern
postmodern / array_addition_benchmark.rb
Created August 1, 2022 00:45
Micro-benchmark to test different ways of adding Arrays
View array_addition_benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
Benchmark.bm do |b|
n = 1_000_000
array1 = [1,2,3,4,5,6]
array2 = [7,8,9,10,11,12,13,14]
array3 = [15,16,17,18,19,20]
@postmodern
postmodern / test.rb
Last active March 14, 2022 09:00
Discovered a weird ruby module constant scoping issue today.
View test.rb
TYPES: {:scope=>Namespace}
self::TYPES: {:scope=>Namespace::Mixin}
@postmodern
postmodern / benchmark.rb
Last active March 9, 2022 01:33
A micro-benchmark of Ruby's `String#include? || String#include?` vs. `String#=~ /[...]/`
View benchmark.rb
#!/usr/bin/env ruby
require 'benchmark'
Benchmark.bm(20) do |b|
n = 10_000
string = ('A' * n) + 'x'
b.report('String#include?(...))') do
@postmodern
postmodern / github_issues_to_markdown.rb
Last active January 23, 2022 09:42
Quick and dirty ruby script to parse a copy/pasted list of GitHub Issues and output a nicely formatted markdown list that can be pasted into a blog post
View github_issues_to_markdown.rb
#!/usr/bin/env ruby
require 'optparse'
USAGE = "usage: #{$0} [options] GITHUB_REPO_URL [FILE]"
optparser = OptionParser.new do |opts|
opts.banner = USAGE
opts.separator ''
@postmodern
postmodern / filter_repo.sh
Last active December 7, 2021 23:33
Boilerplate script for automating git-filter-repo
View filter_repo.sh
#!/usr/bin/env bash
set -e
shopt -s globstar
github_user="FIXME"
orig_repo="FIXME"
new_repo="FIXME"
branch="main"
@postmodern
postmodern / js_eval_hook.rb
Created October 25, 2021 21:45
Hook JavaScript's eval() using Ruby
View js_eval_hook.rb
begin
require 'bundler/inline'
rescue LoadError => error
abort error.message
end
gemfile do
source 'https://rubygems.org'
gem 'therubyracer'
end
View arguments_benchmark.rb
#!/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