Skip to content

Instantly share code, notes, and snippets.

View JackStouffer's full-sized avatar
💭
I may be slow to respond. Email me.

Jack Stouffer JackStouffer

💭
I may be slow to respond. Email me.
View GitHub Profile
@JackStouffer
JackStouffer / monthly_resample.py
Created December 22, 2014 16:03
Get Data Grouped By Month in Pandas
import pandas
import numpy
def resampled_data(query, date_col, target_col, period="M"):
""" Function that takes an sql query and returns the sum of a target column
by a period. Useful for getting monthly data
"""
df = pandas.read_sql(query, conn)
df.set_index(df[date_col], inplace=True)
@JackStouffer
JackStouffer / autorotate.py
Created December 1, 2014 03:08
Fix the EXIF image rotation browser bug by rotating the image manually
from PIL import Image
def autorotate(path):
""" This function autorotates a picture based upon its EXIF data
because smartphones use a little used EXIF option to set the
rotation of an image rather than save the data in that orientation
"""
image = Image.open(path)
try:
@JackStouffer
JackStouffer / sortable_between_tabs.css
Last active August 29, 2015 14:04
jQuery UI Sortable Between Tabs
#sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
@JackStouffer
JackStouffer / mongo_to_dict.py
Created July 24, 2014 20:19
Turn a Mongoengine object in a json-ible dictionary
def mongo_to_dict(obj):
""" Turn a mongoengine object into a jsonible python object
"""
return_data = []
if isinstance(obj, db.Document):
return_data.append(("id", str(obj.id)))
for field_name in obj._fields:
@JackStouffer
JackStouffer / get_odbc_schema.php
Created May 14, 2014 14:16
A simple script to get all tables and their schema from an odbc connection
<?php
$connection = odbc_connect("YOURCONNECTION", "", "");
$result = odbc_tables($connection);
$tables = array();
while (odbc_fetch_row($result))
{
if(odbc_result($result,"TABLE_TYPE")=="TABLE")
{