Skip to content

Instantly share code, notes, and snippets.


Benjamin Curtis stympy

View GitHub Profile

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.


Start by creating the SQS queue.

resource "aws_sqs_queue" "queue" {
stympy / broadcast.rb
Created Feb 26, 2021
Heya broadcasts sample code
View broadcast.rb
class Heya::Broadcast < ApplicationRecord
/\A.+ <\>\z/
validates_presence_of :subject, :body
validate :valid_from_format
def self.create_and_send(subject:, body:, users:, from: nil)
stympy / pgbouncer.conf
Created Jan 17, 2021
consul-template pgbouncer config
View pgbouncer.conf
# /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 / serverless.yml
Created Oct 15, 2020
Creating resources in only one region when deploying to multiple regions with the serverless framework
View serverless.yml
service: hook-relay
name: aws
us-east-1: ${file(./resources/timestream.yml)} # The resources that should be created in just one region
stympy / app-models-application_record.rb
Created Jul 16, 2020
Simple change tracking for Rails models. It also works for non-database-backed models with optional change tracking.
View app-models-application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
include ActivityLogger
stympy / url_checker.rb
Last active May 2, 2021
Ruby class to check URL validity
View url_checker.rb
require "ipaddr"
require "resolv"
require "uri"
class UrlChecker
SCHEME_REGEX =\Ahttps?/)
HOST_REGEX =\..+/)
IPV4_REGEX =[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/)
IPV6_REGEX =[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/)
PRIVATE_RANGES = %w[ 100.64
stympy / intercom-export.rb
Created Apr 23, 2020
Export data from Intercom
View intercom-export.rb
#!/usr/bin/env ruby
root = "/tmp/intercom"
IntercomClient.conversations.all.each do |c|
FileUtils.mkdir_p(path = "#{root}/conversations/#{}")"#{path}/#{}.json", "w") { |f| f.puts IntercomClient.conversations.find(id: }
stympy / active_record.rb
Last active Jul 26, 2019
Hiding sensitive query info -- specifically, RSA keys from Postgres queries
View active_record.rb
# Drop this in config/initializers/active_record.rb
class ActiveRecord::ActiveRecordError
def initialize(message = nil)
if message.respond_to?(:gsub)
super(message.gsub(/dearmor\(.*\)/im, '[FILTERED]'))
stympy /
Created Jul 12, 2019 — forked from naveenarun/
Function for sending a verbose slack message (containing path, command, error code, and custom message) after a process or series of processes exit
# Place this in your .bashrc
# Covers several corner cases such as nested apostrophes, history extraction in screens/subshells, Slack being down, etc.
# Strings to replace with your own credentials:
## {your email address} (1 instance)
## {slack webhook url} (1 instance)
## {your computer name} (2 instances)
slack() {
# Get slack message when a command exits
# Example usage: python; slack
stympy / handler.rb
Created Dec 27, 2018
Get a list of things from DynamoDB and render them in Lambda using Ruby
View handler.rb
require 'aws-sdk-dynamodb'
require 'erb'
DB =
Views = Hash[Dir['views/*'].map {|v| [ File.basename(v, '.html.erb').to_sym, ] }]
def list(event:, context:)
@rows = DB.scan({ table_name: ENV['TABLE_NAME'] }).result.items
{ headers: { 'Content-type' => 'text/html' }, statusCode: 200, body: render { Views[:table].result(binding) } }