Skip to content

Instantly share code, notes, and snippets.

Tyler Hartley tyleha

Block or report user

Report or block tyleha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tyleha
tyleha / gmail_heatmap.py
Created Jan 11, 2016
Unified code needed to build a heatmap of your email data.
View gmail_heatmap.py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import matplotlib.gridspec as gridspec
from datetime import timedelta, datetime, date
import GmailAccount # my package
gmail = GmailAccount(username='you@gmail.com', password=password)
@tyleha
tyleha / gmailaccount.py
Last active Jul 3, 2019
A simple IMAP manager class for Gmail
View gmailaccount.py
from imaplib import IMAP4_SSL
import email as em
from email.utils import parsedate, parsedate_tz
from email.parser import HeaderParser
class GmailAccount(object):
def __init__(self, username=None, password=None, folder=None):
self.username = username
self.password = password
self.folder = folder
@tyleha
tyleha / flights.py
Last active Aug 29, 2015
Map of Flights Taken
View flights.py
fig = plt.figure(figsize=(18,12))
# Plotting across the international dateline is tough. One option is to break up flights
# by hemisphere. Otherwise, you'd need to plot using a different projection like 'robin'
# and potentially center on the Int'l Dateline (lon_0=-180)
# flights = flights[(flights.startlon < 0) & (flights.endlon < 0)]# Western Hemisphere Flights
# flights = flights[(flights.startlon > 0) & (flights.endlon > 0)] # Eastern Hemisphere Flights
xbuf = 0.2
ybuf = 0.35
@tyleha
tyleha / hexbin.py
Last active Dec 1, 2017
Hexbin Map of Location History
View hexbin.py
"""PLOT A HEXBIN MAP OF LOCATION
"""
figwidth = 14
fig = plt.figure(figsize=(figwidth, figwidth*h/w))
ax = fig.add_subplot(111, axisbg='w', frame_on=False)
# draw neighborhood patches from polygons
df_map['patches'] = df_map['poly'].map(lambda x: PolygonPatch(
x, fc='#555555', ec='#555555', lw=1, alpha=1, zorder=0))
# plot neighborhoods by adding the PatchCollection to the axes instance
@tyleha
tyleha / choropleth.py
Last active Nov 12, 2017
Choropleth of Location history
View choropleth.py
# Check out the full post at http://beneathdata.com/how-to/visualizing-my-location-history/
# to utilize the code below
# We'll only use a handful of distinct colors for our choropleth. So pick where
# you want your cutoffs to occur. Leave zero and ~infinity alone.
breaks = [0.] + [4., 24., 64., 135.] + [1e20]
def self_categorize(entry, breaks):
for i in range(len(breaks)-1):
if entry > breaks[i] and entry <= breaks[i+1]:
return i
@tyleha
tyleha / reverse_hash.py
Last active Aug 29, 2015
CSATS Reverse Hash
View reverse_hash.py
def forward_hash(astring, available_characters):
"""A python version of the original hash algo"""
h = 7
for letter in astring:
h = (h*37 + available_characters.index(letter))
return h
def reverse_hash(the_hash, available_characters):
"""The reverse of the forward_hash algorithm"""
the_word = ''
@tyleha
tyleha / tic-toc-python.md
Last active Nov 25, 2016
Building a Matlab-style timing function that can be called with the bare-minimum number of keystrokes and thought.
View tic-toc-python.md

A Simple Python Timing Function

Overview

# What this gist provides:

tic()
'''code to be timed'''
toc()
You can’t perform that action at this time.