Skip to content

Instantly share code, notes, and snippets.

View onyxfish's full-sized avatar

Christopher Groskopf onyxfish

View GitHub Profile
@onyxfish
onyxfish / 555.py
Created April 7, 2014 13:23
Dead simple script to find optimal resistor and capacitor values for a 555 timer circuit
#!/usr/bin/env python
import sys
import itertools
TIME_HIGH_GOAL = int(sys.argv[1])
TIME_LOW_GOAL = int(sys.argv[2])
print 'Seeking optimal R1, R2 and C1 values for a %i pulse every %i milliseconds...' % (TIME_HIGH_GOAL, TIME_LOW_GOAL)
@onyxfish
onyxfish / gist:9421065
Created March 7, 2014 21:57
keybase.md
### Keybase proof
I hereby claim:
* I am onyxfish on github.
* I am onyxfish (https://keybase.io/onyxfish) on keybase.
* I have a public key whose fingerprint is 9D2F F7F8 83C0 E286 25B5 3BA2 B7C0 7A1B 908A E10B
To claim this, I am signing this object:
@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()