Skip to content

Instantly share code, notes, and snippets.

View hoff2's full-sized avatar

Charles Hoffman hoff2

  • Iowa
View GitHub Profile
@hoff2
hoff2 / gist:601302
Created September 28, 2010 16:21
Plugin migration suggestion
# it is my personal opinion that calling something a "plugin" implies that one should be able
# to "unplug" it as well. Therefore, rather than inserting my plugins' migrations into the
# stream of my app's plugins as is usually done with Desert, I prefer the method described
# in section 12.1 "Create A Custom Rake Task" of http://guides.rubyonrails.org/plugins.html.
# It seemed a bit un-DRY however, so here's a little something I drop in my plugins' lib
# directory:
module MigrationGetter
def with_migration_file(filename)
ActiveRecord::Migration.verbose =
@hoff2
hoff2 / gist:904266
Created April 5, 2011 19:00
save BLOBs to files
# Recently I was involved in rebuilding a client’s site that had previously used
# some old CMS system (in Java, source code not to be found) of our company’s,
# with our new one (in Ruby On Rails). I needed to reuse some of the original
# images. Turns out the old system kept images and various other files used on the
# site in the MySQL database, as BLOB objects. I came up with this quickie little
# script to pull the files out of the database and save then as good old fashioned
# files.
#!/usr/bin/env ruby
require 'rubygems'
@hoff2
hoff2 / gist:1259104
Created October 3, 2011 13:28
Rails's mysql connection pool running dry because Thread#wait return value changed in ruby 1.9
## Rails's mysql connection pool running dry because Thread#wait return value changed
## in ruby 1.9. This, by the way, is with Rails 2.3.14 so it's not just a 3.x thing
## https://rails.lighthouseapp.com/projects/8994/tickets/5736-connections-not-released-in-rails-3 edit
Processing WebpagesController#update (for 63.224.186.69 at 2011-10-02 15:16:48) [PUT]
[...parameters...]
Redirected to http://[redacted]/siteman/webpages/1/subpages
Completed in 26ms (DB: 19) | 302 Found [http://[redacted]/siteman/webpages/2]
/!\ FAILSAFE /!\ 2011-10-02 15:16:48 -0500
@hoff2
hoff2 / gist:1323195
Created October 28, 2011 19:13
overriding #call in the singleton class of a Proc, a bad idea in the first place, but also:
ruby-1.9.2-p290 :030 > a = proc{'eh'}
=> #<Proc:0x000001009ac850@(irb):30>
ruby-1.9.2-p290 :031 > a.()
=> "eh"
ruby-1.9.2-p290 :032 > a[]
=> "eh"
ruby-1.9.2-p290 :033 > a.call
=> "eh"
ruby-1.9.2-p290 :034 > def a.call; super + '?'; end
=> nil
@hoff2
hoff2 / fibs.rb
Created October 6, 2012 14:48
yay Enumerator
fibs = Enumerator.new do |y|
recent = [0,1]
loop do
y << recent.last
recent = (recent << recent[0..1].inject(:+)).pop(2)
end
end
fibs.first(20) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]
@hoff2
hoff2 / gist:5378506
Created April 13, 2013 13:58
Rails 3.2.13, Ruby 2.0.0-p0, "rake cucumber:ok" spits out this annoying stack trace at the end if there are failing steps. "cucumber features" does not.
1 scenario (1 failed)
5 steps (1 failed, 3 skipped, 1 passed)
0m0.438s
rake aborted!
Command failed with status (1): [/Users/charleshoffman/.rvm/rubies/ruby-2.0...]
/Users/charleshoffman/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/charleshoffman/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/Users/charleshoffman/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/Users/charleshoffman/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/Users/charleshoffman/.rvm/gems/ruby-2.0.0-p0@aggress/gems/cucumber-1.2.5/lib/cucumber/rake/task.rb:104:in `run'
@hoff2
hoff2 / app.rb
Created August 8, 2013 21:04
wrapping a sinatra app around a static web site
# for those times when you have a static web site but then it turns out you
# need a contact form or some such.
# just sticking the whole site in public/ gets you most of the way there --
# the web server just serves up anything it finds there without calling on
# your app for anything
# but that doesn't work for the default index.html page for paths like
# "/" or "/foo".
### Keybase proof
I hereby claim:
* I am hoff2 on github.
* I am centipedefarmer (https://keybase.io/centipedefarmer) on keybase.
* I have a public key whose fingerprint is 65EE EFFD F4FF 4B3B 6F37 82A3 F8E7 1C46 A007 9449
To claim this, I am signing this object:
@hoff2
hoff2 / gist:3a05a6bff6390d9ec1f6
Created January 6, 2016 20:59
Homebrew: "Error: undefined method `<' for nil:NilClass"
~ $ brew doctor
Error: undefined method `<' for nil:NilClass
Please report this bug:
https://git.io/brew-troubleshooting
/usr/local/Library/Homebrew/os/mac/xcode.rb:131:in `provides_autotools?'
/usr/local/Library/Homebrew/diagnostic.rb:1038:in `check_for_autoconf'
/usr/local/Library/Homebrew/cmd/doctor.rb:30:in `block in doctor'
/usr/local/Library/Homebrew/cmd/doctor.rb:23:in `each'
/usr/local/Library/Homebrew/cmd/doctor.rb:23:in `doctor'
/usr/local/Library/brew.rb:143:in `<main>'
~/dev/gripds-integration-tests(master) $ big up -d
run docker-compose -f /Users/chuckhoffman/dev/big/current-compose.yml up -d from "/Users/chuckhoffman/dev/big"
Starting big_zookeeper_1
Starting big_citydata-solr_1
Starting big_merchants-solr_1
Starting big_redis_1
Starting big_core-fetch_1
Starting big_dns_1
Starting big_hbase35_1
Starting big_grip-admin_1