Skip to content

Instantly share code, notes, and snippets.

View jheasly's full-sized avatar

John Heasly jheasly

View GitHub Profile
@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 / 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
#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 / 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'
@jheasly
jheasly / non_utf_16le_encoded_object_list.py
Last active August 29, 2015 14:21
Non-encoded object_list
from django.views.generic.list_detail import object_list
from foo.models import Baz
...
def foo(request):
response = object_list(
request,
queryset = Baz.objects.order_by('date'),
template_name = 'my_template.html',
@jheasly
jheasly / flip-sort.py
Created December 20, 2014 02:06
Attempt to connect to Tarbell Google spreadsheet
# -*- coding: utf-8 -*-
import getpass
import httplib2
import gspread
from apiclient import discovery
from oauth2client import keyring_storage
'''
Almost entirely cribbed from tarbell/oauth.py
@jheasly
jheasly / rtlsdr-osx.txt
Last active February 26, 2021 04:02 — forked from 0xabad1dea/rtlsdr-osx.txt
Build RTL-SDR on OSX with no tears using homebrew. Forked from https://gist.github.com/0xabad1dea/5777726, a macports solution.
rtl-sdr build notes for OSX
using macports http://www.macports.org/
see http://sdr.osmocom.org/trac/wiki/rtl-sdr
brew install cmake
brew install libusb
brew install pkgconfig
brew install sox # for easy audio
git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
@jheasly
jheasly / first-news-app-screen.sh
Last active August 29, 2015 13:56
first-news-app
$ git push origin gh-master
error: src refspec gh-master does not match any.
error: failed to push some refs to '[email protected]:jheasly/first-news-app.git'
...
$ git push
fatal: The current branch gh-pages has no upstream branch.
To push the current branch and set the remote as upstream, use
@jheasly
jheasly / goodies.md
Created November 20, 2012 21:26 — forked from mhulse/How to delete a story from Lightning, for keeps.md
Caché DTI ContentPublisher v7.7.3 and above: dt_cms_schema.SEOStoryLookup SQL goodies!

Add an entry to the SEOStoryLookup table:

INSERT INTO dt_cms_schema.SEOStoryLookup (cmsStoryId, created, internalStoryURL, seoURL, serverName, urlType, version)
VALUES (123456, getDate(),'/csp/cms/sites/publication/section/index.csp', '/some/funky/url.html', 'localhost', 0, 61)

Where:

  • created = When entry it was made. Used mainly for troubleshooting/cleanup (avoid searching on this).
@jheasly
jheasly / report-on-slotted-stories.sql
Last active October 9, 2015 06:58
Report on slotted stories
/*
Tweak of unified namespace query for use in plain ol' namespace. Based on query by Aaron Kuehn.
May 9, 2013: Added dt_cms_schema.Mapping.version to SELECT.
*/
select
dt_cms_schema.publication.name "Publication Name",
dt_cms_schema."section".name "Section Name",
dt_cms_schema.slotreference.name "Slot Name",
dt_cms_schema.Mapping.version "Version",