Skip to content

Instantly share code, notes, and snippets.

@tyleha
tyleha / gmail_heatmap.py
Created January 11, 2016 01:55
Unified code needed to build a heatmap of your email data.
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 July 3, 2019 15:22
A simple IMAP manager class for Gmail
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 August 29, 2015 14:08
Map of Flights Taken
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 December 1, 2017 15:06
Hexbin Map of Location History
"""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 November 12, 2017 17:23
Choropleth of Location history
# 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 / tic-toc-python.md
Last active February 16, 2023 00:38
Building a Matlab-style timing function that can be called with the bare-minimum number of keystrokes and thought.

A Simple Python Timing Function

Overview

# What this gist provides:

tic()
'''code to be timed'''
toc()