Skip to content

Instantly share code, notes, and snippets.

View jheasly's full-sized avatar

John Heasly jheasly

View GitHub Profile
@jheasly
jheasly / encoded_object_list.py
Last active August 29, 2015 14:21
utf16-le encoded object_list
from django.http import HttpResponse
from django.template import RequestContext, loader
from foo.models import Baz
...
def foo(request):
queryset = Baz.objects.order_by('date')
template_name = 'my_template.html'
mimetype = 'text/plain'
#main/contexts.py
from django.core.urlresolvers import resolve, Resolver404
def appname(request):
try:
app_label = resolve(request.path).app_name
except Resolver404:
app_label = None
return {'appname': app_label}
@jheasly
jheasly / bat_avg.py
Last active April 27, 2016 01:46
mlbgame gets batting avg.
>>> from __future__ import print_function
>>> import mlbgame
>>> game = mlbgame(2016, 4, 26, home='Mariners'][0]
>>> stats = mlbgame.player_stats(game.game_id)
>>> for player in stats['home_batting']:
... print(player.name_display_first_last, player.avg)
...
Norichika Aoki 0.205
Ketel Marte 0.238
Robinson Cano 0.224
@jheasly
jheasly / django_scheduler_event_generic_relation_example.py
Last active September 5, 2016 20:03
civic_calendar & django-scheduler
'''
Experiments in extending the django_scheduler Event class via the built-in EventRelation class.
'''
>>> from schedule.models import Calendar, Event, EventRelation
>>> from civic_calendar.models import Meeting
>>> event = Event.objects.get(pk=2)
>>> meeting = Meeting.objects.get(pk=2)
>>> er = EventRelation(event=event, content_object=meeting)
>>> er.save()
@jheasly
jheasly / docker_exec_mongo.md
Last active November 9, 2017 01:48
The warnings from the mongo inside the Talk Docker container
bash-3.2$ docker exec -it [container ID] mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
@jheasly
jheasly / tarbell_serve_error.py
Created March 6, 2019 04:48
Tarbell traceback
Traceback (most recent call last):
File "/Users/jpheasly/.virtualenvs/tarbell/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/jpheasly/.virtualenvs/tarbell/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/jpheasly/.virtualenvs/tarbell/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/jpheasly/.virtualenvs/tarbell/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/jpheasly/.virtualenvs/tarbell/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
@jheasly
jheasly / get_the_API.py
Last active March 9, 2021 01:01
An example of from using Python to get the API behind a Tableau site, rather than scraping the HTML. Per the author, Jeremy J. Bowers, it will work for any Tableau vizql implementation, with a bit of URL substitution.
# Related, from News Nerdery thread:
#
# aricchokey 2 hours ago
# @ejmurra Looks like another way to grab the data is by tacking on a ".csv" at the end of the chosen sheet. It will
# return the delimited version of the data/trigger the download from Tableau, too.
# Like https://bi.ahca.myflorida.com/t/ABICC/views/Public/HospitalBedsHospital.csv or
# https://bi.ahca.myflorida.com/t/ABICC/views/Public/ICUBedsCounty.csv. Might get rid of the need for a payload
# in your script.
from bs4 import BeautifulSoup
mydate cday dday ma
2020-03-01 0.0 0.0
2020-03-02 0.0 0.0
2020-03-03 0.0 0.0
2020-03-04 0.0 0.0
2020-03-05 0.0 0.0
2020-03-06 0.0 0.0
2020-03-07 0.0 0.0 0.0
2020-03-08 0.0 0.0 0.0
2020-03-09 0.0 0.0 0.0
mydate,cday,dday,ma
2020-03-01,0.0,0.0,
2020-03-02,0.0,0.0,
2020-03-03,0.0,0.0,
2020-03-04,0.0,0.0,
2020-03-05,0.0,0.0,
2020-03-06,0.0,0.0,
2020-03-07,0.0,0.0,0.0
2020-03-08,1.0,0.0,0.14285714285714285
2020-03-09,0.0,0.0,0.14285714285714285
mydate,cday,dday,ma
2020-03-01,0.0,0.0,
2020-03-02,0.0,0.0,
2020-03-03,0.0,0.0,
2020-03-04,0.0,0.0,
2020-03-05,0.0,0.0,
2020-03-06,0.0,0.0,
2020-03-07,0.0,0.0,0.0
2020-03-08,1.0,0.0,0.14285714285714285
2020-03-09,0.0,0.0,0.14285714285714285