Skip to content

Instantly share code, notes, and snippets.

fuzzy logic

Josh Goodall inopinatus

fuzzy logic
Block or report user

Report or block inopinatus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
inopinatus /
Last active Jul 17, 2019
crude little benchmark for parallelizing bundle-installed gems
TMPDIR="$(mktemp -d)"
CORES=$(sysctl -n hw.ncpu 2>/dev/null || nproc)
echo "==> testing with $CORES cores in $TMPDIR"
RUBY_VERSION=$(rbenv version-name)
TIME=$(which time)
inopinatus / taskable.rb
Last active Jul 13, 2019
Delegated relational composition for OR'ing polymorphic ActiveRecord associations
View taskable.rb
module Taskable
extend ActiveSupport::Concern
included do
has_many :tasks, as: :taskable
def tasks
task_relations.inject(super) do |this, rel|
inopinatus / remap_reviewer_ids.rb
Created Jul 1, 2019
example use of CTEs in object-rewriting migration
View remap_reviewer_ids.rb
def remap_reviewer_ids(table)
WITH reviewer_map AS (
SELECT reviewers.base_id, to_jsonb(array_agg(DISTINCT profiles.account_id))
FROM profiles
JOIN (SELECT jsonb_array_elements(options->'reviewer_ids')::text::int as reviewer_id, id AS base_id FROM #{table}) AS reviewers
ON reviewers.reviewer_id =
GROUP BY base_id
UPDATE #{table}
inopinatus / AllowDescribeNetworkInterfacesAndAssignIpv6Address
Last active Jun 28, 2019
OpWorks Stacks managed instance self-update to have IPv6 address.
View AllowDescribeNetworkInterfacesAndAssignIpv6Address
"Version": "2012-10-17",
"Statement": [
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
inopinatus / digest_queries.rb
Created Apr 25, 2019
SHA digest queries for ActiveRecord + postgresql
View digest_queries.rb
# frozen_string_literal: true
module DigestQueries
def predicate_builder
@predicate_builder ||= super.tap do |pb|
class DigestHandler
inopinatus / table_to_csv.rb
Last active Jun 28, 2019 — forked from sandys/table_to_csv.rb
convert a html table to CSV using ruby
View table_to_csv.rb
require 'rubygems'
require 'nokogiri'
require 'csv'
f ="table.html")
doc = Nokogiri::HTML(f)"output.csv", 'w') do |csv|
doc.xpath('//table/tbody/tr').each do |row|
tarray = []
View verify_and_decrypt_session_cookie52.rb
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'authenticated encrypted cookie'
encrypted_cookie_cipher = 'aes-256-gcm'
serializer = ActiveSupport::MessageEncryptor::NullSerializer
key_generator =, iterations: 1000)
inopinatus / simpsonian.rb
Last active Jun 28, 2019
ruby's little-known array parameter destructuring.
View simpsonian.rb
def list((head, *tail))
case tail.length
when 0
when 1
"#{list [head]} & #{list tail}"
"#{list [head]}, #{list tail}"
inopinatus / invoice.rb
Last active Jun 25, 2018
json models embedded in your activerecord models
View invoice.rb
class Invoice < ApplicationRecord
include JsonModel::Attribute
json_attribute_model :payment, Payment
validates_associated :payment
inopinatus / hash_proc_lookup.rb
Created Jun 21, 2018
Cheap lookups with Hash#to_proc
View hash_proc_lookup.rb
[:foo, :bar].map(&{ bar: "BAZ", foo: "QUUX" })
You can’t perform that action at this time.