Skip to content

Instantly share code, notes, and snippets.

View c-rhodes's full-sized avatar

Cullen Rhodes c-rhodes

  • Arm
  • Manchester, UK
View GitHub Profile
import pandas as pd
import matplotlib.pyplot as plt
dataset = '/home/cullenrhodes/Downloads/as-and-a-level-mathematics-data-set.xls'
# Build DataFrame containing Heathrow 1987 data.
# Header starts at row 6 (substract 1 for 0-based indexing).
df_heathrow_1987 = pd.read_excel(
dataset, sheetname='Heathrow May-Oct 1987', header=5, index_col='Date'
)
# Build DataFrame containing Heathrow 2015 data.
@c-rhodes
c-rhodes / factory_boy_pre_imports.py
Created June 3, 2017 12:16
Django extensions import factory boy factories
import django
django.setup()
import factory.base
import inspect
import importlib
factory_pre_imports = []
for app_name in LOCAL_APPS:
module_name = '{}.{}'.format(app_name, 'factories')
try:
module = importlib.import_module(module_name)
from itertools import izip_longest
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)
def exp_treesize(data):
data = data.split('\n')
from rest_framework import renderers
class PlainTextRenderer(renderers.BaseRenderer):
media_type = 'text/plain'
format = 'text'
def render(self, data, media_type=None, renderer_context=None):
return str(renderers.JSONRenderer().render(data, media_type, renderer_context)).encode(self.charset)
@c-rhodes
c-rhodes / ex1.ipynb
Created February 23, 2015 21:26
Example 1 for Decision Mathematics
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@c-rhodes
c-rhodes / settings_test_snippet.py
Last active August 29, 2015 14:14 — forked from NotSqrt/settings_test_snippet.py
A solution to avoid migrations when testing in Django 1.7, the config is set in manage.py so no environment variables have to be set
# settings.py
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return "notmigrations"
"""
Reddit DailyProgrammer Challenge #190 - Webscraping Sentiments.
http://bit.ly/11sBRa0
"""
import requests
from bs4 import BeautifulSoup
comments_url = 'http://www.youtube.com/all_comments?v={video_id}'
happy = ['love','loved','like','liked','awesome','amazing','good','great','excellent']
# Demonstration of a time of check to time of use (toutou) race condition
import os
import time
from threading import Thread
class ReadFileThread(Thread):
def __init__(self, file_name):
import numpy as np
# shape (3, 3, 3, 3)
l = np.array(range(81)).reshape((3, 3, 3, 3))
for w in range(3):
for x in range(3):
for y in range(3):
for z in range(3):
print(l[w][y][x][z], end=" ")