hipchat with software rendering
If you get this error message: “Hipchat could not initiate hardware for rendering video”, you can start hipchat with software rendering like this:
LIBGL_ALWAYS_SOFTWARE=1 hipchatzeus custom plan
I wanted that zeus would reload all my shared examples for each test. This required the following custom plan.
# ./custom_plan.rb
require 'zeus/rails'
class CustomPlan < Zeus::Rails
def test
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/controllers/shared_specs/**/*.rb')].each { |f| puts "reloading #{f}";load f }
super
end
end
Zeus.plan = CustomPlan.newTo get zeus to use it, add a zeus.json with the following content:
{
"command": "ruby -rubygems -r./path/to_your/custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"runner": ["r"],
"console": ["c"],
"server": ["s"],
"generate": ["g"],
"destroy": ["d"],
"dbconsole": []
},
"test_environment": {
"test_helper": {"test": ["test"]}
}
}
}
}
}ruby profiling with ruby-prof
Useful snippet to profile a piece of code:
RubyProf.start
results = RubyProf.stop
File.open "./#{Time.now.strftime("%H-%M-%S")}_res.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
endAfter this, you’ll have a timestamped file containing benchmark results. Really useful for optimization.
ruby command line filtering
I wanted to be able to filter the API calls that took longer than 1200ms from a logentries log. Lines are in the following format:
477 <158>1 2015-06-30T11:24:39.500691+00:00 heroku router - - at=info method=GET path="/api/users.json" host=somehost.name request_id=9bb472d6-c5d7-4f91-95ef-e795cf5ce17f fwd="some.ip.here" dyno=web.1 connect=2ms service=5815ms status=200 bytes=65518The following does the trick:
ruby -n -e 'print $_ if $_[/service=(\d+)/,1].to_f > 1200' < log_entries.logrbtrace ruby debug production mode
This can be useful to debug something in production mode. Add rbtrace to your Gemfile, and start your servers in production mode. In my case, I needed to debug unicorn in production mode. I did a:
ps aux | grep -i unicornAnd found the pid of one of the unicorn worker process. After that:
bundle exec rbtrace -p YOUR_PID -e 'puts Rails.env' # or whatever code you wantgolang time in different timezones
import "time"
// to get the current time in utc, iso8601
location, err := time.LoadLocation("Etc/UTC")
now := time.Now()
fmt.Println(now.In(location).Format(time.RFC3339)exposing a host service to a vagrant instance
I wanted to allow vagrant to connect to host’s postgres:
vagrant ssh -- -R 5432:localhost:5432getting the database representation's of true/false from ActiveRecord
Use this:
ActiveRecord::Base.connection.quote(true)or
ActiveRecord::Base.connection.quoted_trueor
ActiveRecord::Base.connection.quoted_false