This file contains hidden or 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 time | |
import urllib.parse | |
import hmac | |
import hashlib | |
import base64 | |
SB_NAME = "ol-events" | |
EH_NAME = "ol-user-metrics" | |
SAS_NAME = "collect-user-metric" | |
SAS_VALUE = "EXAMPLE-TOKEN" |
This file contains hidden or 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
from datetime import datetime | |
import re | |
import string | |
def to_course_code(course_path, creation_date): | |
""" | |
Turns a course path into a short course code. | |
Max 14 characters (but likely under 10). | |
Not guaranteed to be unique | |
but has month/year of creation date, and single character hash |
This file contains hidden or 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
const uncurry = (fn) => (...args) => args.reduce((fn, arg) => fn(arg), fn); | |
const curry = (fn) => { | |
const collect = (args, arg) => { | |
const collected = args.concat([arg]); | |
return ( | |
collected.length >= fn.length | |
? fn.apply(null, collected) | |
: collect.bind(null, collected) | |
); | |
}; |
This file contains hidden or 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 socket | |
import network | |
import time | |
CONTENT = b"""\ | |
HTTP/1.0 200 OK | |
<!doctype html> | |
<html> |
This file contains hidden or 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 nltk | |
from summa.keywords import keywords | |
def get_features(text): | |
# get the top 80% of the phrases from the text, scored by relevance | |
return dict(keywords(text, ratio=0.8, split=True, scores=True)) | |
def train_texts(classified_texts): | |
# process the training set | |
features = [] |
This file contains hidden or 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 Config(object): | |
def __init__(self, **entries): | |
self.__dict__.update(entries) | |
self._entries = entries | |
def __repr__(self): | |
return "Config(%s)" % str(self._entries) | |
def __getattr__(self, value): | |
return None |
This file contains hidden or 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
const WebSocket = require('ws'); | |
const PythonShell = require('python-shell'); | |
const tmp = require('tmp'); | |
const shortid = require('shortid'); | |
const fs = require('fs'); | |
const mkdirp = require('mkdirp'); | |
// TODO clean up code, error handling, watchdog timer | |
const wss = new WebSocket.Server({ port: 8080 }); |
This file contains hidden or 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
infinity = float("inf") | |
def argmin(seq, fn): | |
"""Return an element with lowest fn(seq[i]) score; tie goes to first one. | |
>>> argmin(['one', 'to', 'three'], len) | |
'to' | |
""" | |
best = seq[0]; best_score = fn(best) | |
for x in seq: | |
x_score = fn(x) |
This file contains hidden or 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
#!/usr/bin/env python | |
import pyrax | |
pyrax.set_setting('identity_type', 'rackspace') | |
pyrax.set_credentials(RACKSPACE_API_USER, RACKSPACE_API_KEY, region='SYD') | |
def server_list_generator(detailed=True, search_opts=None, limit=None): | |
servers = pyrax.cloudservers.servers.list(detailed=detailed, | |
search_opts=search_opts, |
This file contains hidden or 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
const ContrastTools = { | |
relLuminance(rgba) { | |
// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | |
var rgb = rgba.slice(); | |
for (var i = 0; i < 3; i++) { | |
var channel = rgb[i] / 255; | |
rgb[i] = channel < .03928 ? channel / 12.92 : Math.pow((channel + .055) / 1.055, 2.4); | |
} |