Skip to content

Instantly share code, notes, and snippets.

Avatar

David Karchmer dkarchmer

View GitHub Profile
@dkarchmer
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 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()
@dkarchmer
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
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
dkarchmer / django-eb-fab.py
Last active Jul 3, 2017
Fabric based deploy script for a Python/Django Server with a Docker based worker
View django-eb-fab.py
'''
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_Rest_Connection.py
Last active Feb 6, 2016
Python sample script for connecting to a Django Rest Framework based API
View Django_Rest_Connection.py
__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 / .ebextenstions__django-main.config
Created Dec 8, 2015
Elastic Beanstalk .ebextension sample for Django based project
View .ebextenstions__django-main.config
packages:
yum:
libjpeg-turbo-devel: []
postgresql93-devel: []
container_commands:
01_migrate:
command: "django-admin.py migrate --noinput"
leader_only: true
02_initadmin:
@dkarchmer
dkarchmer / cognito-developer-authenticated-client-example.py
Last active Oct 21, 2021
django-boto3-cognito: AWS' Cognito Developer Authenticated Identities Authflow using Django/Python/Boto3 (For building stand-alone clients)
View cognito-developer-authenticated-client-example.py
__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 / djangorestframework-client.py
Last active Aug 29, 2017
Semi-generic Python Rest Client, assuming a DjangoRestFramework back-end (and using TokenAuthentication)
View djangorestframework-client.py
__author__ = 'dkarchmer'
"""
See https://gist.github.com/dkarchmer/d85e55f9ed5450ba58cb
This API generically supports DjangoRestFramework based APIs
It is based on https://github.com/samgiles/slumber, but customized for
Django Rest Frameworks, and the use of TokenAuthentication.
Usage:
# Assuming
# v1_api_router.register(r'some_model', SomeModelViewSet)
@dkarchmer
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'
services:
# Data
dbdata:
image: busybox
command: "true"
volumes:
- /var/lib/postgresql/data
- /data
@dkarchmer
dkarchmer / django_request_factory_test.py
Last active Dec 17, 2021
Sample code for using RequestFactory to do Django Unit Testing - Get and Post
View django_request_factory_test.py
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 *