Skip to content

Instantly share code, notes, and snippets.

View postmodern's full-sized avatar
🚧
working on Phase 2 (of Ronin)

Postmodern postmodern

🚧
working on Phase 2 (of Ronin)
View GitHub Profile
@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
#!/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
#!/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
begin
require 'bundler/inline'
rescue LoadError => error
abort error.message
end
gemfile do
source 'https://rubygems.org'
gem 'therubyracer'
end
#!/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 July 21, 2021 03:12
Benchmark of the String#gsub! based Inflector.camelize method vs. a StringScanner based method
#!/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 July 18, 2021 08:17
Example of adding fork back to Crystal
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 July 12, 2021 07:13
Ruby String building benchmarks
#!/usr/bin/env ruby
require 'benchmark'
require 'zlib'
Benchmark.bm(12) do |b|
n = 10_009_000
str1 = 'A'
str2 = 'A'
@postmodern
postmodern / resolv_weirdness.rb
Last active October 10, 2017 17:44
Resolv::DNS weirdness
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')
@postmodern
postmodern / catted.log
Last active November 17, 2016 04:36
Ruby 2.3 quirk in irb, pry, ripl (see https://twitter.com/josh_cheek/status/798658490235580416)
$ 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
@postmodern
postmodern / tcp_client.rs
Last active May 20, 2022 16:01
TCP Client in Rust
#![allow(unused_variables)]
#![allow(unused_imports)]
use std::env;
use std::process;
use std::thread;
use std::io::{self, Read, Write, Error};
use std::net::TcpStream;
use std::net::TcpListener;