Skip to content

Instantly share code, notes, and snippets.

View gmr's full-sized avatar
:octocat:
🐘 🐇 🐍

Gavin M. Roy gmr

:octocat:
🐘 🐇 🐍
View GitHub Profile
@gmr
gmr / __init__.py
Last active October 21, 2015 19:09
Monkey-patch tornado async support into Botocore
"""
sprockets.clients.botocore
==========================
Asynchronous wrapper for botocore for use with Tornado. This module
monkey-patches in a new :py:func:`botocore.session.get_session` method that
returns an instance of :py:class:`sprockets.clients.botocore.AsyncSession` that
applies request adapters that use
:py:class:`tornado.httpclient.AsyncHTTPClient` for all requests. You can
configure the maximum number of concurrent HTTP requests that can be made
@gmr
gmr / amqp.py
Last active September 23, 2015 18:46
"""The PublishingMixin wraps RabbitMQ use into a request handler, with
methods to speed the development of publishing RabbitMQ messages.
Configured using two environment variables: ``AMQP_URL`` and ``AMQP_TIMEOUT``
``AMQP_URL`` is the AMQP url to connect to, defaults to
``amqp://guest:guest@localhost:5672/%2f``.
``AMQP_TIMEOUT`` is the number of seconds to wait until timing out when
connecting to RabbitMQ.
@gmr
gmr / add-travis.sh
Last active August 29, 2015 14:27
Script I'm using to add travis-ci support to RabbitMQ GitHub repositories. When all the tests pass, everything is automatic \o/. Sometimes the tests fail due to special cases in the tests with extra requirements. When that happens, I add those to the specific .travis.yml script, and then once passing, submit the PR.
#!/bin/bash
cd $1
hub fork
travis sync
travis enable -r gmr/$1
git checkout -b travis-ci-testing
cp ../.travis.yml .
git add .travis.yml
git commit -m 'Add travis-ci configuration' .travis.yml
git push gmr travis-ci-testing
@gmr
gmr / ssh-fail-drop.sh
Created July 27, 2015 03:23
Shell script that drops an IP in iptables INPUT when it's failed SSH login too many times
#!/usr/bin/bash
MAX_FAILURES=10
LINES=1000
DROPPED=`iptables -L INPUT -x -n | tail -n+3 | awk '{print $4}'`
already_blocked() {
local blocked
for blocked in ${2}; do
if [[ "$1" == "$blocked" ]]; then
return 0
@gmr
gmr / my.service
Created May 21, 2015 20:54
A fleetctl file that starts my service and registers it with consul, including the ephemeral port of the docker container :-\
[Unit]
Description=MyService Service
After=docker.service
Requires=docker.service
Requires=consul.service
Requires=datadog-agent.service
Requires=memcached.service
[Service]
TimeoutStartSec=0
@gmr
gmr / example.py
Last active August 29, 2015 14:21
Gracefully stopping a rabbitpy consumer from an external thread
import rabbitpy
import threading
import time
# Event that we'll set to tell the consumer to stop
stop_event = threading.Event()
# Method that will be invoked in 15 seconds to set the event
def set_stop_event():
print('Setting stop-event')
@gmr
gmr / registry.service
Created May 8, 2015 01:23
CoreOS Unit for Docker Registry
[Unit]
Description=Docker Registry
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill registry1
ExecStartPre=-/usr/bin/docker rm registry1
ExecStartPre=/usr/bin/docker pull registry
Custom TCP Rule
TCP
4369
sg-8abf3dee (Riak)
Custom TCP Rule
TCP
6000 - 7999
sg-8abf3dee (Riak)
@gmr
gmr / 0-example.ctmpl
Last active August 29, 2015 14:17
consul-template 0.7.1.dev issue with byKey - this gist contains the template, an example of the output, the expected output, the data, and the recursive output of the sample data from consul using "curl http://localhost:8500/v1/kv/sample/?recurse" to get the data
%YAML 1.2
---
Items:{{with $hostname := env "HOSTNAME"}}{{with $items := printf "sample/assignments/%s" ($hostname) }}{{range key $items | parseJSON}}
{{.}}:
connections: {{range service "rabbitmq"}}
- {{.Node}}{{end}}
foo: {{with $foo := printf "sample/items/%s/foo" (.)}}{{ key $foo }}{{end}}
{{with $baz := printf "sample/items/%s" (.)}}tree-key: {{$baz}}
{{range $key, $pairs := tree $baz | byKey}}{{$key}}:{{range $pairs}}
{{.Key}}: {{.Value}}{{end}}{{end}}{{end}}{{end}}{{end}}{{end}}
@gmr
gmr / Vagrantfile
Created March 9, 2015 23:53
RabbitMQ in Depth Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
$primary = <<SCRIPT
su vagrant -c 'cd /opt/rabbitmq-in-depth;git pull origin master'
SCRIPT
$secondary = <<SCRIPT
# Join it to the primary cluster node
rabbitmqctl stop_app