Skip to content

Instantly share code, notes, and snippets.

@clarkdave
clarkdave / sorbet_sigil.rb
Last active September 3, 2023 14:31
RuboCop / Sorbet sigil rule
# typed: true
# @prettier
require 'sorbet-runtime'
# Put this somewhere like lib/rubocop/cop/lint/sorbet_sigil.rb and then
# require it in .rubocop.yml:
#
# require:
# - ./lib/rubocop/cop/lint/sorbet_sigil.rb
@clarkdave
clarkdave / logstash-sentry.rb
Last active May 15, 2023 11:34
(Logstash) Sentry output plugin
# The MIT License (MIT)
# Copyright (c) 2014 Dave Clark
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@clarkdave
clarkdave / load-balanced-pgbouncer-ecs.tf
Last active March 16, 2023 20:08
[Terraform] Load balanced PgBouncer service on Amazon ECS
#
# Reference implementation of a load balanced PgBouncer service on Amazon ECS
#
# see: https://engineering.loyaltylion.com/load-balanced-pgbouncer-service-on-amazon-ecs-f02120d1733e
#
resource "aws_lb" "pgbouncer" {
name = "${var.environment}-pgbouncer"
internal = true
load_balancer_type = "network"
@clarkdave
clarkdave / ecs-interactive-console.sh
Last active January 31, 2023 19:26
ecs-interactive-console
#!/bin/bash -e
##
# Use this annotated script a base for launching an interactive console task on Amazon ECS
#
# more info: https://engineering.loyaltylion.com/running-an-interactive-console-on-amazon-ecs-c692f321b14d
#
# Requirements:
# - `jq` must be installed on both the client and server
##
@clarkdave
clarkdave / pgsql-query-json-array.sql
Created March 26, 2014 16:05
(PostgreSQL) Query something in a JSON array in a WHERE clause
-- when you have a record which looks like this
--
-- id: 5,
-- properties: {
-- ages: [20, 30]
-- }
--
-- it is a bit of a pain if you need to query based on the contents of the "ages" array inside the JSON object "properties"
-- because PG currently lacks easy to use operators to work with JSON arrays
@clarkdave
clarkdave / createPages.ts
Created April 15, 2018 13:11
TypeScript + Gatsby node API
import { resolve } from 'path'
import { GatsbyCreatePages } from './types'
const createPages: GatsbyCreatePages = async ({
graphql,
boundActionCreators,
}) => {
const { createPage } = boundActionCreators
const allMarkdown = await graphql(`
@clarkdave
clarkdave / nconf-yaml.js
Created August 20, 2014 11:19
Load YAML config files using nconf (nodejs)
var nconf = require('nconf');
var yaml = require('js-yaml');
var app_config = __dirname + '../config/application.yml';
// load cmd line args and environment vars
nconf.argv().env();
// load a yaml file using a custom formatter
nconf.file({
@clarkdave
clarkdave / parseAndModifyHtml.js
Created May 6, 2011 21:24
Using node.js to parse HTML with jsdom and modify it with jQuery
/**
* npm install jsdom
* npm install jquery
*/
var html = "<!doctype html><html><body><h1>Hello world!</h1></body></html>";
/* parse the html and create a dom window */
var window = require('jsdom').jsdom(html, null, {
// standard options: disable loading other assets
@clarkdave
clarkdave / rabbitmq-queue-metrics.rb
Last active November 24, 2020 16:45
Monitoring thousands of queues with Datadog
#!/usr/bin/env ruby
require 'datadog/statsd'
require 'json'
statsd = Datadog::Statsd.new('localhost', 8125)
queue_fields = %w(
consumer_utilisation
consumers
@clarkdave
clarkdave / chef-insert-line-if-no-match.rb
Created June 13, 2013 11:12
[CHEF] Insert a line in a file if it doesn't already exist
line = '127.0.0.1 gateway.internal gateway'
file = Chef::Util::FileEdit.new('/etc/hosts')
file.insert_line_if_no_match(/#{line}/, line)
file.write_file