Skip to content

Instantly share code, notes, and snippets.

View Lockyy's full-sized avatar
🏳️‍🌈

Naomi Lockhart Lockyy

🏳️‍🌈
  • London, United Kingdom
  • 01:57 (UTC +01:00)
View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@Lockyy
Lockyy / rspec-changed.sh
Last active June 15, 2023 09:25
Uses files-diff to retrieve a list of changed files and then filters it down to runnable specs then runs them
#!/bin/bash
changedSpecFiles=$(files-diff | grep '^spec' | grep -v 'spec/support' | grep -v 'spec/factories')
joinedSpecFileNames=$($changedSpecFiles | tr "\n" " ")
spring rspec "$@" $($joinedSpecFileNames)
@Lockyy
Lockyy / files-diff.sh
Last active June 6, 2023 16:16
Outputs a list of all files changed between your current HEAD and develop
#!/bin/bash
git diff --name-only --diff-filter=d main...
@Lockyy
Lockyy / gist:d35c82c489c165ee5fae50ca83c5b2ff
Last active June 6, 2023 16:20
Git blame addition or removal of string in file
git log -S <string> path/to/file
@Lockyy
Lockyy / Auto-fail on focused specs
Last active June 6, 2023 16:21
Triggers a failure automatically when a focused spec is encountered
if ENV['CI']
config.before(:example, :focus) {
raise "You've added a focused spec to a commit, this'll prevent CI from running properly and you should remove this."
}
else
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
@Lockyy
Lockyy / colorize_string_monkey_patch.rb
Last active June 6, 2023 16:21
Monkey patch to add `.red`/`.green`/`.yellow` to the String class to color strings on console output
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
namespace :db do
desc 'Dumps the database to db/backups'
task :dump, [:backup_name] => :environment do |_task, args|
params = gather_required_data(args)
cmd = [
'pg_dump',
'-F c',
'-v',
'-h', params[:host],
@Lockyy
Lockyy / to_age.rb
Last active June 6, 2023 16:23
Monkey patch onto Date/Time/DateTime objects to allow them to be converted to an age, accommodating for leap years
def to_age
today = Time.current
year_diff = today.year - year
today_is_past_birthday = today.month > month || (today.month == month && today.day >= day)
today_is_past_birthday ? year_diff : year_diff - 1
end
@Lockyy
Lockyy / reekchanged.sh
Last active June 6, 2023 16:23
Run Reek on files that've changed in Git
#!/bin/bash
reek --force-exclusion "$@" $(git status --porcelain | sed s/^...//)
@Lockyy
Lockyy / copchanged.sh
Last active June 6, 2023 16:23
Run Rubocop on files that've changed in Git
#!/bin/bash
rubocop $(git diff --name-only --diff-filter=d main...) --force-exclusion "$@"