Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@dkarchmer
dkarchmer / aws-lambda-picture-resize
Created May 20, 2016 04:12
Sample JavaScript code for resizing pictures on AWS Lambda
/**
* This is based on: http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser.html
*/
// dependencies
var async = require('async');
var AWS = require('aws-sdk');
var gm = require('gm').subClass({ imageMagick: true }); // Enable ImageMagick integration.
var util = require('util');
var MAX_WIDTH;
@dkarchmer
dkarchmer / django-filter-sample.py
Created May 2, 2016 00:26
How to use django-filter to add a DRF filter using dates and slugs
class SampleFilter(filters.FilterSet):
start_date = django_filters.DateFilter(name="date", lookup_type='gte')
end_date = django_filters.DateFilter(name="date", lookup_type='lte')
# How to filter by a foreign key that uses slug as a lookup
foo = django_filters.ModelMultipleChoiceFilter(
queryset=MyModel.objects.all(),
to_field_name='slug',
conjoined=True,
)
class Meta:
@dkarchmer
dkarchmer / new-mac.md
Last active November 14, 2019 22:33
Setting up a new Mac for Django and Docker development

before

  • Enable Firewall
  • Enable FileVault
  • Disable all sharing

Installation script

0.- Install XCode Compiler

@dkarchmer
dkarchmer / init.el
Created October 30, 2019 17:07
Emacs .emacs.d/init.el file with Python configuration
;; .emacs.d/init.el
;; ===================================
;; MELPA Package Support
;; ===================================
;; Enables basic packaging support
(require 'package)
;; Adds the Melpa archive to the list of available repositories
(add-to-list 'package-archives
@dkarchmer
dkarchmer / 8kbuttons.ino
Last active February 20, 2019 01:36
PODuino with multi-LED button
/* This project implements a multi-color (LED) button with the following specification:
*
* - Button starts as off, representing everything is good
* - A click changes the button to green and represents a request to start filling up a new order
* - The warehouse control can send a "receive" event, which turns color to light blue
* - Clicking button for more than 3sec resets button to off
* - Double click sets the button to red
*
*/
@dkarchmer
dkarchmer / AccessPointReadme.md
Last active February 8, 2019 02:01
Configuration Instructions for an IOTile Access Point

IOTile Access Point

Configuration Instructions

Requirements:

  • bled112 dongle on your machine
  • Create a Python virtual environment (Python 2.7 or 3.6)
  • Install:
@dkarchmer
dkarchmer / iotile_coretools_tutorial.md
Last active January 31, 2019 18:59
IOTile Core Tools Tutorial

IOTile Core Tools

Basics

The public facing documentation for the IOTile Core Tools is https://coretools.readthedocs.io/en/latest/introduction.html, but things change a little when you have access to a real device.

With a BLED112 dongle, and access to the proper packages, you can communicate with a real device.

After installation, the iotile operations can be run from the OS command-line, or by using the IOTile Shell.

@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');
import argparse
import time
import sys
from iotile.core.hw import HardwareManager
def build_parser():
parser = argparse.ArgumentParser(description="Print broadcast readings from a specific device")
parser.add_argument('-d', '--dev', type=lambda x: int(x, 0), help="Optional, the UUID of the device you want to see broadcasts from (0x21 for example)")
parser.add_argument('-i', '--interval', type=float, default=1.0, help="The minimum interval in seconds between two reported readings (only applies when -d is given), defaults to 1s")
@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()