Skip to content

Instantly share code, notes, and snippets.

View cdimartino's full-sized avatar

Chris DiMartino cdimartino

View GitHub Profile
@cdimartino
cdimartino / benchmark_concurrent_vs_mutex.rb
Created April 16, 2024 18:16
Benchmark manual Mutex vs Concurrent::Array
require "benchmark"
require "concurrent-ruby"
class Bench
def initialize(arrayish)
@arrayish = arrayish
end
def self.run
count = 100
def solution(number)
{
15 => "FizzBuzz",
5 => "Buzz",
3 => "Fizz",
}.select { number % _1 == 0 }.map { _2 }.first
end
raise unless solution(3) == "Fizz"
raise unless solution(5) == "Buzz"
# From https://gist.github.com/Schwad/44f01093e4fe7d8a083a0bc2ac246918
#
# Given Data:
# https://gist.githubusercontent.com/Schwad/9938bc64a88727a3ab2eaaf9ee63c99a/raw/6519e28c85820caac2684cfbec5fe4af33f179a4/rows_of_sweet_jams.csv
#
# Output:
# - Has the blog URLs as key values
# - Each blog URL key points to nested arrays.
# - The arrays each have a list of filenames and kilobyte values of songs found on that website.
# - An array's total megabytes cannot exceed 120. (This is the limit when burning an 80 minute audio CD!)
❯ export SKIP_SMART_DYNAMIC_EXAMPLES=false; for iter in `seq 1 5`; do /usr/bin/time rails runner 'puts :booted_without_database_calls'
booted_without_database_calls
14.25 real 8.50 user 3.98 sys
booted_without_database_calls
13.97 real 8.58 user 4.01 sys
booted_without_database_calls
14.04 real 8.56 user 4.05 sys
booted_without_database_calls
12.76 real 8.35 user 3.80 sys
booted_without_database_calls
@cdimartino
cdimartino / utf8_unique_index.md
Last active July 23, 2020 02:48
UTF8MB4 not properly indexing my 💩

TLDR;

Unique index containing an utf8mb4 encoded string are 🤮 due to improperly indexed 💩 value.

Database State:

All collations appear to be utf8mb4 compatible. Note also that innodb_large_prefix = on.

mysql> select version();
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.18.0.119
Master_User: rdsrepladmin
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin-changelog.182568
Read_Master_Log_Pos: 42797165
## Fetch Panels (with presigned url for read)
query {
currentUser{
panels {
nodes {
id
title
type
brandingAsset {
# frozen_string_literal: true
describe Smart::Representers::QuickTests::QuickTestTemplateRepresenterV1 do
let(:user) { create(:user) }
let(:study) { create(:study, :quick_test, last_updated_by: user) }
let(:quick_test_template) { create(:quick_test_template, :mobile_usability, study_template: study) }
let(:quick_test_form_item) { create(:quick_test_form_item, :url, quick_test_template: quick_test_template) }
let(:json) { described_class.new(quick_test_template).to_json }
around(:each) do |example|
Resolving dependencies...........
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
shoulda-matchers (~> 4.1.2) was resolved to 4.1.2, which depends on
activesupport (>= 4.2.0)
neo4j (~> 9.4.0) was resolved to 9.4.0, which depends on
activesupport (>= 4.0)
bullet was resolved to 5.7.5, which depends on
CREATE TABLE `demographic_groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`gender` int(11) NOT NULL DEFAULT '0',
`country` int(11) NOT NULL DEFAULT '0',
`expertise` int(11) NOT NULL DEFAULT '0',
`operating_system` int(11) NOT NULL DEFAULT '0',
`gaming_genre` int(11) NOT NULL DEFAULT '0',
`social_network` int(11) NOT NULL DEFAULT '0',
`web_browser` int(11) NOT NULL DEFAULT '0',
`min_income` int(11) DEFAULT NULL,