Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
natritmeyer / trex.rb
Last active December 19, 2015 21:28
Why dynamic languages are awesome
class Thing
def method_missing(method, *args, &block)
puts method.to_s.gsub /_/, " "
end
end
Thing.new.send <<-T_REX
_____________.-=-==--==--.
_______..-=="__,'o`)______`.
_____,'_________`"'_________\\
@natritmeyer
natritmeyer / vagrant_ssh_run_forked_process.sh
Created July 10, 2013 16:19
Run a process you want to fork in vagrant over ssh
vagrant ssh -c "nohup java -jar /vagrant/my_app.jar >> my_app.out 2>&1 &"
@natritmeyer
natritmeyer / get_messages_off_rabbitmq.rb
Last active February 16, 2024 13:52
Get messages off a RabbitMQ... Queue!
require 'httparty'
require 'json'
class QueueInspector
include HTTParty
basic_auth "guest", "guest"
base_uri "http://192.168.0.1:55672"
def messages
body = {'count' => 5,'requeue' => true, 'encoding' => 'auto', 'truncate' => 50000}.to_json
@natritmeyer
natritmeyer / ruby_ssl_error_solution.rb
Last active December 19, 2015 04:48
Failure/Error: response = http.request(request) OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: (null)
#Getting this?
<<-ANNOYING_ERROR
Failure/Error: response = http.request(request)
OpenSSL::SSL::SSLError:
SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: (null)
ANNOYING_ERROR
@natritmeyer
natritmeyer / ruby_time_duration_hack.rb
Created June 18, 2013 13:03
Converts a float/active_support-time to print a duration (ie: a date time that starts from 0000 instead of the epoch, ie: 1/1/1970)
require 'active_support/time'
def duration_of(input)
Time.at(input).gmtime.strftime "0000-00-00T%H:%M:%S"
end
duration_of 6.seconds #=> "0000-00-00T00:00:06"
duration_of 70.seconds #=> "0000-00-00T00:01:10"
duration_of 5.minutes #=> "0000-00-00T00:05:00"
@natritmeyer
natritmeyer / Rakefile
Created June 10, 2013 13:49
How to add task dependencies to custom rake tasks that don't allow for the normal rake task behaviour around setting task dependencies.
# Example Rakefile that demonstrates how to add task dependencies
# to custom rake tasks that don't allow for the normal rake task
# behaviour around setting task dependencies.
require 'cucumber/rake/task'
# here's the task that I want to run before any of my cucumber tasks (see below)
namespace :stub do
desc "Start stub required by features"
task :start do
@natritmeyer
natritmeyer / specific_version_of_library_in_homebrew.sh
Last active December 10, 2015 22:18
Install specific versions of a library from Homebrew
#substitute LIBNAME for the library you want. Eg: grails
brew tap homebrew/versions
brew versions LIBNAME
#2.1.2 git checkout 5c5b964 /usr/local/Library/Formula/grails.rb # <== we want this version
#2.1.3 git checkout d08ef78 /usr/local/Library/Formula/grails.rb
#2.1.1 git checkout 1bcf5af /usr/local/Library/Formula/grails.rb
#...
cd /usr/local
git checkout 5c5b964 Library/Formula/LIBNAME.rb # <== notice the hash, it's a reference to the version we want
@natritmeyer
natritmeyer / Rakefile
Last active December 10, 2015 18:19
Rake task for Reek
require 'reek/rake/task'
Reek::Rake::Task.new do |t|
t.config_files = "config.reek"
t.source_files = "**/*.rb"
t.fail_on_error = false
t.reek_opts = "-q" #only list smelly files
end
@natritmeyer
natritmeyer / Rakefile
Created December 6, 2012 10:04
Sinatra Stubs and Rake Tasks
require 'rspec/core/rake_task'
namespace :stubs do
namespace :schedule do
pid_file_path = "lib/stubs/schedule.pid"
desc "Start the schedule stub"
task :start do
`rackup -D lib/stubs/schedule.ru -P #{pid_file_path} -p 2000`
end
@natritmeyer
natritmeyer / time_zome_management.rb
Created August 29, 2012 21:18
Make your tests run in any timezone...
#in env.rb:
require 'active_support/time'
Time.zone = 'Europe/London'
#use in tests instead of `Time.now`:
Time.current #=> will output the time in London, regardless of the localhost's timezone