Skip to content

Instantly share code, notes, and snippets.

View johncarney's full-sized avatar

John Carney johncarney

View GitHub Profile
@johncarney
johncarney / pre-push
Last active July 29, 2024 18:04
Git pre-push rubocop check
#!/bin/sh
# Passes all changed and added files on the current branch to RuboCop before pushing. Paste the below into your
# .bin/hooks/pre-push file, which should be made executable.
# Note that it assumes that your trunk branch is named "main." If this is not the case, make the appropriate adjustment.
TRUNK_BRANCH=main
CURRENT_BRANCH="$(git branch --show-current)"
if [ "$CURRENT_BRANCH" != "$TRUNK_BRANCH" ]; then
rubocop $(git diff --name-status "$TRUNK_BRANCH" "$CURRENT_BRANCH" | egrep '^[AM]' | cut -f 2 | egrep '(^Gemfile|.rb)$')
@johncarney
johncarney / presence_refinements.rb
Last active August 15, 2024 20:01
Simple drop-in refinements module that replicates Rails's presence methods
# frozen_string_literal: true
module PresenceRefinements
refine Object do
def blank? = (respond_to?(:empty?) ? !!empty? : !self)
def present? = !blank?
def presence = (self if present?)
end
# This bit is cribbed from https://github.com/rpanachi/core_ext
@johncarney
johncarney / macOS-security.sh
Last active September 4, 2025 15:06
Simple macOS secrets management
# I sometimes need to securely manage credentials for external services for work
# purposes and these need to be available in environment variables. It would be
# nice to think that I only need these credentials for non-production
# environments, but that is not always the case. Rather than using .env files
# or similar plaintext mechanisms, I use macOS's `security` tool to add
# these credentials to my login keychain and store them in environment
# variables.
# Add a generic password to yur macOS login keychain. You will be prompted
# to enter the password.