Skip to content

Instantly share code, notes, and snippets.

View HarlemSquirrel's full-sized avatar

Kevin McCormack HarlemSquirrel

View GitHub Profile
@HarlemSquirrel
HarlemSquirrel / show_git_additions.rb
Created October 28, 2022 19:38
Show git additions/changes for the git diff from the main branch
##
#
# https://github.com/anolson/git_diff
require 'git_diff'
patch = `git diff main -U0 --diff-filter=AM`
diff = GitDiff.from_string(patch)
diff.files.each do |diff_file|
@HarlemSquirrel
HarlemSquirrel / location_bias_queries.rb
Created September 12, 2022 19:01
Compare location-biased autocomplete search results from Mapbox and Google Places
#!/usr/bin/env ruby
##
# Compare location-biased autocomplete search results from Mapbox and Google Places
#
require 'json'
require 'net/http'
QUERIES = [
@HarlemSquirrel
HarlemSquirrel / send_coverage_summary_to_dd.rb
Last active September 1, 2022 21:06
Send SimpleCov or CodeClimate test coverage summary metrics to Datadog
# /usr/bin/env ruby
begin
require "git"
require "datadog_api_client"
rescue LoadError
Gem.install "git"
Gem.install "datadog_api_client"
require "git"
@HarlemSquirrel
HarlemSquirrel / constant_sharing.rb
Created August 15, 2022 15:38
Sharing constants between classes in same namespace
module Youtube
API_KEY = Rails.application.credentials.youtube_api_key.freeze
end
module Youtube
class SomeClass
def call
puts API_KEY
end
end
@HarlemSquirrel
HarlemSquirrel / rspec-repeat.rb
Created January 5, 2022 22:11
Run one or more specs as many times as you need in a row.
#!/usr/bin/env ruby
##
# Run one or more specs as many times as you need in a row.
#
# The files are loaded just once for speed and
# failure counts are tracked and reported at the end.
#
# Provide the number of times and the file(s).
# i.e.
@HarlemSquirrel
HarlemSquirrel / find_present.rb
Created November 8, 2021 16:28
Enumerable#find_present extension for Rails
require 'rails'
# Return the first value from the block that evalues to present.
#
# objects = [OpenStruct.new(name: nil), OpenStruct.new(name: ' '), OpenStruct.new(name: 'Matz')]
# objects.find_present(&:name) # => "Matz"
module Enumerable
def find_present(&block)
each do |item|
result = yield(item)
@HarlemSquirrel
HarlemSquirrel / refresh_aws_mfa_creds.rb
Created June 8, 2021 16:04
Refresh AWS MFA credentials
#! /usr/bin/env ruby
##
# Retrieve MFA credentials using the default profile and saving them to the mfa profile.
# Old credentials are removed in this process.
#
require 'json'
AWS_CREDS_FILE_PATH = File.join(ENV['HOME'], '.aws/credentials')
@HarlemSquirrel
HarlemSquirrel / docker-compose.yml
Last active July 3, 2022 14:35
Valheim Server Docker Compose file
# https://github.com/sorisum/valheim-server-docker
version: "3.9"
services:
valheim:
image: lloesche/valheim-server
volumes:
- /mnt/valheim:/config
- valheim_data:/opt/valheim
ports:
- "2456-2458:2456-2458/udp"
@HarlemSquirrel
HarlemSquirrel / pre-commit
Last active January 4, 2022 17:58
A pre-commit file for Ruby on Rails applications
#!/bin/bash
#
# A set of commands to run as pre-commit hooks for git.
#
# Save this to .git/hooks/pre-commit and make executable to enable
#
# This will run whenever we run `git commit`.
# To skip this, add `-n` or `--no-verify` flag.
#
@HarlemSquirrel
HarlemSquirrel / OpenLDAPClient.java
Created December 11, 2020 22:49
Example doing paged search with UnboundID Java SDK and OpenLDAP
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPSearchException;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.controls.SimplePagedResultsControl;
import com.unboundid.util.ssl.SSLUtil;
import com.unboundid.util.ssl.TrustAllTrustManager;