Skip to content

Instantly share code, notes, and snippets.

View danigro77's full-sized avatar

Daniela Kohls danigro77

View GitHub Profile
@kschlarman
kschlarman / benchmark.md
Created September 11, 2012 02:11
The Benchmark Module

##Benchmark The benchmark module provides an easy way to time how long your Ruby code takes to run. In this example, I will use the bm method to generate sequential reports with labels.

This bit of code compares two different ways to concatenate strings. It times how long it takes to concatenate a period at the end of a string of 10,000 a's, one million times in a row. The label for the each test is passed into the report method.

require 'benchmark'

Benchmark.bm do |x|
 # Test for concatenation with +=
@gabrielgrant
gabrielgrant / postinstall
Created July 29, 2012 19:38
Postinstall script to put dotCloud DB settings into Rails' database.yml
#! /usr/bin/env ruby
require 'yaml'
environment = YAML.load_file('../environment.yml')
database = YAML.load_file('config/database.yml')
prod_db = database['production']
prod_db['username'] = environment['DOTCLOUD_DB_SQL_LOGIN']
prod_db['password'] = environment['DOTCLOUD_DB_SQL_PASSWORD']
prod_db['host'] = environment['DOTCLOUD_DB_SQL_HOST']
prod_db['port'] = Integer(environment['DOTCLOUD_DB_SQL_PORT'])