This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import matplotlib | |
from matplotlib import pyplot as plt | |
# Define data | |
data_grp1 = [1, 2, 3, 4, 5, 3, 2, 1, 5, 6, 4, 2, 4] | |
data_grp2 = [6, 7, 8, 7, 8, 9, 1, 1, 9, 15] | |
# Boxplot | |
plt.boxplot([data_grp1, data_grp2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data = ... | |
# subjects = ... | |
# trials = ... | |
# computation = function(...) | |
for (subject in subjects) { | |
subject_rows = data$subject == subject | |
for (trial in trials) { | |
rows = subject_rows & data$trial == trial | |
result = computation(data[rows,]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def states_to_colors(states, cols): | |
'''Generate all possible mappings of states to colors. | |
Args: | |
states (list) : list of state names | |
cols (list) : list of color names | |
Returns: | |
list of dictionaries of state-color mappings | |
Example use: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enum(sofar, new): | |
if len(new) == 0: | |
return sofar | |
else: | |
return enum (sofar + new[0] + 'r', new[1:]) \ | |
+ enum (sofar + new[0] + 'g', new[1:]) \ | |
+ enum (sofar + new[0] + 'b', new[1:]) \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extract PDF text using PDFMiner. Adapted from | |
http://stackoverflow.com/questions/5725278/python-help-using-pdfminer-as-a-library | |
""" | |
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter#process_pdf | |
from pdfminer.pdfpage import PDFPage | |
from pdfminer.converter import TextConverter | |
from pdfminer.layout import LAParams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.before_request | |
def prepare_private_key(): | |
# Done if private_key in args | |
key_from_args = request.args.get('private_key') | |
if key_from_args: | |
return | |
# Check referrer for private key | |
parsed_referrer = urllib.urlparse(request.referrer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function forceDownload(href) { | |
var anchor = document.createElement('a'); | |
anchor.href = href; | |
anchor.download = href; | |
document.body.appendChild(anchor); | |
anchor.click(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _Bar(object): | |
pass | |
class Foo(object): | |
def __init__(self): | |
self._bar = None | |
@property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Tornado / Celery / sockets proof of concept | |
To run: | |
$ celery -A app worker | |
$ python app.py | |
""" | |
import os | |
import socket | |
import random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import aiohttp | |
import tornado.web | |
import tornado.options | |
import tornado.concurrent | |
import tornado.platform.asyncio | |
URL = '...' | |
UPLOAD_URL = '...' |
OlderNewer