Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
@stympy
stympy / .gitignore
Created December 21, 2012 13:10 — forked from karmi/.gitignore
.DS_Store
Gemfile.lock
*.pem
node.json
tmp/*
!tmp/.gitignore
@stympy
stympy / restore.sh
Last active December 11, 2015 17:58
Restoring a wal-e backup
export ENVDIR=/etc/wal-e.d/env
export PGDATA=/var/lib/postgresql/9.2/main
export LATEST=`envdir $ENVDIR wal-e backup-list | tail -1 | awk '{ print $3 }'`
/etc/init.d/postgresql stop
rm -rf $PGDATA
envdir $ENVDIR wal-e backup-fetch $PGDATA LATEST
envdir $ENVDIR wal-e wal-fetch $LATEST $PGDATA/pg_xlog/$LATEST
chmod 0700 $PGDATA

WAL-E needs to be installed on all machines, masters and slaves.

How to install WAL-E

Only one machine, the master, writes WAL segments via continuous archiving. The configuration for the master postgresql.conf is:

archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env wal-e wal-push %p'
archive_timeout = 60
@stympy
stympy / campfire.rb
Last active December 18, 2015 10:09
Easy post to a campfire room using faraday
class Campfire
def initialize(domain, token)
@client = Faraday.new(:url => "https://#{domain}.campfirenow.com") do |faraday|
faraday.basic_auth(token, 'X')
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end
end
def speak(room, message)
@stympy
stympy / strong_parameters.rb
Created October 11, 2013 18:02
Initializer for CanCan + Strong Parameters
# This makes CanCan play nicely with strong parameters in Rails 4
# From https://gist.github.com/mckeed/2878508
class ActionController::Base
# Use this with CanCan's load_resource to permit a set of params before
# it tries to build or update a resource with them.
#
# Usage:
# class BooksController < ApplicationController
# load_resource :book
@stympy
stympy / purge_campfire_files.rb
Created November 13, 2013 04:18
Delete all your files from campfire, with minimal dependencies
#!/usr/bin/env ruby
require 'json'
domain = 'YOUR_CAMPFIRE_SUBDOMAIN'
token = 'YOUR_CAMPFIRE_TOKEN'
room_id = 'CAMPFIRE_ROOM_ID'
while (uploads = JSON.parse(`curl https://#{token}:X@#{domain}.campfirenow.com/room/#{room_id}/uploads.json`)['uploads']).any? do
uploads.each { |u| `curl -X POST "https://#{token}:X@#{domain}.campfirenow.com/uploads/delete/#{u['id']}?n=0"`; sleep(0.5) }
@stympy
stympy / upgrade_pg.sh
Last active December 29, 2015 08:39
Upgrade postgres on OS X with homebrew
#!/bin/bash
# Do the upgrade
brew upgrade postgres
# Dump all the databases
pg_dumpall > pg.dump
# Stop the server
pg_ctl -D /usr/local/var/postgres stop
@stympy
stympy / helpscout_controller.rb
Created April 18, 2014 14:12
Simple Rails controller to return info from the database to be used in a Help Scout custom app
require 'base64'
require 'hmac-sha1'
class HelpscoutController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :verify_signature
def user
payload = JSON.parse(request.raw_post)
if payload['customer'] && payload['customer']['email'] && @user = User.where(email: payload['customer']['email']).first
@stympy
stympy / gist:4385e225e2b1fc3e14d7
Created July 3, 2014 13:02
Sending context with a Honeybadger error
begin
...
rescue ActiveRecord::RecordInvalid => e
Honeybadger.notify e, { context: { record: e.record.attributes } }
end
@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'])