Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
@stevenharman
stevenharman / same-videos.sh
Created July 6, 2015 23:59
Compare a directory of large binary files (1080p HD video, in this case) to another set of those files to make sure they're byte-for-byte identical.
# Back story: I uploaded a dozen or so HD (1080p) movies to my Synology while across the country.
# Now I want to make sure the uploads all came through without corruption.
for video in *.mp4; do
cmp "./${video}" "/Volumes/video/Movies/${video}"
done
@stevenharman
stevenharman / expanding_raid_5_array.sh
Created March 31, 2015 00:03
Improving RAID Expansion speed (and wall clock time) on my Synology DS1515+.
# log the default values:
echo "speed_limit_max: `cat /proc/sys/dev/raid/speed_limit_max`" #=> 200000
echo "speed_limit_min: `cat /proc/sys/dev/raid/speed_limit_min`" #=> 10000
echo "stripe_cache_size: `/sys/block/md2/md/stripe_cache_size`" #=> 256
# update to use more RAM (Stripe Cache Size) and higher lower bound (speed_limit_min)
echo 100000 > /proc/sys/dev/raid/speed_limit_min
# This will result in more memory usage. bumping to 32768 resulted in ~512MB RAM increase.
echo 32768 > /sys/block/md2/md/stripe_cache_size
@stevenharman
stevenharman / burger-king.md
Last active February 28, 2018 12:46
Setting up a new Rails app, with thoughtbot/suspenders, and my own preferences.

A new Rails app

It goes a little something like this:

  1. rails new APP_NAME --database=postgresql --skip-test-unit
  2. suspenders APP_NAME --skip-git true --skip-keeps true --force

Then comes a whole bunch of customizing for my likes:

  1. unicorn -> puma
@stevenharman
stevenharman / dig-rustbyexample.log
Created December 13, 2014 15:33
rustbyexample.com DNS records, via Dig.
☺ $ dig rustbyexample.com +nostats +nocomments +nocmd
; <<>> DiG 9.8.3-P1 <<>> rustbyexample.com +nostats +nocomments +nocmd
;; global options: +cmd
;rustbyexample.com. IN A
rustbyexample.com. 3142 IN A 103.245.222.133
@stevenharman
stevenharman / heroku-multiple-accounts.md
Created October 8, 2014 18:56
Heroku Feature Request: Multiple emails for my account.

TL;DR: I would be great to get some soft of multi-account (or really, multi-email) support.

I have a personal account that I've used for personal and work in the past. But we (work) are now requiring only our company email addresses w/in our Heroku org to make auditing easier, and make accidentally inviting the wrong folks harder. This means I have to have two different accounts, but don't have a useful way to switch between them on either the CLI nor web dashboard. @ddollar's heroku-accounts is now officially not recommended, and intentionally broken when 2FA is enabled (heroku/heroku-two-factor#13). Painful!

I'd really like to be able to associate multiple email addresses with my account, a la GitHub.

  1. Is this something that's being considered?
  2. Are there any usable workarounds?

Thanks.

@stevenharman
stevenharman / nerd.rb
Last active August 29, 2015 14:04
Implementing the null object pattern on an ActiveRecord association. This is really a special case being represented with an object which acts like a null object.
class Nerd < ActiveRecord::Base
belongs_to :team, inverse_of: :nerds
def team
super || NullTeam.new
end
end
@stevenharman
stevenharman / bootstrap.sh
Created July 25, 2014 18:50
A bin/bootstrap script to install and configure Dnsmasq as a local DNS server for *.dev TLDs.
#!/bin/sh
brew_install_if_needed() {
package=$1
brew info $package | grep "Not installed" > /dev/null 2>&1
if [[ "$?" -eq "0" ]]; then
brew install $package
fi
}
@stevenharman
stevenharman / constraint_staff.rb
Last active September 2, 2015 16:41
Use Routing Constraints to limit access to Rails Routes. An example from Brewdega Cellar app.
module Constraint
class Staff
def matches?(request)
warden(request).authenticated? &&
warden(request).user.staff?
end
private
@stevenharman
stevenharman / keybase.md
Last active April 10, 2018 00:16
Keybase.io Proof

Keybase proof

I hereby claim:

  • I am stevenharman on github.
  • I am stevenharman (https://keybase.io/stevenharman) on keybase.
  • I have a public key whose fingerprint is 5CFB 7527 D9F9 87E2 3CFE C110 56CD A4F8 EF41 531E

To claim this, I am signing this object:

@stevenharman
stevenharman / hash_merge_block.rb
Created January 30, 2014 22:14
Ruby's Hash#merge with an optional block to resolve key conflicts.
# via @avdi's RubyTapas Episode 170: http://www.rubytapas.com/episodes/170-Hash-Merge
headers = <<END
Accept: */*
Set-Cookie: foo=42
Set-Cookie: bar=23
END
def parse_headers(headers)
headers.lines.reduce({}) { |result, line|