Skip to content

Instantly share code, notes, and snippets.

class Equation
def initialize(*args)
@argset = args
end
attr_reader :argset
def sum
if @argset.length == 1

The Erlang VM only allows a limited set of expressions as guards:

  • comparison operators (==, !=, ===, !==, >, <, <=, >=);
  • boolean operators (and, or) and negation operators (not, !);
  • arithmetic operators (+, -, *, /);
  • <> and ++ as long as the left side is a literal;
  • the in operator;
  • all the following type check functions:
    • is_atom/1
  • is_binary/1
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'robot'
class RobotTest < MiniTest::Unit::TestCase
def test_has_name
assert_match /\w{2}\d{3}/, Robot.new.name
end
def test_name_sticks
class Anagram < Struct.new(:base)
def match(candidates)
candidates.select do |candidate|
word.anagram?(candidate)
end
end
def word
@word ||= AnagramWord.new(base)
end
require 'rspec'
class MinNaturalNumber
def initialize(*args)
@numbers = args
end
attr_reader :numbers
def solution
@marksim
marksim / string_calculator_spec.rb
Created June 18, 2013 03:16
String Calculator Pairing Kata with @shicholas
require 'rspec'
class StringCalculator
def initialize(string)
@string = string
end
def call
raise NoNegativesAllowed.new(numbers.select{|n| n < 0}) if numbers.any? {|n| n < 0}
numbers.inject(&:+).to_i
@marksim
marksim / tictactoe_spec.rb
Created June 15, 2013 03:18
My favorite TicTacToe implementation yet. Doing testing right results in better design.
require 'rspec'
class TicTacToe
def initialize
@x_moves = []
@o_moves = []
end
def play space
return false unless (1..9).include?(space)
@marksim
marksim / tictactoe_spec.rb
Created June 14, 2013 22:15
TicTacToe TDD from my pairing session with @willpragnell
require 'rspec'
class TicTacToe
def initialize
@x_moves = []
@o_moves = []
end
def play space
return false unless (1..9).include?(space)
return false if occupied?(space)
@marksim
marksim / README.md
Last active September 28, 2018 15:56
Pair Sessions Script Adding more security (automatically timeout sudo, append the command to each ssh key

My script for pair sessions on my box.

What it does

  • downloads the appropriate ssh keys from github
  • copies the appropriate 'ssh pair@your-external-ip' command to your clipboard (see Note #1)
  • sets up the tmux session
  • cleans up the session, and the keys after it's done

How to use