Skip to content

Instantly share code, notes, and snippets.

@subimage
subimage / cap_util.rb
Created March 14, 2015 20:56
Capistrano task to upgrade all servers
namespace :util do
desc "apt software update"
task :apt_upgrade do
run "#{sudo} apt-get update -q"
run %Q\#{sudo} sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade -q -y\
end
end
@subimage
subimage / cap_rolling_restart.rb
Last active August 29, 2015 14:17
Capistrano rolling restart for passenger / nginx
desc "Restarts app servers in a rolling fashion, one by one with wait in between"
task :rolling_restart, roles: [:passenger] do
servers = find_servers_for_task(current_task)
servers.each do |s|
run "touch #{current_path}/tmp/restart.txt", hosts: s.host
puts "#{s.host} restarting...I'm sleep doe."
sleep 45
status = capture "sudo passenger-status; true", hosts: s.host
# Sometimes nginx/passenger is a bit wonky and fails to restart?
# Not sure if it's because of the load balancer fucking things up or what
@subimage
subimage / date_time_season.rb
Created April 29, 2015 23:32
Get the named 'season' for a Time / Date / DateTime in ruby
module DateTimeUtils
def season
case self.month
when 3, 4, 5
'Spring'
when 6, 7, 8
'Summer'
when 9, 10, 11
'Fall'
when 12, 1, 2
@subimage
subimage / check_image_hotlink_status.rb
Last active June 17, 2016 17:26
Check if an image can be hotlinked, or should be downloaded/not used.
@subimage
subimage / thread_counter.rb
Last active July 31, 2016 07:37
A threaded counter implementation in Ruby
#!/usr/bin/env ruby
require 'singleton'
require 'thread'
# Test to see if I remember how to use threads in Ruby properly
class ThreadCounter
include Singleton
NUM_THREADS = 4
@subimage
subimage / mysql-backup.sh
Last active May 9, 2017 21:09
UNIX bash shell script to store 30 days worth of MySQL backups on Amazon s3.
#!/bin/bash
# Backs up MySQL databases with zero downtime using Percona Xtrabackup.
# Stores 30 days worth on Amazon s3.
# These {{ double bracket }} things are Ansible/Jinja (ansible-vault) variables.
# Fill them in for your own usage.
MYSQLROOT=root
MYSQLPASS="{{ mysql_root_pass }}"
S3BUCKET={{ mysql_backup_bucket }}