Skip to content

Instantly share code, notes, and snippets.

@kplawver
kplawver / .irbrc
Last active November 8, 2021 20:21
This is my personal .irbrc. It's fun.
class Object
def self.interesting_methods
self.public_methods.sort - Object.methods
end
def interesting_methods
self.public_methods.sort - Object.methods
end
end
desc "Checks ruby syntax on all files"
task :syntax_check do
puts "#{Dir.pwd}"
current_dir = Dir.pwd
files = []
["app", "config", "lib", "experiments", "spec"].each do |dir|
files = files + Dir.glob("#{current_dir}/#{dir}/**/*.rb")
end
puts "Testing #{files.length} files:"
@kplawver
kplawver / assets.rake
Created April 7, 2017 12:14
How to skip including the asset host when precompiling assets, which is pretty important if you use Heroku pipelines and your CDN is different between stages!
namespace :assets do
desc "Unsets the asset host, so it's not included in JS and CSS asset urls during precompile."
task :unset_asset_host => :environment do
ActionController::Base.asset_host = ""
end
Rake::Task["assets:precompile"].enhance(["assets:unset_asset_host"])
end

Keybase proof

I hereby claim:

  • I am kplawver on github.
  • I am kplawver (https://keybase.io/kplawver) on keybase.
  • I have a public key whose fingerprint is CF3C DF1D F19F 4783 F4C4 A779 C58F 5468 6FFC 6EBC

To claim this, I am signing this object:

@kplawver
kplawver / gitgc.rb
Created April 16, 2014 16:21
Have a lot of git repos around? This script will go clean them up for you.
# Running: ruby gitgc.rb and it'll do its thing.
#
# There's potentially a lot of output if you have a lot of directories
# and if you've never run git gc on them, it can take a while.
#
# Put the full paths of the directories where you keep git repos in the $STARTING_DIRS array:
# Example:
# $STARTING_DIRS = ["/Users/me/Documents/Projects"]
#
$STARTING_DIRS = []

The High Availability Switch: from MySQL+MMM to MariaDB+Galera Cluster

INSERT PICTURE Kevin Lawver, President @ Rails Machine, is our guest author for this post.

Few things feel worst than rolling out a High Availability (HA) system, then regularly seeing that system collapse. For our team at Rails Machine, this failing HA system was MySQL Multi-Master Replication (MMM).

We've been searching for a MMM replacement for a while, and a few months ago, we made the switch to MariaDB + Galera Cluster for High Availability MySQL. Here's the full story: the reasons why MMM doesn't work, why Galera Cluster does work, and our production takeaways.

MySQL Multi-Master Replication (MMM) is fundamentally broken

@kplawver
kplawver / flickr.com.js
Created July 15, 2013 16:42
A dotjs script for killing the new Yahoo toolbar on Flickr. Drop in your home directory/.js/flickr.com.js and say bye-bye to it. Don't know what dotjs is? See: https://github.com/defunkt/dotjs
function killYahooToolbar() {
$("#eyebrow").remove();
$("body").removeClass("with-eyebrow");
}
killYahooToolbar();
@kplawver
kplawver / index.html
Created February 13, 2012 21:11
Weird response from http://github.com
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" CONTENT="0.1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE></TITLE>
</HEAD>
@kplawver
kplawver / paginate_array.js
Created October 11, 2011 13:23
I needed to page through results in an array and couldn't find any simple pagination functions through the googles, so I wrote this. I hope it's useful!
function paginateArray(arr,page_num,per_page) {
var i,r=[];
if (arr.length < 1) {
return r;
}
if (per_page == undefined || per_page == null) {
per_page = 10;
}
@kplawver
kplawver / file_check_plugin.rb
Created December 7, 2010 15:00
A super simple Scout plugin to monitor just the existence of a file. We're using it to alert us when an NFS share goes down (if it times out, it's down).
class FileCheckPlugin < Scout::Plugin
OPTIONS=<<-EOS
file:
default: ~
name: File
notes: The file to check to make sure it exists.
EOS
def build_report