Skip to content

Instantly share code, notes, and snippets.

class Title
def initialize(string)
@string = string
end
def fix
small_words = %w(of a and the an)
new_title = []
@string.downcase.split.each_with_index do |element, index|
@dogweather
dogweather / Gemfile
Created April 21, 2014 17:46
Rails 4.1.0 + SASS + SASS-Rails
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'
@dogweather
dogweather / better_csv_spec.rb
Created May 7, 2014 19:50
A first pass at a CSV API which provides header-based access plus error handling
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
@dogweather
dogweather / controller1.py
Last active August 29, 2015 14:06
The controller code as originally written, with a small test suite
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
@dogweather
dogweather / controller2.py
Last active August 29, 2015 14:06
After some refactoring to make DRY, enable re-use, and keep similar abstractions together
import pytest
def product_index(request):
limit = parse_parameter(request, 'limit', int, default=10)
offset = parse_parameter(request, 'offset', int, default=0)
return limit, offset
def parse_parameter(request, name, klass, default=None):
try:
return klass(request.GET.get(name, default))
@dogweather
dogweather / ipython-output.py
Created October 13, 2014 20:09
Using ipython to learn about the String class
pluto:~ $ ipython
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
@dogweather
dogweather / csv_test.rb
Created November 26, 2014 22:30
An automated test which verifies compliance with the LIVES standard
require 'test_helper'
describe 'csv' do
describe 'encoder' do
it 'should properly enclose quotes and commas' do
# From http://www.yelp.com/healthscores
#
# Field values that contain quotation marks or commas must be enclosed
# within quotation marks. In addition, each quotation mark in the field
# value must be preceded with a quotation mark. This is consistent with
@dogweather
dogweather / setup.py
Created December 14, 2014 23:12
Is this a reasonable setup.py for a 2.7.8 app?
#!/usr/bin/env python
from setuptools import setup, find_packages
import sys
if sys.argv[1] == 'test':
import multiprocessing, logging
from billiard import util
with open('requirements.txt') as f:
required = f.read().splitlines()
@dogweather
dogweather / python-testing-survey.md
Created January 29, 2015 08:06
Python Testing Options, Early 2015

Unittest

Doctest

@dogweather
dogweather / transcript.txt
Created March 2, 2015 21:15
Set up a Python development directory
pluto:~ $ mkdir project
pluto:~ $ cd !$
cd project
pluto:~/project $ pyvenv venv
pluto:~/project $ ls
venv/
pluto:~/project $ source venv/bin/activate
pluto:~/project $ which python
/Users/me/project/venv/bin/python
pluto:~/project $ python --version