Skip to content

Instantly share code, notes, and snippets.

View cshoe's full-sized avatar
🚵

Chris Schomaker cshoe

🚵
View GitHub Profile
@cshoe
cshoe / datadog_ascii.py
Last active February 22, 2016 19:55
Datadog Python library doesn't seem to like Unicode.
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from datadog import statsd
def main():
"""docstring for main"""
import functools
import threading
from tornado import gen, httpserver, ioloop, stack_context, web
class ThreadRequestContext(object):
"""
A context manager that saves some per-thread state globally.
Intended for use with Tornado's StackContext.
import time
from contextlib import contextmanager
@contextmanager
def timed(metric, tags=None):
start = time.time()
try:
yield tags
finally:
print tags

Keybase proof

I hereby claim:

  • I am cshoe on github.
  • I am cshoe (https://keybase.io/cshoe) on keybase.
  • I have a public key whose fingerprint is 2DB5 0FC0 C3FF F9EF D3A9 76A2 1E0B 7699 6E4C 5D94

To claim this, I am signing this object:

# As mentioned, this is a bit verbose but I like the separation of concerns.
# Basically, you have two functions -- one that does meaningful work and
# another that just serves as the "glue" to connect the Django signal
# infrastructure to your function.
from django.dispatch import receiver
@receiver
def glue_funtion(sender, **kwargs):
"""

Keybase proof

I hereby claim:

  • I am cshoe on github.
  • I am cshoe (https://keybase.io/cshoe) on keybase.
  • I have a public key whose fingerprint is C6FD 526A 4254 CC42 2427 0747 0862 C043 DAD3 9ACC

To claim this, I am signing this object:

@cshoe
cshoe / gist:83696dd39f12f3447ef5
Created May 14, 2014 18:51
Cleanup interviews for Mo.
import sys
from xml.etree import ElementTree
from jinja2 import Template
template_string = """{\\rtf1\\ansi\\ansicpg1252\cocoartf1265\cocoasubrtf190
{\\fonttbl\\f0\fswiss\\fcharset0 ArialMT;\\f1\\froman\\fcharset0 Times-Roman;}
{\colortbl;\\red255\green255\\blue255;}
FROM ubuntu:12.04
MAINTAINER Chris Schomaker <schomaker.c@gmail.com>
# add salt repository
RUN sudo apt-get update
RUN sudo apt-get install -y python-software-properties
RUN sudo add-apt-repository -y ppa:saltstack/salt
RUN sudo apt-get update
@cshoe
cshoe / reader_example
Created June 3, 2013 19:42
Quick ReaderClient example.
from readability import ReaderClient
rdb_client = ReaderClient('my_reader_token', 'my_reader_secret', 'user_key', 'user_secret')
bookmarks_response = rdb_client.get_bookmarks(favorite=True)
print bookmarks_response.content
>>> {'bookmarks': [{'user_id': 1039419, 'read_percent': u'0.00', u'tags': [], u'date_updated': u'2013-05-31 08:22:57', u'favorite': True, u'archive': False, u'date_archived': None, u'date_opened': None, u'article': … }
@cshoe
cshoe / rdb_content_post.py
Last active December 17, 2015 21:19
Example of POSTing content to Readability Parser API in Python.
# -*- coding: utf-8 -*-
import json
import urllib
import requests
CONTENT = """
<html lang="en" dir="ltr" class="client-js"><head>
<title>Cryptography - Wikipedia, the free encyclopedia</title>