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 / helpscout-export.rb
Last active June 28, 2023 16:44
Script to export helpscout data
#!/usr/bin/env ruby
require 'helpscout'
require 'fileutils'
api_key = ARGV[0]
helpscout = HelpScout::Client.new(api_key)
helpscout.mailboxes.each do |box|
FileUtils.mkdir(box.name) unless File.exists?(box.name)
puts "Fetching #{helpscout.conversation_count(box.id, 'all', nil)} conversations for #{box.name}"
@stympy
stympy / session_cookie_dump.rb
Created January 31, 2012 22:06
Rails utility class for manually decoding session cookie values
@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 / skcluster.rb
Created February 8, 2017 20:53
Sidekiq cluster control script and systemd service
#!/usr/bin/env ruby
require 'sidekiq'
require 'sidekiq/cli'
# Default to running one process per core
def process_count
return ENV['SK_PROCESS_COUNT'].to_i unless ENV['SK_PROCESS_COUNT'].to_i == 0
case RbConfig::CONFIG['host_os']
@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 / instance-iam-policy.json
Last active April 14, 2022 17:29
Cleanly scaling in instances that are running Sidekiq
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"autoscaling:CompleteLifecycleAction",
"autoscaling:RecordLifecycleActionHeartbeat"
],
"Effect": "Allow",
"Resource": "*"
@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" {