Skip to content

Instantly share code, notes, and snippets.

@taylorhughes
taylorhughes / upload_api.py
Last active May 11, 2024 11:18
Use a pre-signed S3 URL with a modern web uploader
import uuid
from datetime import datetime
import boto3
from django.conf import settings
from mypy_boto3_s3 import S3Client
from rest_framework import serializers
from rest_framework.response import Response
from myproject.models import ProfilePhoto
from typing import Any, Dict, List, Optional
from OpenSSL import crypto
import jwt
from jwt.utils import base64url_decode
import requests
import logging
ROOT_CER_URL = "https://www.apple.com/certificateauthority/AppleRootCA-G3.cer"
G6_CER_URL = "https://www.apple.com/certificateauthority/AppleWWDRCAG6.cer"
@taylorhughes
taylorhughes / user-agents.txt
Last active April 6, 2024 16:07
A list of iOS embedded webview User-Agents
SAFARI 10.0.1
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1
CHROME on 10.0.1
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.86 Mobile/14A403 Safari/601.1.46
FACEBOOK MESSENGER
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Mobile/14A403 [FBAN/MessengerForiOS;FBAV/87.0.0.24.69;FBBV/38293694;FBRV/0;FBDV/iPhone8,4;FBMD/iPhone;FBSN/iPhone OS;FBSV/10.0.1;FBSS/2;FBCR/AT&T;FBID/phone;FBLC/en_US;FBOP/5]
TWITTER FOR IPHONE
@taylorhughes
taylorhughes / run-worker.sh
Last active March 23, 2022 19:05
Celery example with tasks of varying length + -Ofair
# tested with celery[redis]==3.1.17
# to run with default configuration -- tasks will take 14 seconds to complete the 20 tasks in start_all() below
celery worker -A cluster_project.celery_app -Q tester -lINFO --concurrency=4
# to run with -Ofair -- tasks will take 10 seconds to complete
celery worker -A cluster_project.celery_app -Q tester -lINFO --concurrency=4 -Ofair
@taylorhughes
taylorhughes / gist:4dc50b2fe674c0a84cc6
Created October 29, 2014 00:33
Update Facebook token in iOS client from existing server-side cached token
[self.apiClient retrieveConnectedServicesWithSuccessBlock:^(NSDictionary *services) {
NSArray *facebookTokens = services[@"facebook"];
if (facebookTokens.count == 0) {
return;
}
NSDictionary *mostRecentFacebookTokenDict = facebookTokens[0];
NSNumber *refreshTimeNumber = mostRecentFacebookTokenDict[@"refreshTime"];
NSDate *refreshDate = [NSDate dateWithTimeIntervalSince1970:[refreshTimeNumber doubleValue]];
//
// ImgixURL.h
// Cluster
//
// Created by Taylor Hughes on 12/18/12.
// Copyright (c) 2012 Taylor Hughes. All rights reserved.
//
#import "NSDictionary+FormEncoded.h"
@taylorhughes
taylorhughes / uploader.go
Last active July 26, 2022 14:00
A lightly modified excerpt from Cluster's streaming media upload server, which encodes video on the fly as it is uploaded.
func EncodeStreamingVideo(streamingFile io.Reader, request ShouldCanceler) (*os.File, error) {
outputFilename := generateFilename("mp4")
// Actually start the command.
cmd := exec.Command("ffmpeg",
// Read input from stdin.
"-i", "-",
// ... environment-specific ffmpeg options ...
"-y", outputFilename)
### Keybase proof
I hereby claim:
* I am taylorhughes on github.
* I am taylorhughes (https://keybase.io/taylorhughes) on keybase.
* I have a public key whose fingerprint is 7D46 ECF4 DADE BBED 1540 9C79 F40B 2664 6BE8 555D
To claim this, I am signing this object:
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
)
define(['cluster/util'], function(util) {
var PubSub = function() {
this.listeners_ = [];
this.listenersById_ = {};
this.lastId_ = 0;
};