This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'uri' | |
require 'json' | |
require 'net/http' | |
require 'optparse' | |
require 'forwardable' | |
COMMAND_NAME = File.basename(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A nice way to add color to strings | |
class PrettyString < String | |
# https://no-color.org/ | |
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 | |
ANSI_COLORS = { | |
white: 0, | |
red: 31, | |
green: 32, | |
yellow: 33, | |
blue: 34, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PrettyString.new('something').blue | |
# PrettyString.new('something').red | |
# PrettyString.new('something').green | |
# PrettyString.new('something').yellow | |
# PrettyString.new('something').magenta | |
# PrettyString.new('something').white | |
class PrettyString < String | |
# https://no-color.org/ | |
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 | |
ANSI_COLORS = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
MAX_COLUMNS_FOR_TABLE = 15 unless defined?(MAX_COLUMNS_FOR_TABLE) | |
DEFAULT_EDITOR = 'code' unless defined?(DEFAULT_EDITOR) | |
class PrettyString < String | |
# https://no-color.org/ | |
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 unless defined?(NO_COLOR) | |
unless defined?(ANSI_COLORS) | |
ANSI_COLORS = { | |
red: 31, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# A quick and easy way to test scopes sql queries by checking only the sql output | |
# | |
# is_expected.to have_scope(:user, 1).include('users.id = 1') | |
# is_expected.to have_scope(:user, 1).match_array([user]) | |
# is_expected.to have_scope(:user, 1).eq([user]) | |
module RSpec | |
module Matchers | |
class HaveScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | |
address.match(MAC_ADDRESS_PATTERN).to_s.delete(':') | |
}.call | |
NODE_ID = -> { (MAC_ADDRESS.to_i(16) % 1023).to_s(2).rjust(10, '0') }.call | |
SEQUENCE_STARTED_AT = 1671750375309 | |
COUNTER_MAX = 4096 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 https://gist.githubusercontent.com/brand-it/93d04c839238283e3e756811b9c9cee0/raw/616bf812b58bcefc52d564ed8abacbf30966193c/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Instructions: | |
# | |
# This script is a Git pre-commit hook that spell checks any content you are about to commit. | |
# | |
# Place this script into the ".git/hooks/" directory in your repository. It must be called "pre-commit" and be | |
# executable. A Git hook only works in a single repository. You need to copy this hook into every repository you wish to | |
# use it in manually. Optionally, you can set up a symlink in the ".git/hooks/" directory pointing to the script. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_as_table(header, data) | |
total_columns = data.first.size | |
data.insert(0, header) if header | |
column_widths = total_columns.times.map { |col| data.map { |row| row[col].size }.max } | |
if header | |
data.insert(1, Array.new(total_columns, '-').zip(column_widths).map { |a, b| a * b }) | |
end | |
data.map do |row| | |
row.zip(column_widths).map do |cell, width| | |
cell.to_s.ljust(width) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = {} |
NewerOlder