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

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@rodreegez
rodreegez / gist:1818506
Created February 13, 2012 17:36
Ruby 1.9.2 Load paths

via Gregory Brown (@seacreature) on Twitter:

Wrong way to deal with the 1.9.2 removal of . from the loadpath:

  1. require "./foo/bar" forces you to run code from your project root
  2. $LOAD_PATH.unshift(".") recreates security issue, and pollutes

Right way to deal with the 1.9.2 removal of . from the loadpath:

  1. require_relative "foo/bar" if you don't need Ruby 1.8 compatibility
@canton7
canton7 / Sample DataMapper model.rb
Last active September 10, 2018 03:16
Sinatra Auth in a Box
# From bcrypt-ruby gem
require 'bcrypt'
class User
include DataMapper::Resource
attr_accessor :password, :password_confirmation
property :id, Serial
property :username, String, :required => true, :length => (2..32), :unique => true
property :password_hash, String, :length => 60
@taktran
taktran / mongomapper_cheatsheet.md
Created January 25, 2012 19:39
Mongomapper cheatsheet

Mongomapper cheatsheet

Mongomapper reference

Set up connection

require 'mongo_mapper'

def setup_mongo_connection(mongo_url)
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@canton7
canton7 / 0main.md
Last active November 7, 2023 08:16
Local versions of tracked config files

How to have local versions of tracked config files in git

This is a fairly common question, and there isn't a One True Answer.

These are the most common techniques:

If you can modify your application

@apeiros
apeiros / wav.rb
Created November 6, 2011 19:10
Fun with pure tones and WAV (see code after __END__)
class Numeric; def cap(min,max) return min if self < min; return max if self > max; self; end; end
class Wav
module Generators
end
def self.mnot(str)
tones = {
'C' => 264.0,
@AndrewVos
AndrewVos / install-irssi-on-ec2.sh
Created September 3, 2011 22:58
Installing IRSSI on ec2
# dependencies
sudo yum install pkg-config
sudo yum install perl-ExtUtils-Embed
# Download and extract latest irssi
wget http://irssi.org/files/irssi-0.8.15.tar.gz
tar tar -xzvf irssi-0.8.15.tar.gz
#configure and make
cd irssi-0.8.15
@igrigorik
igrigorik / hello.rb
Created February 27, 2011 03:01
goliath hello world example
require 'goliath'
class Hello < Goliath::API
# default to JSON output, allow Yaml as secondary
use Goliath::Rack::Render, ['json', 'yaml']
def response(env)
[200, {}, "Hello World"]
end
end