Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@dkarchmer
dkarchmer / cognito-developer-authenticated-client-example.py
Last active November 8, 2022 16:12
django-boto3-cognito: AWS' Cognito Developer Authenticated Identities Authflow using Django/Python/Boto3 (For building stand-alone clients)
__author__ = 'dkarchmer'
'''
This script emulates a stand-alone Python based client. It relies on Boto3 to access AWS, but
requires your Django server to have an API for your user to access Cognito based credentials
Because of Cognito, the client (this script) will only get temporary AWS credentials associated
to your user and only your user, and based on whatever you configure your AIM Policy to be.
Most Cognito examples demonstrate how to use Cognito for Mobile Apps, so this scripts demonstrate
how to create a stand-alone Python script but operating similarly to these apps.
@dkarchmer
dkarchmer / .ebextenstions__django-main.config
Created December 8, 2015 19:14
Elastic Beanstalk .ebextension sample for Django based project
packages:
yum:
libjpeg-turbo-devel: []
postgresql93-devel: []
container_commands:
01_migrate:
command: "django-admin.py migrate --noinput"
leader_only: true
02_initadmin:
@dkarchmer
dkarchmer / Django_Rest_Connection.py
Last active February 6, 2016 00:53
Python sample script for connecting to a Django Rest Framework based API
__author__ = 'David Karchmer'
'''
Main fucntionality to manage API calls to a Django based server (with django-rest-framework)
Demonstrates how to set token on header for secure gets/posts
'''
import json
import requests
import logging
DOMAIN_NAME = 'https://example.com'
@dkarchmer
dkarchmer / django-eb-fab.py
Last active July 3, 2017 10:20
Fabric based deploy script for a Python/Django Server with a Docker based worker
'''
Example of a deployment script for:
- A Django based server running as an Elastic Beanstalk server tier, with Load Balancing
(Assumes a pre-configured RDS database - best practice)
- A Docker based running as an Elastic Beanstalk worker tier
Assumes following directory structure
- ./server # With Django based project and appropriate .ebextensions
- ./worker # with Docker based project and appropriate .ebextensions, Dockerfile and Dockerrun.aws.json file
# (similar to https://github.com/dkarchmer/aws-eb-docker-django)
@dkarchmer
dkarchmer / django-gulpfile.js
Created December 8, 2015 17:31
Example of a Gulp file for processing a Django base template and releasing statics to cloudfront
/* Assumes the following directory structure:
* ./images # With original images
* ./base # With the index.html, css, js to be used to create a base template
* # This directory containts its own gulpfile (maybe coming from a yeoman or similar)
* ./server # Actual Django project, with a templates subdirectory
*/
var gulp = require('gulp');
var chug = require( 'gulp-chug' );
var awspublish = require('gulp-awspublish');
@dkarchmer
dkarchmer / ffmpeg-resize.js
Last active March 14, 2024 17:32
Example of NodeJS script to resize videos (to 1080P and 720P) using fluent-ffmpeg
(function () {
var ffmpeg = require('fluent-ffmpeg');
function baseName(str) {
var base = new String(str).substring(str.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") != -1) {
base = base.substring(0, base.lastIndexOf("."));
}
return base;
}
@dkarchmer
dkarchmer / ffmpeg-mosaic.js
Last active June 7, 2018 01:44
Node.js based script to build a mosaic of four videos (using fluent-ffmpeg)
// Based on http://pythonhackers.com/p/fluent-ffmpeg/node-fluent-ffmpeg
// and https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos
// Usage:
// node ffmpeg-mosaic.js file1.mp2 file2.mp4 file3.mp4 file4.mp4
// Generates out.mp4
var ffmpeg = require('fluent-ffmpeg');
var command = ffmpeg()