Skip to content

Instantly share code, notes, and snippets.

View dkarchmer's full-sized avatar

David Karchmer dkarchmer

View GitHub Profile
@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 / 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 / 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 / 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 / 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;
@dkarchmer
dkarchmer / docker-rpi3-image-setup
Created July 17, 2016 00:24
Steps to create a docker based RPi3 image
# Download latest image from http://blog.hypriot.com/downloads/. Assuming v0.8.0.
unzip hypriotos-rpi-v0.8.0.img.zip
# And identify SSD disk
diskutil list
# Unmount disk. Assuming we identified /dev/disk2 in previous step
diskutil unmountdisk /dev/disk2
# Flash SD card. May take up to 5min with no feedback
var getCookie = function (cname) { // eslint-disable-line no-unused-vars
var name = cname + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') { c = c.substring(1); }
if (c.indexOf(name) === 0) { return c.substring(name.length, c.length); }
}
return '';
};
AWSIID=$(aws ec2 run-instances --image-id ami-8da458e6 --count 1 --instance-type t2.micro \
--key-name myKeys --security-group-ids sg-XXXXXXXX \
| json -aH Instances | json -aH InstanceId); time aws ec2 wait instance-running
aws ecs register-task-definition --cli-input-json file://elasticsearch.json --region us-east-1
aws ecs register-task-definition --cli-input-json file://redis.json --region us-east-1
aws ecs list-task-definitions --region us-east-1
aws ecs run-task --task-definition foobar-elasticsearch:1 --count 1 --region us-east-1
@dkarchmer
dkarchmer / codeship-setup
Created December 1, 2016 22:40
Setup to run django-aws-template on codeship
if [ -d "${HOME}/cache/python3_env" ]; then echo "venv exists"; else virtualenv -p $(which python3) "${HOME}/cache/python3_env";fi
source "${HOME}/cache/python3_env/bin/activate"
pip install -r server/requirements/development.txt
nvm install 5
npm install -g gulp bower
cd webapp
bower install
npm install
cd ..