Skip to content

Instantly share code, notes, and snippets.

Avatar
⛏️
slogging through the issues

Postmodern postmodern

⛏️
slogging through the issues
View GitHub Profile
@postmodern
postmodern / array_addition_benchmark.rb
Created Aug 1, 2022
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 Mar 14, 2022
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 Mar 9, 2022
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 Jan 23, 2022
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 Dec 7, 2021
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 Oct 25, 2021
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
@postmodern
postmodern / camelize_benchmark.rb
Last active Jul 21, 2021
Benchmark of the String#gsub! based Inflector.camelize method vs. a StringScanner based method
View camelize_benchmark.rb
#!/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
@postmodern
postmodern / fork.cr
Created Jul 18, 2021
Example of adding fork back to Crystal
View fork.cr
lib LibC
fun fork : PidT
fun wait(Int *) : PidT
fun waitpid(PidT, Int *, Int) : PidT
end
puts "Before fork"
pid = LibC.fork
@postmodern
postmodern / string_building_benchmarks.rb
Last active Jul 12, 2021
Ruby String building benchmarks
View string_building_benchmarks.rb
#!/usr/bin/env ruby
require 'benchmark'
require 'zlib'
Benchmark.bm(12) do |b|
n = 10_009_000
str1 = 'A'
str2 = 'A'