Skip to content

Instantly share code, notes, and snippets.

View onyxfish's full-sized avatar

Christopher Groskopf onyxfish

View GitHub Profile
@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()
@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 / oauth.sh
Created December 14, 2012 15:47
Generate a Github OAuth token using Curl
curl --user $USERNAME:$PASSWORD -X POST -H "Content-Type: application/json" -d '{ "scopes": ["repo","gist","notifications"], "client_id": "$OAUTH_APP_ID", "client_secret": "$OAUTH_APP_SECRET" }' https://api.github.com/authorizations
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import getpass
import json
import requests
from requests.auth import HTTPBasicAuth
# CHANGE THESE CONSTANTS
@onyxfish
onyxfish / app.js
Created October 24, 2012 19:19
Code to generate and prune state combinations
combos = combinations(state_ids, 1);
_.each(combos, function(combo) {
// Calculate available votes
var combo_votes = _.reduce(combo, function(memo, id) { return memo + states_by_id[id].electoral_votes; }, 0);
// (1) Skip combinations which don't have enough votes to win for Romney
if (combo_votes >= red_needs && red_needs > 0) {
// (2) Skip supersets of prior combinations
if (!is_subset(red_combos, combo)) {
@onyxfish
onyxfish / combinations.js
Created October 24, 2012 17:32
Algorithm for non-recursively generating combinations in JavasScript
function combinations(superset, min_size, max_size) {
/*
* Compute all possible combinations of a given array.
*
* Algorithm via http://stackoverflow.com/a/4061167
*/
var result = [];
var size = min_size || 1;
var max_size = max_size || superset.length
@onyxfish
onyxfish / .vimrc
Created September 27, 2012 19:41
Map - and = to resize vertical window splits by five columns at a time
map = <c-w>><c-w>><c-w>><c-w>><c-w>>
map - <c-w><<c-w><<c-w><<c-w><<c-w><
@onyxfish
onyxfish / electris.yml
Created September 27, 2012 14:16
Teamocil Config
session:
name: "electris"
windows:
- name: "term"
clear: true
root: "~/src/electris"
filters:
before:
- "workon electris"
splits:
@onyxfish
onyxfish / cloc.txt
Created September 5, 2012 19:25
PANDA Project Stats
$ cloc --exclude-dir=media,.coverage,_site,docs,test_data,coverage_html,client/static/js/lib .
400 text files.
392 unique files.
1072 files ignored.
http://cloc.sourceforge.net v 1.55 T=4.0 s (68.2 files/s, 7816.5 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
@onyxfish
onyxfish / results.txt
Created February 7, 2012 16:48
Stupid Komen graphic
First order approximation of this image's actual slice size using pixel counts:
https://motherjones.com/files/images/komen_expenses_300px.jpg
Graphic had numbers painted out and text cropped before processing with stupid.py.
Pixel counts, l to r:
(255, 162, 194, 255) 1602
(177, 178, 180, 255) 392