Skip to content

Instantly share code, notes, and snippets.

@beauvais
beauvais / gist:4091805
Created November 16, 2012 23:16
traceback
Traceback (most recent call last):
File "parser.py", line 42, in <module>
for n, r in enumerate(records(argv[1])): # 'My Clippings.txt') ):
File "parser.py", line 23, in records
clip['type'], clip['location'], clip['dow'], clip['date'], clip['time'] = match.groups()
AttributeError: 'NoneType' object has no attribute 'groups'
@beauvais
beauvais / gist:4091833
Created November 16, 2012 23:20
parser.py
import re
import codecs
from pprint import pprint
EOR = u"=========="
def records(file_path):
clip_file = codecs.open(file_path)
clip_file.seek(3) # skip magic cookie
@beauvais
beauvais / gist:4091857
Created November 16, 2012 23:25
out.txt
0{'attribution': [u'Mark Pilgrim'],
'body': u"You KNOW HOW OTHER books go on and on about programming fundamentals, and finally work up to building a complete, working program? Let's skip all that.\n",
'date': u'June 13, 2011',
'dow': u'Monday',
'location': u'218-19',
'time': u'09:54 PM',
'title': u'Dive Into Python',
'type': u'Highlight on Page 11 |'}
1{'attribution': [u'Mark Pilgrim'],
'body': u'Often love this approach to learning, but appreciate context too.',
def talk_time(argv):
count = 0
remaining = sum(argv)
for i in argv:
print("time elapsed: " + str(count))
count += i
remaining -= i
print("after " + str(i) + "time remaining: " + str(remaining) + " ")
discussion = {}
discussion['John'] = 45
discussion['Graham'] = 30
discussion['Michael'] = 20
discussion['Terry'] = 30
@beauvais
beauvais / extractor.py
Created December 11, 2012 13:23
extracting and soupifying
import requests
from sys import argv
from bs4 import BeautifulSoup
script, landing = argv # landing is the first URI for this script
def extractor(landing): # extractor uses requests to GET pages
r = requests.get(landing) # and assigns them variables for use
response = r.status_code
c = r.text
Beauvais dit Saint-Joseph, Joseph-Xavier. Soldat au régiment de Languedoc, compagnie de Vaudray en 1755, engagé le 5 mai 1753 comme soldat dans la compagnie de Vaudray. Il est né le 14 mai 1730 à Champagnole (St-Cyr-et-Ste-Juliette), Jura, fils de Jacques Beauvais et Anne-Marie Roussout. Il épouse Josephte Desnoyers le 21 février 1757 à Chambly. Il décède à Chambly le 26 avril 1804. Notes : Charactéristiques physiques : 5 pieds et 2 pouces, les cheveaux et sourcils châtains, les yeux gris bleu, le nez et la bouche petite, le visage plein, une cicatrice à côté de l'œil droit. (239)
@beauvais
beauvais / anti_vowel.py
Created January 20, 2013 20:06
anti_vowel for code academy
def anti_vowel(text):
vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
anti = []
for i in text:
if i in vowels:
pass
else:
anti.append(i)
return "".join(anti)
@beauvais
beauvais / scrabble_score.py
Created January 20, 2013 21:12
Returning a scrabble score (without letter multiplier squares).
score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}
def scrabble_score(word):
word = word.lower()
tally = 0
@beauvais
beauvais / grades_variance.py
Created January 21, 2013 19:34
codeacademy variance calculator
grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
def print_grades(grades):
for grade in grades:
print grade
def grades_sum(grades):
total = 0