Skip to content

Instantly share code, notes, and snippets.

@christophergregory
christophergregory / solution_2.py
Last active August 29, 2015 14:05
Python 101 Assignment 3 Solution 2
import csv
# Open all required files with at once
with open('numbers.txt', 'r') as numbersfile, \
open('birthdays.txt', 'r') as birthdayfile, \
open('output.txt', 'w') as output:
# Read in each line as a dictionary
# https://docs.python.org/2/library/csv.html#csv.DictReader
numReader = csv.DictReader(numbersfile, fieldnames=['Name','Number'])
@christophergregory
christophergregory / solution_1.py
Created August 27, 2014 14:24
Python 101 Assignment 3 Solution 1
people = {} # let's start with an empty dictionary to hold our data
with open('numbers.txt', 'r') as numbers:
for index, line in enumerate(numbers):
if index > 0: # skip the first line (don't need the headers)
name, birthday = line.rstrip().split(',')
# study this line carefully, it's intentionally terse
people.update({ name : { 'number' : birthday } })
@christophergregory
christophergregory / birthdays.txt
Last active August 29, 2015 14:05
Class Assignment 3
Name,Number
Amal Albertson,7/2/1972
Sondra Shoemaker,2/2/1964
Ryann Ralphs,5/22/1999
Delcie Demma,8/19/1975
Gemma Gates,5/16/1999
Su Scurlock,3/18/1990
Delma Duchene,12/16/1994
Kathyrn Kreps,2/25/1965
Cinda Christon,6/26/1987
# Ask the user to enter a number
number_of_rows = int(raw_input('Enter a number: '))
# Iterate through range of numbers up to what the user entered
for row in range(number_of_rows):
stars = 1 + row * 2
spaces = number_of_rows - row - 1
print ' ' * spaces + '*' * stars
@christophergregory
christophergregory / csv_builder.py
Last active August 29, 2015 14:05
Class 2 Problem - Combine files into one CSV file
"""
Problem: You are given two files, one contains a list of
names (names.txt) and the other a list of phone numbers (numbers.txt).
Your boss needs a single CSV file that can be loaded into excel.
Your task is to combine both txt files into one CSV file.
The first and last names need to be in separate columns
and the phone number must be in the format (555)555-5555
@christophergregory
christophergregory / getVowels.py
Created August 11, 2014 01:11
Function that returns list of vowels in string
def getVowels(word, includeY=False, unique=False):
matches = []
vowels = 'aeiou' if not includeY else 'aeiouy'
for char in word:
if char.lower() in vowels:
matches.append(char)
return list(set(matches)) if unique else matches
print getVowels('This is a fancy test string', includeY=True, unique=True)
@christophergregory
christophergregory / star_pyramid_starter.py
Last active August 29, 2015 14:05
Python 101 - Assignment 1 Starter
# Assignment 1 - Building a star pyramid
# Ask the user to enter a number
number_of_rows = int(raw_input('Enter a number: '))
# Write your code below this comment
@christophergregory
christophergregory / age-verification.liquid
Created April 15, 2014 15:13
Shopify Modal Age Verification
<style>
#verify {
position: absolute;
top: 0;
left: 0;
background: rgba(67, 157, 207, 0.9);
z-index: 200;
width: 100%;
height: 100%;
}
@christophergregory
christophergregory / gist:8982396
Created February 13, 2014 19:45
Split Shopify lists into columns
{% for link in linklists.footer-nav.links %}
{% cycle '<ul>', '' %}
<li><a href="{{ link.url }}">{{ link.title }}</a></li>
{% cycle '', '</ul>' %}
{% capture needsEndingElement %}{% cycle 'yes', 'no' %}{% endcapture %}
{% endfor %}
{% if needsEndingElement == 'yes' %}
</ul>
{% endif %}