Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile

Keybase proof

I hereby claim:

  • I am stympy on github.
  • I am ben_curtis (https://keybase.io/ben_curtis) on keybase.
  • I have a public key whose fingerprint is FC63 ED9F FA43 9CD2 F58C 578C 3DDD 5CC4 C993 CF11

To claim this, I am signing this object:

@stympy
stympy / get_secrets.rb
Created October 12, 2016 19:15
Using KMS + S3 to store application secrets
begin
es3 = Aws::S3::Encryption::Client.new(kms_key_id: ENV['KMS_KEY_ID'])
YAML.load(es3.get_object(bucket: "yourbucket", key: "secrets.yml").body.read).each do |k, v|
ENV[k] ||= v # Don't override local ENV settings
end
rescue ArgumentError
# Raised when no KMS_KEY_ID was found in ENV, so there's nothing to do
rescue Aws::S3::Errors::NoSuchKey
# No secrets file was found, so there's nothing to do
end
@stympy
stympy / reload-cores.sh
Created March 2, 2016 21:37
Handy bits and bobs for recovering from a SolrCloud disaster
#!/usr/bin/bash
# We're only processing one solr collection named notices
for x in `seq 1 8`; do
curl "http://localhost:8983/solr/admin/cores?action=UNLOAD&core=notices_shard${x}_replica3
rm -rf /var/lib/solr/data/notices_shard${x}_replica3/*
mkdir -p /var/lib/solr/data/notices_shard${x}_replica3/data
@stympy
stympy / README.md
Created January 26, 2016 21:36 — forked from ralph-tice/README.md
SolrCloud backups

A little background on my context:

We run multiple Solr JVMs per box, which live in directories like:

/mnt/solr_8983
/mnt/solr_8984
/mnt/solr_8985
...
/mnt/solr_${PORT}
@stympy
stympy / solr_side_join.txt
Created December 21, 2015 12:56 — forked from phact/solr_side_join.txt
Solr Side Join to replace collections / dynamic fields
CREATE KEYSPACE IF NOT EXISTS docstore WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
CREATE TABLE IF NOT EXISTS docstore.metadata (
userid text,
docid text,
joinkey text,
title text,
body text,
PRIMARY KEY(userid, docid));
@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 / gist:f2dcb65a95c5a69a8a76
Created June 4, 2015 20:21
Undo all the migrations created on a branch, for cleaning up the db before switching branches
for x in `git diff --name-only master..head -- db/migrate | cut -d/ -f3 | cut -d_ -f1`; do rake db:migrate:down VERSION=$x; done
@stympy
stympy / gist:4b7537829da856e3e5f6
Created April 23, 2015 20:45
Sample Honeybadger payload
{
"notifier":{
"name":"Honeybadger Notifier",
"url":"https://github.com/honeybadger-io/honeybadger-ruby",
"version":"1.0.0"
},
"error":{
"class":"RuntimeError",
"message":"RuntimeError: This is a runtime error, generated by the crywolf app at 2012-09-26 17:25:24 -0700",
"tags":["wubba"],
@stympy
stympy / users_controller.rb
Created February 5, 2015 22:40
Notifying Honeybadger for access violations
class UsersController < ApplicationController
before_action :restrict_access, only: [ :new ]
protected
def restrict_access
if request.remote_ip != '127.0.0.1'
Honeybadger.notify(
error_class: "AccessError",
error_message: "Denied non-local access to users/new"
@stympy
stympy / idonethis.rb
Created July 31, 2014 12:59
Simple client for the iDoneThis API
#!/usr/bin/env ruby
require 'httparty'
require 'json'
class IDoneThis
include HTTParty
base_uri "https://idonethis.com/api/v0.0"
def initialize(token = ENV['IDONETHIS_API_KEY'])