Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏴

Benoit Tigeot benoittgt

🏴
View GitHub Profile
@vlad-velciov
vlad-velciov / flakiness.rb
Last active December 10, 2018 10:46
retry_tests/lib/formatters/flakiness
# lib/formatters/flakiness.rb
require 'rspec/core/formatters/console_codes'
require 'rspec/core/formatters/documentation_formatter'
class Flakiness < RSpec::Core::Formatters::DocumentationFormatter
RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished,:example_passed, :example_pending, :example_failed
def example_passed(notification)
return super unless notification.example.metadata[:flaky]
output.puts flaky_output(notification.example)
@vojtad
vojtad / benchmarks.md
Created November 21, 2018 00:00
Rails JSON rendering benchmarks

Rendered JSON is ~250 KB in size.

Runtime benchmarks

Warming up --------------------------------------
   render json: data    20.000  i/100ms
render json: data.to_json
                        27.000  i/100ms
render json: ActiveSupport::JSON.encode(data)
                        26.000  i/100ms
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
begin
Integer("foo", exception: false)
def parse_int string, default
Integer(string, exception: false) || default
end
rescue TypeError
def parse_int string, default
Integer(string)
rescue
@marcotc
marcotc / query_caller.rb
Last active February 11, 2021 14:02
ActiveRecord debug query caller
::ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload|
puts " == Query : #{payload[:sql]}"
puts " == Caller: #{caller.reject{|x|x.include?('/gems/')||x.include?('/lib/ruby/')}.join("\n")}"
puts
end
@chrismaximin
chrismaximin / activerecord-inconsistent-caching.rb
Last active October 30, 2018 19:33
ActiveRecord inconsistent clearing of QueryCache
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
end
require "active_record"
@mmalek-sa
mmalek-sa / string_enums.rb
Created August 16, 2018 20:45
String enums are useful when you want to keep the actual string instead of integer in database, This gist add the validation to make sure users are passing correct values to model.
require 'active_support/concern'
module StringEnums
extend ActiveSupport::Concern
class_methods do
def string_enum(enums_hash)
enum_name = enums_hash.keys.first.to_s
define_singleton_method(enum_name.pluralize) do
@r00k
r00k / retro-questions.md
Last active May 27, 2022 21:59
Helpful retrospective (retro) questions

Retro Questions

  • KPI dashboard review
  • Since our last retro, what's gone well?
  • How do we feel about our productivity and work/life balance
  • How is the product better than last week?
  • How is the company better than last week?
  • Is there anything we should ask a consultant about?
  • How is the office/ops?
  • How can we enjoy the journey more?
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'benchmark-ips'
end
require 'active_record'
@jorgehatccrma
jorgehatccrma / recursive-resample.sh
Last active June 29, 2023 14:48
Recursively resample a bunch of audio files in a directory, using sox
#!/bin/bash
# A simple script to recursively resample a bunch of files
# in a directory. Only certain file extensions (mp3, aac,
# flac, wav) are considered.
#
# It takes 2 command line options: `indir` and `outdir`.
# The destination (`outdir`) is relative to the current
# directory of where you were when the script was run.
#