Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@dkarchmer
dkarchmer / process_sqs_messages.py
Created April 14, 2016 20:09
Using Boto3 to process SQS messages
import boto3
# Get the service resource
sqs = boto3.resource('sqs')
# Get the queue. This returns an SQS.Queue instance
queue = sqs.get_queue_by_name(QueueName='my-queue')
# You can now access identifiers and attributes
logger.info(queue.url)
@dkarchmer
dkarchmer / docker-machine-aws-create.sh
Created April 22, 2016 16:55
How to create a docker-machine for AWS
#!/bin/bash
echo "Creating docker machine on AWS: $1"
source .env
docker-machine create -d amazonec2 \
--amazonec2-access-key=$AWS_ACCESS_KEY_ID \
--amazonec2-secret-key=$AWS_SECRET_ACCESS_KEY \
--amazonec2-vpc-id=$AWS_VPC_ID \
--amazonec2-instance-type=c4.4xlarge \
@dkarchmer
dkarchmer / view_api_with_pagination.py
Created April 24, 2016 01:45
How to paginate a custom detail_route get on djangorestframework
# 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 / 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 / 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 / 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 / mac--bash_profile
Last active April 17, 2018 17:16
Sample .bash_profile for a new Mac (See new-mad.md setup)
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
gpip(){
# gpip allows to install on global env
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
@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 / sample-arduino-101-notify-random.ino
Created July 10, 2016 19:19
Sample Arduino 101 code advertising BLE characteristic with 'BLERead | BLENotify'
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
#include <CurieBLE.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;