Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@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()
@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 / 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 / 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_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 / .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 / cognito-developer-authenticated-client-example.py
Last active October 11, 2024 16:44
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 / djangorestframework-client.py
Last active August 29, 2017 03:11
Semi-generic Python Rest Client, assuming a DjangoRestFramework back-end (and using TokenAuthentication)
__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 February 25, 2016 01:38
This shows a V2 Docker Compose example with a Django server/worker, redis, postgres, elasticcache and local dynamodb (for development)
version: '2'
services:
# Data
dbdata:
image: busybox
command: "true"
volumes:
- /var/lib/postgresql/data
- /data
@dkarchmer
dkarchmer / django_request_factory_test.py
Last active September 20, 2023 06:19
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 *