Skip to content

Instantly share code, notes, and snippets.

@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@fnichol
fnichol / README.md
Created February 26, 2012 01:23
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects

Background

I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.

@nesquena
nesquena / basic.sql
Created September 7, 2011 01:56
PostgreSQL Common Utility Queries
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
@jt
jt / phone_number_regex.rb
Created June 5, 2011 19:49
Phone number regular expression pattern
def match(number)
/\+?(\d)?[-|\.|\s]?\(?(\d{3})\)?[-|\.|\s]?(\d{3})[-|\.|\s]?(\d{4})/.match number
end
# test match and captures against possibilities
[
['3335557777', nil, '333', '555', '7777'],
['333-555-7777', nil, '333', '555', '7777'],
['333.555.7777', nil, '333', '555', '7777'],
['333 555 7777', nil, '333', '555', '7777'],
@mrflip
mrflip / quickie_json_to_tsv
Created March 11, 2011 01:22
Here's a brittle but mostly-worky oneliner to turn a search result into an excel-loadable file
# run this in Terminal
curl "http://api.infochimps.com/social/network/tw/search/people_search?q=qualcomm&apikey=YOURAPIKEY" | ruby -rubygems -e 'require "json" ; $_ = $stdin.read.gsub(%r{^george_api_explorer\((.*)\)$}, "\\1") ; rows = JSON.load($_); ks= rows["results"].first.keys ; ks.sort! ; rows["results"].each{|row| puts row.values_at(*ks).map{|el| el.gsub(%r{[",]+},"") }.join(",") } ' > FILE_TO_SAVE_IN.csv