Skip to content

Instantly share code, notes, and snippets.

View onyxfish's full-sized avatar

Christopher Groskopf onyxfish

View GitHub Profile
@onyxfish
onyxfish / api_sample.json
Last active March 9, 2016 19:28
Sample API output from NPR's Artemis API--including full-text transcript with timestamps.
{
total: 1,
start: 0,
size: 10,
hits: [{
_index: "artemis-0319",
_type: "story",
_id: "931678",
_score: 14.204842,
_source: {
@onyxfish
onyxfish / readme.txt
Created December 17, 2013 20:07
The Google Spreadsheets republishing issue
We use Google Spreadsheets as a de facto CMS for most of our apps team projects. Examples:
http://apps.npr.org/best-books-2013/
http://www.lobbyingmissouri.org/
We store both the data and the text (copy) for the apps in those spreadsheets. Whenever we deploy we curl those spreadsheets, pull the data out of them and plug it into the app. This allows us the flexibility of collaboratively aggregating and editing application content with our reporters, without them needing to be able to run the app.
The Achilles hill of this process is that it currently requires us to manually go to File -> Publish to Web -> Republish now, in order for the latest data to be downloaded. This is very inconvenient when we are iterating quickly. I understand we could work around this by auth'ing to the API, but that's a) unnecessarily complicated and b) requires we deal with storing all those credentials or having a shared user account.
Two solutions spring to mind:
@onyxfish
onyxfish / app.snippet.js
Created December 5, 2013 21:39
The key fragment for integrating isotope and unveil gracefully.
// Never relayout the grid more than twice a second
var relayout = _.throttle(function() {
$books_grid.isotope('reLayout');
}, 500);
/*
* Begin unveiling visible books in the grid.
*/
var unveil_grid = function() {
var BITMAPS = {
BIRD_OF_PREY: [
[0,0,0,0,0,0,0,0,0],
[0,0,1,1,1,1,1,1,0],
[0,1,0,1,0,0,0,0,0],
[0,1,1,1,0,0,0,0,0],
[0,1,0,0,1,0,0,0,0],
[0,1,0,0,0,1,1,1,0],
[0,1,0,0,0,1,1,1,0],
[0,1,0,0,0,1,1,0,0],
@onyxfish
onyxfish / app-tumblr.js
Last active December 17, 2015 23:09
Excerpts from the glyph code for http://she-works.tumblr.js
function render_glyphs(glyph_set) {
/*
* Render the SVG ornament glyphs.
*/
for (var i = 0; i < glyph_rects.length; i++) {
glyph_rects[i].remove();
}
glyph_rects = [];
@onyxfish
onyxfish / fix_svg.py
Created May 20, 2013 21:54
Part of our SVG processing that normalizes the input before its passed to cairosvg
svg = request.form.get('image', None)
svg = re.sub('(height|width)=\"[0-9]+\"', '', svg, 2)
# Fix for duplicate namespaces in IE...
if svg.count('xmlns="http://www.w3.org/2000/svg"') > 1:
svg = svg.replace('xmlns="http://www.w3.org/2000/svg"', '', 1)
@onyxfish
onyxfish / svg_to_hidden_input.js
Created May 20, 2013 20:19
Example demonstrating how to extract SVG from the DOM and populate a hidden form input.
var $hidden_input = $('input[name="svg_body"]');
var $svg_root = $('svg#preview');
var svg = $svg_root.html();
$hidden_input.val(svg);
@onyxfish
onyxfish / gist:5196967
Created March 19, 2013 15:16
NPR Apps Analytics tags
<!-- GOOGLE ANALYTICS -->
<script type="text/javascript">
var _gaq = _gaq || [];
var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-5828686-4']);
_gaq.push(['_setDomainName', 'npr.org']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
@onyxfish
onyxfish / test.py
Created February 8, 2013 22:58
Operators are an Illusion; A 2nd Koan for Katie
#!/usr/bin/env python
class SevenObject(object):
def __add__(self, other):
return 7 + other
def __sub__(self, other):
return 7 - other
seven = SevenObject()
@onyxfish
onyxfish / test.py
Last active December 12, 2015 08:09
Functions as Objects Koan for Katie
#!/usr/bin/env python
class AnObjectThatCanBeCalled(object):
def __call__(self):
print 'Called an object'
def AFunction():
print 'Called an actual function'
obj = AnObjectThatCanBeCalled()