Skip to content

Instantly share code, notes, and snippets.

View ejmurray's full-sized avatar

Ernest Murray ejmurray

  • Leeds, UK
  • 23:39 (UTC -12:00)
View GitHub Profile
#!/usr/bin/env python
__author__ = 'Ernest'
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
COMPOUND_LIST = "compounds.txt"
wordlist = open(COMPOUND_LIST).readlines()
# Get rid of newlines
wordlist = [word.lower().strip() for word in wordlist]
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
for grade in grades:
total += grade
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
for grade in grades:
total += grade
#!/usr/bin/env python
__author__ = 'Ernest'
import urllib2
import re
from bs4 import BeautifulSoup
packtpub_url = "http://www.packtpub.com/"
def get_bookurls(url):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# there are a few erors where the script cannot return the correct number of lines
# and the problem with utf-8 encoding
# could use the code in scrapePubMed2.py to sort out the encoding issue?
__author__ = 'Ernest'
from bs4 import BeautifulSoup
import urllib2
import re
#!/usr/bin/env python
"""
This script takes a list of authors which have the following format:
[T Yamamoto, N Hagima, M Fukasawa, J Yamaguchi, M Nakamura, Y Kohno, K Nagata, Y Yamazoe.] or
[TS Emudianughe, J Caldwell, RL Smith.]
and converts it to the following format:
[Yamamoto T, Hagima N, Fukasawa M, Yamaguchi J, Nakamura M, Kohno Y, Nagata K, Yamazoe Y.] or
[Emudianughe TS , Caldwell J, Smith RL.]
"""
__author__ = 'Ernest'
#!/usr/bin/env python
__author__ = 'Ernest'
def is_leap_year(x):
if x % 4 == 0 and x % 100 != 0:
print "%r was a leap year" % x
elif x % 400 == 0:
print "%r was a leap year" % x
else:
#!/usr/bin/env python
__author__ = 'Ernest'
import math
def distance(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
dsquared = dx**2 + dy**2
#!/usr/bin/python
# encoding: utf-8
"""
Created: 22/07/15, 14:02
Description: return the median value from a sorted list of numbers,
an odd length list will have the median value at the centre
an list with an even set of numbers will have the median at n and n-1
In the online exercise you need to use 2.0 in the division to get the floating point number.
"""
import sqlite3
from bottle import route, run, debug, template, request, static_file, error
# only needed when you run Bottle on mod_wsgi
from bottle import default_app
@route('/todo')
def todo_list():
conn = sqlite3.connect('todo.db')