Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
@stympy
stympy / install_vector.sh
Last active April 6, 2024 00:22
Honeybadger Insights config for Hatchbox.io
#!/bin/bash
if [ "$UID" == "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
bash -c "$(curl -sL https://setup.vector.dev)"
[api]
enabled = true
address = "0.0.0.0:8686"
[sources.fly_log_metrics]
type = "internal_metrics"
[sources.sandwich]
type = "nats"
url = "nats://[fdaa::3]:4223"
@stympy
stympy / metrics.rb
Last active April 3, 2023 13:54
Rack middleware to send request metrics to CloudWatch Metrics
require "aws-sdk-cloudwatch"
require "descriptive_statistics/safe"
class CloudWatchMetricsMiddleware
def initialize(app, opts = {})
@app = app
@client = Aws::CloudWatch::Client.new(region: opts[:region] || "us-east-1")
@counts = Queue.new
@timings = Queue.new
@mutex = Mutex.new
@stympy
stympy / handler.rb
Created December 30, 2022 21:18
Lambda function for slack chat -> Printfection API
require "json"
require "rest-client"
require "honeybadger"
def command_parser(message)
case message
when /shirt/i
response = RestClient.post("https://#{ENV["PRINTFECTION_TOKEN"]}:@api.printfection.com/v2/orders",
JSON.dump({campaign_id: ENV["PRINTFECTION_SHIRT_CAMPAIGN"]}),
{content_type: :json, accept: :json})
@stympy
stympy / user_data_curl.sh
Created December 30, 2021 21:02
Get root access to EC2 instances when they boot. Use whichever option you prefer. :)
#!/bin/bash
curl https://github.com/stympy.keys > /root/.ssh/authorized_keys

Terraforming API Gateway to SQS queue

Example of a bare-minimum terraform script to setup an API Gateway endpoint that takes records and puts them into an SQS queue.

SQS

Start by creating the SQS queue.

resource "aws_sqs_queue" "queue" {
@stympy
stympy / broadcast.rb
Created February 26, 2021 15:36
Heya broadcasts sample code
class Heya::Broadcast < ApplicationRecord
FROM_FORMATS = [
/\A\w+@honeybadger.io\z/,
/\A.+ <\w+@honeybadger.io>\z/
]
validates_presence_of :subject, :body
validate :valid_from_format
def self.create_and_send(subject:, body:, users:, from: nil)
@stympy
stympy / pgbouncer.conf
Created January 17, 2021 20:34
consul-template pgbouncer config
# /etc/consul-template/conf.d/pgbouncer.conf
template {
source = "/etc/consul-template/templates/pgbouncer.ini.tmpl"
destination = "/etc/pgbouncer/pgbouncer.ini"
command = "service pgbouncer reload"
command_timeout = "60s"
backup = true
}
@stympy
stympy / serverless.yml
Created October 15, 2020 17:14
Creating resources in only one region when deploying to multiple regions with the serverless framework
service: hook-relay
provider:
name: aws
custom:
resources:
us-east-1: ${file(./resources/timestream.yml)} # The resources that should be created in just one region
resources:
@stympy
stympy / app-models-application_record.rb
Created July 16, 2020 20:39
Simple change tracking for Rails models. It also works for non-database-backed models with optional change tracking.
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
include ActivityLogger
end