Skip to content

Instantly share code, notes, and snippets.

View HarlemSquirrel's full-sized avatar

Kevin McCormack HarlemSquirrel

View GitHub Profile
@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;
@HarlemSquirrel
HarlemSquirrel / pulseaudio-dlna.service
Last active September 20, 2023 22:03
a pulseaudio-dlna Unit file for systemd
## Systemd user unit file for pulseaudio-dlna
# Copy to: ~/.config/systemd/user/pulseaudio-dlna.service
# Enable: systemctl --user enable pulseaudio-dlna
[Unit]
Description=PulseAudio-DLNA Service
[Install]
WantedBy=default.target
require "redis-client"
##
# Emulate the methods of the Redis gem for HealthMonitor
# so we can use RedisClient gem instead.
#
class HealthMonitorRedisClient
def initialize
# REDIS_CONNECTION_SETTINGS should be defined elsewhere
@client = RedisClient.config(**REDIS_CONNECTION_SETTINGS).new_client
#!/usr/bin/env ruby
##
# Construct an exclusion search query for Datadog log search for Tenable IP address ranges.
#
# Datadog does not seem to be able to reliably use CIDR notation but
# if we know the start and end of each IP address range we can construct a single compound query.
# Here we retreive the latested published list of IP address ranges and filter that down to
# the short list of regions we care about.
#
@HarlemSquirrel
HarlemSquirrel / decimate.rb
Last active February 24, 2023 21:26
Ruby float and decimal math
##
# Run this with different versions of Ruby and BigDecimal to see different results.
#
# https://ruby-doc.org/3.2.1/exts/bigdecimal/BigDecimal.html
#
require "bigdecimal/util"
result_float_math = ((111.87 - 99) * 2)
puts "= Ruby v#{RUBY_VERSION}"
@HarlemSquirrel
HarlemSquirrel / tz_lookup_bench.rb
Last active February 22, 2023 18:43
Benchmarking time zone lookups
# frozen_string_literal: true
require "benchmark"
# https://github.com/zverok/wheretz
require "json" # Should be required by wheretz but it isn't currently
require "wheretz"
# https://github.com/HarlemSquirrel/tzf-rb
require "tzf"
@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