Skip to content

Instantly share code, notes, and snippets.

# This computes the sum of the integers from a through b:
def sum_integers(a,b)
return 0 if a > b
a + sum_integers((a+1), b)
end
puts sum_integers(1,10)

RVM and Bash

Post-installation line

The rvm installation documentation instructs you to put the following line at the very end of your bash profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

For those, like me, who are not very familiar with bash scripting, this is what the line above does: [[ condition ]] evaluates the condition inside the double brackets and returns true or false. The option -s file tells bash to look for file and decide whether it exists and is nonempty. So the line [[ -s "$HOME/.rvm/scripts/rvm" ]] looks inside the default rvm scripts folder ~/.rvm/scripts/ for rvm, and returns true or false.

require 'sinatra/base'
require 'erb'
class CIJoe
class Server < Sinatra::Base
[...]
def self.project_path=(project_path)
# next line does something screwy
user, pass = Config.cijoe(project_path).user.to_s, Config.cijoe(project_path).pass.to_s
if user != '' && pass != ''
Then /^the (\d+)(?:st|nd|rd|th) post title should be "([^"]*)"$/ do |pos, title|
with_scope(".blog_info_top:nth-of-type(#{pos.to_i})") do
if page.respond_to? :should
page.should have_content(title)
else
assert page.has_content?(title)
end
end
end
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
[[ -r "$rvm_path/scripts/completion" ]] && . "$rvm_path/scripts/completion"
[[ -r "$PWD/.rvmrc" ]] && . "$PWD/.rvmrc"
require 'spec_helper'
describe User do
let(:user) { User.new }
subject{ user }
# I just ripped off the deep_merge core extension from activesupport.
# The file is 'activesupport-3.0.3/lib/active_support/core_ext/hash/deep_merge.rb'
class Hash
# Returns a new hash with +self+ and +other_hash+ merged recursively.
def deep_merge(other_hash)
dup.deep_merge!(other_hash)
end
# Returns a new hash with +self+ and +other_hash+ merged recursively.
irb(main):009:0> puts RubyVM::InstructionSequence.new("class Person;def to_s;'bob';end;end;person=Person.new;person.to_s").disassemble
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] person
0000 trace 1 ( 1)
0002 putspecialobject 3
0004 putnil
0005 defineclass :Person, <class:Person>, 0
0009 pop
0010 trace 1
# Turn off welcome message
startup_message off
# Enable scrollback with Shift+PgUp, Shift+PgDn and scrollwheel
termcapinfo xterm* ti@:te@
# Fix for residual editor text
# When you open a text editor like Vim in screen and then close it, the text
# may stay visible in your terminal. To fix this, set altscreen on.
altscreen on
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set list
set listchars=tab:▸-,trail:-,eol:¬
let mapleader = ","
set nocompatible " use vim defaults
set scrolloff=3 " keep 3 lines when scrolling