Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am davidakachaos on github.
  • I am doopysmurf (https://keybase.io/doopysmurf) on keybase.
  • I have a public key ASClLiGWIu6OPt0ZnkUuvPCQnGr-N0T6-Why0E5gJEtepAo

To claim this, I am signing this object:

@davidakachaos
davidakachaos / random_record.rb
Created September 13, 2017 13:38
Return a random ActiveRecord object
module ActiveRecord
class Base
def self.random(max_records = 10_000)
find(limit(max_records).pluck(primary_key).sample)
end
end
end
@davidakachaos
davidakachaos / pull-db.sh
Created September 12, 2017 15:02
Pull Heroku MySQL database to local (possible overwrite local development database)
#!/usr/bin/env bash
function join_by { local IFS="$1"; shift; echo "$*"; }
# Check for commands used by this script
command -v pv >/dev/null 2>&1 || { echo >&2 "I require pv but it's not installed. Aborting."; exit 1; }
command -v mysqldump >/dev/null 2>&1 || { echo >&2 "I require mysqldump but it's not installed. Aborting."; exit 1; }
command -v mysql >/dev/null 2>&1 || { echo >&2 "I require mysql but it's not installed. Aborting."; exit 1; }
stages=$(git remote | sed 's/origin//g' | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
stage_req=$1
@davidakachaos
davidakachaos / backup-database.sh
Created September 12, 2017 15:00
Backup Heroku MySQL to local
#!/usr/bin/env bash
function join_by { local IFS="$1"; shift; echo "$*"; }
# Check for commands used by this script
command -v pv >/dev/null 2>&1 || { echo >&2 "I require pv but it's not installed. Aborting."; exit 1; }
command -v mysqldump >/dev/null 2>&1 || { echo >&2 "I require mysqldump but it's not installed. Aborting."; exit 1; }
command -v gzip >/dev/null 2>&1 || { echo >&2 "I require gzip but it's not installed. Aborting."; exit 1; }
stages=$(git remote | sed 's/origin//g' | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
stage_req=$1
@davidakachaos
davidakachaos / migrate_when_needed_strategy.rb
Last active December 19, 2015 04:48
Custom Heroku deploy Strategy. Migrates the database only when needed. Needs heroku_san to work Needs to have all stages added as git remote! (via rake all heroku:remotes)
# Custom Heroku deploy Strategy
# Needs to have all stages added as git remote! (via rake all heroku:remotes)
if defined?(HerokuSan)
class MigrateWhenNeededStrategy < HerokuSan::Deploy::Base
def deploy
puts "[#{@stage.name}] Fetching current state."
`git fetch #{@stage.name}`
puts "[#{@stage.name}] Deploying..."
super
previous_sha_commit = `git rev-parse HEAD`.strip
@davidakachaos
davidakachaos / Gemfile
Created November 6, 2012 09:50
Guard spul
#### GEMFILE
#Gems for automating some tasks.
group :development, :test do
gem 'rb-fsevent', '~> 0.9.1'
gem "guard-bundler"
gem 'guard-rspec'
gem 'guard-rails'
gem 'growl'
gem "rspec", "~> 2.7"
gem 'rspec-rails', "~> 2.7"
@davidakachaos
davidakachaos / gist:754231
Created December 24, 2010 13:25
WsMailer
class WsMailer < ActionMailer::Base
def webservice_warning(webservice)
setup_email
@subject += "Webservice warning"
@body[:webservice] = webservice
end
def not_saved_report(saplogs)
def prepare_literal_token
str = ""
count = 1
#puts "prepare_literal_token..."
while count > 0 && !@io.eof
#puts "\t count: #{count} str: #{str.inspect}"
#raise "\t\t!!!!!!EOF!!!!!!" if str == '%%EOF'
chr = @io.read(1)
#break if @io.pos == eof_index
#raise "Chr found: #{chr.inspect} && str[-1,1] != \x5C #{str[-1,1] != "\x5C"}" if count > 4