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
def percentage_of_whole(part1, part2): | |
return float(part1) / (part1 + part2) * 100 |
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
def percentage_of_whole(part1, part2) | |
part1.to_f / (part1 + part2) * 100 | |
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
# Repair strings which won't encode into UTF-8 | |
text.gsub(/\x92/n, "'") | |
text.gsub(/\x97/n, ", ") |
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
optparse is deprecated. | |
use argparse. |
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
# | |
# Parse textual numbers into actual numbers | |
# | |
class NumberParser | |
ATOMS = { | |
'zero' => 0, | |
'one' => 1, | |
'two' => 2, | |
'three' => 3, | |
'four' => 4, |
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
# -*- coding: utf-8 -*- | |
require 'spec_helper' | |
describe Parsers::NumberParser do | |
before(:each) do | |
@p = Parsers::NumberParser.new | |
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
require 'rspec' | |
describe "Behaviour" do | |
it "should pass" do | |
true.should eq true | |
end | |
it "should fail" do | |
true.should eq false | |
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
source 'https://rubygems.org' | |
ruby '2.1.1' | |
gem 'rails', '4.1.0' | |
gem 'sass-rails', '~> 4.0.3' | |
gem 'uglifier', '>= 1.3.0' | |
gem 'coffee-rails', '~> 4.0.0' | |
gem 'jquery-rails' | |
gem 'jquery-ui-rails' | |
gem 'turbolinks' |
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
describe BetterCsv do | |
it 'has a nice API' do | |
parser = BetterCsv.parse('info.csv', headers: :first_row) | |
parser.each_row do |parse_result| | |
next if parse_result.error? | |
puts "Found the name and phone #: #{parse_result.name}, #{parse_result.telephone}" | |
end | |
end | |
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
import pytest | |
def product_index(request): | |
limit = request.GET.get('limit') | |
offset = request.GET.get('offset') | |
if limit and limit.isdigit(): | |
limit = int(limit) | |
else: | |
limit = 10 |