Skip to content

Instantly share code, notes, and snippets.

View brand-it's full-sized avatar

Brandt Lareau brand-it

View GitHub Profile
brand-it / .irbrc
Last active November 7, 2023 06:39
.irbrc with a bunch of stuff I found useful. This is all sort of hacky but that kinda of the point. Do what you want take what you need. no need to be perfect
# frozen_string_literal: true
DEFAULT_EDITOR = 'code' unless defined?(DEFAULT_EDITOR)
class PrettyString < String
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 unless defined?(NO_COLOR)
unless defined?(ANSI_COLORS)
red: 31,
brand-it / have_scope.rb
Created April 7, 2023 17:08
A simple tool to make it easier to test scopes on models using rspec
# frozen_string_literal: true
# A quick and easy way to test scopes sql queries by checking only the sql output
# have_scope(:user, 1).include(' = 1')
# have_scope(:user, 1).match_array([user])
# have_scope(:user, 1).eq([user])
module RSpec
module Matchers
class HaveScope
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'uri'
require 'json'
require 'net/http'
require 'optparse'
require 'forwardable'
COMMAND_NAME = File.basename(__FILE__)
class SnowflakeId < ApplicationService
MAC_ADDRESS_PATTERN = /(?:(?:(?:[a-f0-9]{2}:){5})|(?:(?:[a-f0-9]{2}-){5}))[a-f0-9]{2}/i
MAC_ADDRESS = lambda {
address = RUBY_PLATFORM =~ /darwin/ ? `ifconfig` : `cat /sys/class/net/*/address`
NODE_ID = -> { (MAC_ADDRESS.to_i(16) % 1023).to_s(2).rjust(10, '0') }.call
SEQUENCE_STARTED_AT = 1671750375309
brand-it / install
Last active September 7, 2022 16:25
A simple tool to run rubocop on files you have changed
echo "Creating $(git rev-parse --git-dir)/hooks/pre-commit.d"
mkdir $(git rev-parse --git-dir)/hooks/pre-commit.d
echo "Downloading rubocop hook into $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop"
wget -O $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop
echo "Changing rubocop into a executable $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop"
chmod 755 $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop
echo "adding hooks_directory variable to $(git rev-parse --git-dir)/hooks/pre-commit if it does not already exist"
grep -qxF 'hooks_directory=$(git rev-parse --git-dir)/hooks/pre-commit.d' $(git rev-parse --git-dir)/hooks/pre-commit || echo 'hooks_directory=$(git rev-parse --git-dir)/hooks/pre-commit.d' >> $(git rev-parse --git-dir)/hooks/pre-commit
echo "adding $hooks_directory/rubocop variable to $(git rev-parse --git-dir)/hooks/pre-commit if it do
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'net/http'
require 'open-uri'
require 'tempfile'
require File.expand_path('ruby_bash', __dir__).to_s
options = {}
def format_as_table(header, data)
total_columns = data.first.size
data.insert(0, header) if header
column_widths = { |col| { |row| row[col].size }.max }
if header
data.insert(1,, '-').zip(column_widths).map { |a, b| a * b })
end do |row| do |cell, width|
brand-it / default_ruby_version.txt
Last active April 5, 2022 00:10
I use this to full my Alfred Workflows
brand-it / simple_gql_ruby.rb
Last active March 24, 2022 21:36
Simple tool for making GQL request with vanilla ruby
require 'uri'
require 'json'
require 'net/http'
class Gql
class Base
Response = do
def success?
brand-it / pretty_string.rb
Created March 12, 2022 00:52
I don't know who created this origionaly I but I know some one did. I did some googling to find the original but could not.
class PrettyString < String
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8