Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@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 / supervisord.conf
Created April 26, 2016 17:01
Sample supervisord conf for running a python script in the background
; Assumes dockerfile with:
; ENTRYPOINT ["/usr/bin/supervisord", "-c", "/var/app/supervisord.conf"]
[supervisord]
;logfile=/var/app/logs/ ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
loglevel=debug ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
@dkarchmer
dkarchmer / drf-nested-views.py
Last active December 21, 2023 19:47
Example of a Django Rest Framework ViewSet with nested views
# ViewSets define the view behavior.
class FooViewSet(viewsets.ModelViewSet):
lookup_field = 'slug'
queryset = Foo.objects.all()
serializer_class = FooSerializer
def get_queryset(self):
"""
This view should return a list of all records
"""
@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 *
@dkarchmer
dkarchmer / python-script-template.py
Created June 10, 2017 19:04
Python Script Template with logging and arguments
import sys
import os
import argparse
import getpass
import logging
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger('upload_bom')
if __name__ == '__main__':
@dkarchmer
dkarchmer / Ubuntu19.10-DockerCompose.md
Last active January 19, 2023 10:59
Installing Docker Compose on Ubuntu to run from ECR docker repos

Ubuntu 19.10 with Docker Compose

Installing Ubuntu 19.10 with latest docker, docker-compose.

Install Ubuntu

Install latest Ubuntu 19.10 and then upgrade to latest

sudo apt-get update
@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 / datatable-django-template-example.html
Created June 27, 2016 17:21
Example of a Django Template instantiating a Data Table
{% extends "base.html" %}
{% load i18n %}
{% block media %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/bs/dt-1.10.10,r-2.0.0/datatables.min.css"/>
{% endblock %}
{% block js %}
<!-- DataTable -->
<script type="text/javascript" src="https://cdn.datatables.net/s/bs/dt-1.10.10,r-2.0.0/datatables.min.js"></script>
@dkarchmer
dkarchmer / WSL2-Ubuntu.txt
Last active December 15, 2021 05:17
Windows 10 WSL Ubuntu Setup
sudo apt-get update
sudo apt-get upgrade
# Store Github credentials
git config --global credential.helper store
git clone ...
# Install Python
sudo apt-get install -y python
sudo apt-get install python3.8
@dkarchmer
dkarchmer / windows10.md
Last active March 2, 2021 01:13
Windows 10 Setup

Install

  • Docker for Windows
  • Visual Studio Code (or IDE of choice), but VSCode supports WSL2 very well.
  • Github Desktop (optional)
  • Evernote (Personal)
  • Slack App, Notion App, Twist App (optional)
  • Chrome and/or Firefox and set as default

Choco should be used to manage packages