Skip to content

Instantly share code, notes, and snippets.

View copiousfreetime's full-sized avatar

Jeremy Hinegardner copiousfreetime

View GitHub Profile
require 'benchmark/ips'
# This is a quick bemchmark to compare the performance of ways to convert
# an integer to a base32 string, we want to comare a low-level way to do it
# that uses bit shifting and a high-level way that uses the Integer#digits
#
# Turns out using the digits(32) method is faster than using bit shifting...
# unless you turn on --yjit in which case the bit shifting loop is better
#
# Here are the results on my machine:
@copiousfreetime
copiousfreetime / searchable.rb
Created February 17, 2023 16:56
Searchable Model Concern for use with pg_search
module Searchable
extend ActiveSupport::Concern
included do
include PgSearch::Model
class_attribute :searchable_attributes, default: []
class_attribute :searchable_internal_attributes, default: []
multisearchable against: [
:searchable_attributes_text,
:custom_searchable_text
#!/usr/bin/env ruby
# Run this program on the commandline as:
#
# ruby day-1.rb <filename of csv>
#
# The output will be a prettified JSON representation of the result
#
require 'csv'
@copiousfreetime
copiousfreetime / README.md
Last active October 9, 2022 21:49
Replicating Heroku CI/CD + Review Apps

How to deal with missing Heroku CI/CD and Review Apps

The reason for this

In particular the update from 2022-04-26 23:54:00 UTC

For the protection of our customers, we will not be reconnecting to GitHub until we are certain that we can do so safely, **which may take some time

#!/usr/bin/env ruby
require 'optimist'
require 'thread'
require 'socket'
opts = Optimist::options do
opt :host, "Hostname to connect to", default: "127.0.0.1"
opt :port, "Port to connect to", default: 4332
opt :timeout, "Connection timeout", type: :integer
@copiousfreetime
copiousfreetime / 00_readme.md
Last active February 1, 2021 21:57
Fault Tolerant TCP Client

This is code associated with the blog post ...

@copiousfreetime
copiousfreetime / output.txt
Last active January 20, 2021 20:48
send vs. method invocation benchmark comparison
% bundle exec ./send-bench.rb
Warming up --------------------------------------
native 973.581k i/100ms
symbol 476.433k i/100ms
string 355.763k i/100ms
frozen 417.573k i/100ms
constant-frozen 356.666k i/100ms
instance_eval 738.433k i/100ms
singleton_method 468.459k i/100ms
subclass 794.878k i/100ms
@copiousfreetime
copiousfreetime / check-tsv.rb
Created August 31, 2020 00:01
check-tsv.rb
#!/usr/bin/env ruby
line_number = 0
unique_counts = Hash.new(0)
filename = ARGV.shift
abort "filename needed" unless filename
File.open(filename) do |f|
header = f.readline.strip
class CreatePgSearchDocuments < ActiveRecord::Migration[6.0]
def self.up
create_table :pg_search_documents do |t|
t.text :content
t.string :searchable_type
t.uuid :searchable_id
t.tsvector :content_tsvector
t.timestamps null: false
end
require 'logger'
class LogFormatter
MSG_FORMAT = "%s -- %5s : %s\n".freeze
DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%3N".freeze
attr_accessor :datetime_format
def initialize
@datetime_format = nil