Skip to content

Instantly share code, notes, and snippets.

View jasonhdavis's full-sized avatar

Jason jasonhdavis

View GitHub Profile
@jasonhdavis
jasonhdavis / Readme.io + Segment Tracking.html
Last active February 11, 2020 16:31
Send Segment "Page Viewed" actions on subsequent page loads
<!-- Place this in the Apperance -> Custom Include Tags Page -->
<!-- ReadMe.io glue script for Segment -->
<script type="text/javascript">
// Content is loaded via ajax - this means normal js embed will not work.
// Instead, we check for a completed ajax event of type GET
// Similarly, we need to refresh on-page variables
// This event is fired a half second after document ready to give title tag time to refresh
$(document).ajaxComplete(function(event,xhr,settings){
@jasonhdavis
jasonhdavis / amazon-locations.py
Created May 21, 2019 06:21
Python dictionary of all Amazon FBA locations across the country. This is helpful as Amazon will sometimes refer to their shipping locations by their code in the MWS api. Also helpful for FBA shippers and other shipping apis
fba_locations = {'*XFR': {'address': '2021 7th Avenue',
'city': 'Seattle',
'code': '*XFR',
'notes': '',
'state': 'WA',
'zip': '98121'},
'ABE1': {'address': '705 Boulder Dr',
'city': 'Breinigsville',
'code': 'ABE1',
'notes': '',
@jasonhdavis
jasonhdavis / mongodb-group-by-day.py
Last active November 19, 2018 14:29
Efficient MongoDB query in Python to group results by day. This uses a single, simple find query to get all results within a date range. We then build a nested dictionary of [year][month][day] and add results to the dictionary structure
################################
########## WHY & How ###########
################################
# I had written a query inside of a loop that pulled results for every day
# This was very ineffecient
# While I belive this could be solved with a MongoDB Aggrigation, the syntax seemed complicated
# I could not find good examples for what I needed to do (aggrigate results of a day based on timestamp in one query)
# This is likely due to my ignorance
# Nonetheless, I thought this method may be helpful to someone else having the same issues as me
# Finally, dealing with nested dictionaries in python is slightly difficult as a nested key needs to be added with 'update'