Skip to content

Instantly share code, notes, and snippets.


David Karchmer dkarchmer

View GitHub Profile
dkarchmer / ffmpeg-mosaic.js
Last active Jun 7, 2018
Node.js based script to build a mosaic of four videos (using fluent-ffmpeg)
View ffmpeg-mosaic.js
// Based on
// and
// Usage:
// node ffmpeg-mosaic.js file1.mp2 file2.mp4 file3.mp4 file4.mp4
// Generates out.mp4
var ffmpeg = require('fluent-ffmpeg');
var command = ffmpeg()
dkarchmer / ffmpeg-resize.js
Last active Feb 25, 2021
Example of NodeJS script to resize videos (to 1080P and 720P) using fluent-ffmpeg
View ffmpeg-resize.js
(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 / django-gulpfile.js
Created Dec 8, 2015
Example of a Gulp file for processing a Django base template and releasing statics to cloudfront
View django-gulpfile.js
/* 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 /
Last active Jul 3, 2017
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 file
# (similar to
dkarchmer /
Last active Feb 6, 2016
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
dkarchmer / .ebextenstions__django-main.config
Created Dec 8, 2015
Elastic Beanstalk .ebextension sample for Django based project
View .ebextenstions__django-main.config
libjpeg-turbo-devel: []
postgresql93-devel: []
command: " migrate --noinput"
leader_only: true
dkarchmer /
Last active Oct 21, 2021
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 /
Last active Aug 29, 2017
Semi-generic Python Rest Client, assuming a DjangoRestFramework back-end (and using TokenAuthentication)
__author__ = 'dkarchmer'
This API generically supports DjangoRestFramework based APIs
It is based on, but customized for
Django Rest Frameworks, and the use of TokenAuthentication.
# Assuming
# v1_api_router.register(r'some_model', SomeModelViewSet)
dkarchmer / docker-compose-v2.yml
Created Feb 25, 2016
This shows a V2 Docker Compose example with a Django server/worker, redis, postgres, elasticcache and local dynamodb (for development)
View docker-compose-v2.yml
version: '2'
# Data
image: busybox
command: "true"
- /var/lib/postgresql/data
- /data
dkarchmer /
Last active Dec 17, 2021
Sample code for using RequestFactory to do Django Unit Testing - Get and Post
from django.test import TestCase, RequestFactory
from django.utils.importlib import import_module
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.messages.middleware import MessageMiddleware
from rest_framework import status
from .models import *