Skip to content

Instantly share code, notes, and snippets.

View chrisseto's full-sized avatar

Chris Seto chrisseto

View GitHub Profile
uploadMethod: 'PUT',
uploadAdded: function(file, item) {
//Recieve the signed PUT request here
//I can create another GIST if anyone would like the code for signing the requests
mydropzone.options.url = url;
},
uploadSending: function(file, formData, xhr) {
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
@chrisseto
chrisseto / signurl.py
Created February 13, 2014 23:40
How to generate an s3 signed url in python
def generate_signed_url(mime, file_name, s3):
"""
:param mime str: The file mime type.
:param file_name str: The name of the file to be upload into s3.
:param s3 Object: An object containing the bucket name and access keys to amazon.
:return str: The signed url.
"""
expires = int(time.time() + 10)
amz_headers = 'x-amz-acl:private'
@chrisseto
chrisseto / Html5VideoStream
Last active August 29, 2015 13:57
A small and simple video browser/streamer in nodejs
var fs = require('fs')
var util = require('util')
var express = require('express');
var serveIndex = require('serve-index');
var querystring = require('querystring');
var app = express();
app.use(serveIndex(__dirname, {
'icons': true
@chrisseto
chrisseto / rediscluster.py
Last active August 29, 2015 14:00
RedisCluster class
import crc16
from redis import Redis
TOTAL_HASH_SLOTS = 16384
#TODO
SHARDED_COMMANDS = [
'get',
'set',
@chrisseto
chrisseto / Handler.py
Created August 25, 2014 19:18
Streaming tornado uploads to Amazon S3
@web.stream_request_body
class UploadHandler(RequestHandler):
def prepare(self):
self.count = 0
self.buffer_len = 0
self.buffer = StringIO()
self.mp = bucket.initiate_multipart_upload('Multiparts are cool')
def data_received(self, data):
{
"metadata": {
"name": "",
"signature": "sha256:5414b12e5613456d6b81de472be9f5d902c5ef090fa39aad4abc1864f95ad48c"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
from IPython.core.magic import Magics, magics_class, line_magic
import asyncio
@magics_class
class AsyncMagics(Magics):
@line_magic
def await(self, line):
return asyncio.get_event_loop().run_until_complete(eval(line, self.shell.user_global_ns, self.shell.user_ns))
@chrisseto
chrisseto / application.controller.js
Last active February 29, 2016 19:39
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
myComponent: 'will-destroy-element',
appName: 'Ember Twiddle',
actions: {
click() {
if (this.get('myComponent') !== null)
this.set('myComponent', null);
else
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Experimenter Interface</title>
</head>
<body>
<select id="exp"></select>
<select id="session"></select>
@chrisseto
chrisseto / regexRange.js
Last active March 9, 2016 22:04
Given two bounding number generate a regex that matches that range, inclusive.
function regexRange(lo, hi) {
let re = [];
hi = hi.toString();
lo = lo.toString();
while (hi.length > lo.length) {
re.push(hi.split('').reduce((acc, c) => acc + `[${acc.length === 0 ? 1 : 0}-${c}]`, ''));
hi = '9'.repeat(hi.length - 1);
}
let i = 0;
re.push(lo.split('').reduce((acc, c) => acc + `[${c}-${hi[i++]||c}]`, ''));