Skip to content

Instantly share code, notes, and snippets.

View hosh's full-sized avatar

Ho-Sheng Hsiao hosh

  • Remine
  • Phoenix, AZ
View GitHub Profile
hhh@sparkfly-rails3 ~/work/sparkfly/benchmarks/metaprogramming $ uname -a
Linux sparkfly-rails3 2.6.31-gentoo-r10 #1 SMP Fri Mar 26 23:55:26 Local time zone must be set--see zic x86_64 Intel(R) Core(TM)2 Duo CPU P8800 @ 2.66GHz GenuineIntel GNU/Linux
hhh@sparkfly-rails3 ~/work/sparkfly/benchmarks/metaprogramming $ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
hhh@sparkfly-rails3 ~/work/sparkfly/benchmarks/metaprogramming $ ruby bench_meta.rb
user system total real
instance_eval/str 68.230000 0.070000 68.300000 ( 88.718078)
class_eval/str 69.370000 0.050000 69.420000 ( 93.801272)
eval/str 70.800000 0.020000 70.820000 (100.582867)
define_method/class 48.570000 0.100000 48.670000 ( 65.632684)
@hosh
hosh / csv.rb
Created November 18, 2010 21:42
The worst kludge I've written in years.
# NOOP
#
# Place in RAILS_ROOT/lib/csv.rb
#
# Short Description: I dare you to remove this file.
#
# Long Description:
# This file is needed so that active_record/fixtures.rb (for AR3) can load 'csv' library. Since this file
# comes before the standard library load path, this gets loaded instead. Otherwise, Ruby will
# complain because FasterCSV has changed the class signature of CSV::Row
#http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
describe User do
subject { user }
let(:user) { User.new }
context "when name empty" do
it { should_not be_valid }
specify { user.save.should be_false }
end
@hosh
hosh / group_by_helper.rb
Created June 29, 2011 19:55
Group By Helper
# Ugly hack until PostgreSQL 9.1 comes out.
module Models
module GroupByHelper
extend ActiveSupport::Concern
included do
scope :group_by_all, lambda { group(self.column_names.map { |c| "#{self.table_name}.#{c}" }.join(',')) }
end
end
end
@hosh
hosh / example1.rb
Created August 26, 2011 18:15 — forked from defunkt/gist:2059
def explain!
puts 'Want to embed this Gist?'
puts 'Use this: <script src="http://gist.github.com/2059.js"></script>'
end
explain!
@hosh
hosh / gist:2285755
Created April 2, 2012 17:58
What is Devops?
Devops is for people who want to get their product out to their customers.
Devops is...
1. Software Eats Infrastructure.
http://online.wsj.com/article/SB10001424053111903480904576512250915629460.html
2. Disposable Resources.
@hosh
hosh / Gemfile
Created July 31, 2012 19:39
Gemfile.local
# Add this snippet at the bottom of your Gemfile
# This allows you to add gems for debugging that you may not want to
# version.
# If you want to load debugging tools into the bundle exec sandbox,
# add these additional dependencies into Gemfile.local
eval(IO.read(__FILE__ + '.local'), binding) if File.exists?(__FILE__ + '.local')
Migrating from Chef 10 to Chef 11
Strategy
We stand up a new Chef 11 server. We then download all the artifacts and data from Chef 10 using knife download, and then upload them to the Chef 11 server using knife upload. Since the data is saved into a repo before uploading, we can verify the data and modify it as needed.
Considerations
Chef 10 uses CouchDB. Chef 11 uses PostgreSQL. There are also changes in the underlying data. However, the data from the API are communicated in JSON and knife knows how to handle the differences between Chef 10 and 11. `knife upload` and `knife download` in knife-essentials will take us most of the way there.
-- Copyright 2013 Opscode, Inc. All Rights Reserved.
--
-- This file is provided to you under the Apache License,
-- Version 2.0 (the "License"); you may not use this file
-- except in compliance with the License. You may obtain
-- a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
Failures:
1) Search API endpoint /search/node POST targeted toward many nodes with body of {"possibly_nested"=>["top", "middle", "bottom"], "the_name"=>["name"], "not_found"=>["foo", "bar", "baz", "totally_not
_a_real_field"], "empty"=>[]} should succeed, and return multiple nodes
Failure/Error: r.should look_like search_success_response
Expected a full match of the result
{"total"=>4,
"start"=>0,