Skip to content

Instantly share code, notes, and snippets.

View HarlemSquirrel's full-sized avatar

Kevin McCormack HarlemSquirrel

View GitHub Profile
@HarlemSquirrel
HarlemSquirrel / health_check_client.ts
Last active March 28, 2025 17:18
TypeScript gRPC health check client
// https://github.com/grpc/grpc-node/tree/master/packages/grpc-health-check
import { service as healthServiceDefinition } from 'grpc-health-check';
// https://github.com/grpc/grpc-node/tree/master/packages/grpc-js
import { credentials, makeClientConstructor } from '@grpc/grpc-js';
const HealthClientConstructor = makeClientConstructor(healthServiceDefinition, 'grpc.health.v1.HealthService');
const serverAddress = '0.0.0.0:50051';
const healthClient = new HealthClientConstructor(serverAddress, credentials.createInsecure());
@HarlemSquirrel
HarlemSquirrel / something.rb
Created October 25, 2024 02:32
Single file code example with watcher
##
# Single file starter with broken test using only the Ruby standard library.
#
def mymeth(a,b)
a + b
end
require "minitest/autorun"
class TheTest < Minitest::Test
@HarlemSquirrel
HarlemSquirrel / print_gh_user_summaries.rb
Created September 27, 2024 16:10
An example use case for make multi-threaded HTTP requests and using shared variables
require "json"
require "net/http"
require "ostruct"
require "amazing_print"
user_summaries = []
req_total_ms = 0
host = "api.github.com"
@HarlemSquirrel
HarlemSquirrel / list_all_my_unarchived_repos.sh
Created September 17, 2024 00:25
List all my my GitHub repos that are not archived
gh api graphql --paginate -f query='
query {
viewer {
repositories(first: 100, isArchived: false) {
nodes { nameWithOwner }
}
}
}
' | jq -r '.data.viewer.repositories.nodes[]."nameWithOwner"'
@HarlemSquirrel
HarlemSquirrel / set-zen32-indicator-for-switch-with-onoff-state-overwrite.yaml
Last active July 1, 2024 23:51 — forked from sle118/set-zen32-indicator-for-switch-with-onoff-state-overwrite.yaml
Blueprint: Set Indicator on a ZEN32 Scene Controller button Based on Switch Status with on/off state overwrite
blueprint:
name: Set Indicator Light for SWITCH on Scene Controller with State Overwrite
description: For Zooz ZEN32. Sets the indicator color when switch is off or on.
domain: automation
input:
zooz_switch:
name: Zooz Switch
description: List of available Zooz ZEN32 switches.
selector:
device:
@HarlemSquirrel
HarlemSquirrel / karafka.rb
Last active May 9, 2024 17:47
Dynamic Karafka Subscription
# karafka.rb
class KarafkaApp < Karafka::App
setup do |config|
# setup
end
# Unique consumer group for our dynamic consumers
DYNAMIC_CONSUMER_GROUP_NAME = "#{ENV['KAFKA_PREFIX']}dyn-group"
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"