Skip to content

Instantly share code, notes, and snippets.

View spikegrobstein's full-sized avatar

spike grobstein spikegrobstein

View GitHub Profile
@spikegrobstein
spikegrobstein / postgres_backup.sh
Created April 30, 2012 02:35 — forked from robertsosinski/daily.sh
PostgreSQL - Backup Util
#! /bin/bash -
####
## postgres_backup
## back up postgres on a regular basis
## USAGE:
## ./postgres_backup [ <prefix> ] [ <number_to_keep> ]
## prefix will default to 'pg'
## number_to_keep defaults to 2
##
@spikegrobstein
spikegrobstein / benzo.rb
Created November 16, 2012 16:13
Comparing benzo to cocaine
line = Benzo.line('createdb',
'-E :encoding' => @encoding,
'-O :owner' => @owner,
'-T :template' => @template,
':db_name' => @database )
@spikegrobstein
spikegrobstein / chef_compact.sh
Created November 16, 2012 23:39
Chef compaction script run via cron
#! /bin/bash -
curl -H "Content-Type: application/json" localhost:5984/chef
curl -H "Content-Type: application/json" -X POST http://localhost:5984/chef/_compact
sleep 3
for VIEW in nodes roles registrations clients data_bags data_bags_items users checksums cookbooks sandboxes environments id_map; do
curl -H "Content-Type: application/json" -X POST http://localhost:5984/chef/_compact/$VIEW
@spikegrobstein
spikegrobstein / couchdb.log
Created November 26, 2012 17:08
couchdb compaction log
[Mon, 26 Nov 2012 17:06:54 GMT] [info] [<0.18152.6>] Starting compaction for db "chef"
[Mon, 26 Nov 2012 17:06:54 GMT] [info] [<0.20248.6>] 127.0.0.1 - - 'POST' /chef/_compact 202
[Mon, 26 Nov 2012 17:06:54 GMT] [error] [emulator] Error in process <0.20250.6> with exit value: {{badmatch,no_valid_header},[{couch_db_updater,start_copy_compact,1}]}
[Mon, 26 Nov 2012 17:06:54 GMT] [error] [<0.20251.6>] ** Generic server <0.20251.6> terminating
** Last message in was {'EXIT',<0.20250.6>,
@spikegrobstein
spikegrobstein / resque-failed-iterator.rb
Created December 11, 2012 23:35
iterate through resque failed jobs
1.upto(Resque::Failure.count) do |i|
job = Resque::Failure.all(i)
# inspect failed job
args = job['payload']['args']
klass = job['payload']['class']
end
def get_quotes(block_of_text)
lines = block_of_text.split(/\n+/)
lines.map do |line|
m = line.match(/^(.+?):\s+(.+)$/) # match the line
next unless m # skip any lines that don't look like "some name: some text"
[ m[1], m[2] ]
end.compact
end
@spikegrobstein
spikegrobstein / nginx.conf
Last active September 22, 2023 04:19
nginx config for proxying requests for plex over a hostname-based virtualhost.
upstream plex-upstream {
# change plex-server.example.com:32400 to the hostname:port of your plex server.
# this can be "localhost:32400", for instance, if Plex is running on the same server as nginx.
server plex-server.example.com:32400;
}
server {
listen 80;
# server names for this server.
@spikegrobstein
spikegrobstein / deploy.rb
Last active December 16, 2015 16:20
Deploying to multiple environments in a single capistrano command
# This is such a hack. holy shit.
# use it like this:
# cap production deploy sandbox deploy
require 'capistrano/ext/multistage'
set :base_servers, @roles.clone
stages.each do |stage|
before(stage) do
@roles.replace(base_servers)
@spikegrobstein
spikegrobstein / class.pid_file.php
Created June 4, 2013 10:38
php code to ensure that only n instances of a process are running at a time.
<?
class PIDFileException extends Exception {}
class PIDFileSlotsExhaustedException extends PIDFileException {}
class PIDFileErrorException extends PIDFileException {}
class PIDFileNoBigDealException extends PIDFileException {}
class PIDFileBadPidException extends PIDFileErrorException {}
/**
*
## Profiler
## A wrapper for the rblineprof library to pretty-print the profile data
## and enable customization of the output
## Based heavily on tmm1's examples
## This assumes that rblineprof lib is installed in Rails.root + 'vendor/rblineprof/ext'
## https://github.com/tmm1/rblineprof
class Profiler
# see docs for self.log_line method
@@logger = Proc.new { |line| Rails.logger.info line }