This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is when a refactoring really pays off. | |
* | |
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away). | |
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects. | |
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded | |
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example, | |
* for someone to later add logging around method invocations of that object, or timeouts, or whatever. | |
* | |
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but | |
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'hirb' | |
rescue LoadError | |
# Missing goodies, bummer | |
end | |
if defined? Hirb | |
# Dirty hack to support in-session Hirb.disable/enable | |
Hirb::View.instance_eval do | |
def enable_output_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bigdecimal' | |
require 'csv' | |
require 'pp' | |
class Stats | |
include Enumerable | |
def initialize(array) | |
standardize_array(array) | |
end |
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").
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# thin This shell script takes care of starting and stopping | |
# thin daemon from rbenv shared install | |
# | |
# chkconfig: 2345 85 15 | |
# description: thin is an Ruby web server | |
# config: /etc/sysconfig/thin | |
### BEGIN INIT INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gitlab 5.1: https://github.com/gitlabhq/gitlabhq/blob/5-1-stable/doc/install/installation.md | |
# Set up an AWS EC2 Ubuntu 12.04 LTS Server. | |
# Use ap-southeast-1b: spot pricing is smoother | |
# Log in as ubuntu@ | |
sudo apt-get -y update | |
sudo apt-get -y upgrade | |
# Install the required packages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Features | |
module MailHelpers | |
def last_email | |
ActionMailer::Base.deliveries[0] | |
end | |
# Can be used like: | |
# extract_token_from_email(:reset_password) | |
def extract_token_from_email(token_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -------------------------------------------------------------------------------------------- | |
# Installs Ruby using rbenv/ruby-build on the Raspberry Pi (Raspbian) | |
# | |
# Run from the web: | |
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh) | |
# -------------------------------------------------------------------------------------------- | |
# Set the Ruby version you want to install |
OlderNewer