Skip to content

Instantly share code, notes, and snippets.

View dcollien's full-sized avatar

David Collien dcollien

View GitHub Profile
@dcollien
dcollien / olpageapi.py
Last active August 29, 2015 14:25
ol auth
import requests, json, string, os
chars = string.ascii_lowercase
random_crap = ''.join(chars[ord(x) % len(chars)] for x in os.urandom(16))
# Auth
credentials = {'user': 'testapiuser', 'password': 'test1234'}
request_url = "https://www.openlearning.com/json/auth"
response = requests.post(request_url, data=credentials)
token = response.cookies["auth_token"].replace('"', '')
@dcollien
dcollien / ImageTools.es6
Last active April 28, 2023 09:00
Resize Images in the Browser
let hasBlobConstructor = typeof(Blob) !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
let hasArrayBufferViewSupport = hasBlobConstructor && typeof(Uint8Array) !== 'undefined' && (function () {
try {
@dcollien
dcollien / server.py
Last active August 29, 2015 14:26
Tornado HMAC Authenticated POST
from tornado import web, ioloop, escape
import hmac, hashlib
SECRET = 'jGW7UPn8T1kpuNP1Op79YIL4Th4a5Cduebgta4riFE2zcAWAmhZToDmevmr4iLfO'
def constant_time_compare(val1, val2):
"""
Returns True if the two strings are equal, False otherwise.
The time taken is independent of the number of characters that match.
<!DOCTYPE html>
<head>
<script>
var start_indicator = 'START';
var lineNum = 0;
var render = function(newData) {
var content = '';
newData = newData.replace(/^\s+|\s+$/g, '');
if (newData === '') return '';
var lines = newData.split('\\n');
@dcollien
dcollien / package.json
Last active February 9, 2017 16:14
HTTP-ify anything: A server which executes commands.
{
"name": "http-exec",
"version": "1.0.0",
"description": "Command Execution Server",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "David Collien",
@dcollien
dcollien / multipart.js
Last active March 30, 2024 18:15
Parse multi-part formdata in the browser
var Multipart = {
parse: (function() {
function Parser(arraybuf, boundary) {
this.array = arraybuf;
this.token = null;
this.current = null;
this.i = 0;
this.boundary = boundary;
}
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);
}
#!/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,
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)
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 });