Skip to content

Instantly share code, notes, and snippets.

View keithpitt's full-sized avatar
🍔
This is not a burger

Keith Pitt keithpitt

🍔
This is not a burger
View GitHub Profile
require 'uri'
require 'net/http'
require 'net/https'
require 'json'
GRAPHQL_API_KEY = ENV.fetch("GRAPHQL_API_KEY")
def perform_graphql_query(query, variables)
# This is our Buildkite GraphQL Endpoint.
uri = URI.parse("https://graphql.buildkite.com/v1")
@keithpitt
keithpitt / database_state_loader.rb
Last active June 10, 2022 16:32
Note that this code only works with PostgreSQL, but it wouldn’t be too hard to adapt our approach for other relational databases.
# Add to `spec/support/database_state_loader.rb`
class DatabaseStateLoader
class EnvironmentError < RuntimeError; end
def self.load(path)
new(path).load
end
def initialize(path)
# Add this file to `spec/support/rails_log_splitter.rb`
require "stringio"
require "logger"
require "fileutils"
class RailsLogSplitter
def initialize(all: false)
@io = StringIO.new
@logger = Logger.new(@io)
class IDSequenceResetter
def reset(connection)
@cached_sql ||= {}
sql = @cached_sql[connection] ||=
begin
sequences = connection.execute(%{SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'}).values.flatten
"".tap do |sql|
sequences.each do |name|
next if not name.ends_with?("id_seq")
# Add this file to `spec/support/timecop.rb`
#
# Usage:
#
# it "should touch the `updated_at` attribute", :timecop do
# ...
# end
require 'timecop'
# Add this file to `spec/support/active_record_id_tracer.rb`
module ActiveRecordIDTracer
def insert(*args)
super(*args).tap do |returned_id|
Rails.logger.debug("\033[1m\033[33mActiveRecordIDTracer\033[0m #{klass.name} insert returned ID #{returned_id}")
end
end
end
# Add this file to `spec/support/simple_database_cleaner.rb`
class SimpleDatabaseCleaner
def clean(connection)
@cached_sql ||= {}
sql = @cached_sql[connection] ||=
begin
"".tap do |sql|
connection.tables.each do |table_name|
next if table_name == "schema_migrations".freeze
#!/usr/bin/env ruby
#
# Usage:
# ./flood --pipeline "my-org/bash-dumper" --api-key ... -n 20
require 'net/http'
require 'optparse'
require 'json'
options = { pipeline: "", api_key: "", endpoint: "https://api.buildkite.com", commit: "HEAD", branch: "master", number: 5 }
execve("./pty-test", ["./pty-test"], [/* 21 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x5fb988) = 0
sched_getaffinity(0, 8192, {1, 0, 0, 0}) = 32
mmap(0xc000000000, 65536, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc000000000
munmap(0xc000000000, 65536) = 0
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7f8851a000
mmap(0xc820000000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc820000000
mmap(0xc81fff8000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc81fff8000
mmap(0xc000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc000000000
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7f8850a000
execve("./pty-test", ["./pty-test"], [/* 20 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x5fb988) = 0
sched_getaffinity(0, 8192, {1, 0, 0, 0}) = 32
mmap(0xc000000000, 65536, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc000000000
munmap(0xc000000000, 65536) = 0
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f41063b8000
mmap(0xc820000000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc820000000
mmap(0xc81fff8000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc81fff8000
mmap(0xc000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xc000000000
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f41063a8000