Skip to content

Instantly share code, notes, and snippets.

Avatar

David Karchmer dkarchmer

View GitHub Profile
@dkarchmer
dkarchmer / python-script-template.py
Created Jun 10, 2017
Python Script Template with logging and arguments
View python-script-template.py
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 / returnObservableWithNestedForkJoin.ts
Created Feb 19, 2017
Example of Angular2/TypeScript function returning an Observable after executing two nested forkJoin
View returnObservableWithNestedForkJoin.ts
public fetchABunchOfData (rootObj: RootObj): Observable<Project> {
// Returned original RootObj as an Observer when nested resource is fetched
let returnedData = new ReplaySubject(1);
let firstObservable = Observable.forkJoin(
this._cloud.getSomeRestData(rootObj.id),
this._cloud.getOtherRestData(rootObj.id)
);
// Execute first two Rest calls (someData and OtherData)
@dkarchmer
dkarchmer / codeship-setup
Created Dec 1, 2016
Setup to run django-aws-template on codeship
View codeship-setup
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 ..
@dkarchmer
dkarchmer / drf-nested-views.py
Last active May 27, 2021
Example of a Django Rest Framework ViewSet with nested views
View drf-nested-views.py
# 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
"""
View ECS-scripts
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
View getCookie.js
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 '';
};
@dkarchmer
dkarchmer / rds-cache-tasks.py
Last active Apr 30, 2018
Invoke Tasks to create RDS and ElasticCache instances
View rds-cache-tasks.py
import os
import sys
import time
import boto3
import botocore
import pprint
from invoke import run, task
DB_CONFIG = {
# SecurityGroup='sg-name" with ingress on port 5432 and source from itself
@dkarchmer
dkarchmer / docker-rpi3-image-setup
Created Jul 17, 2016
Steps to create a docker based RPi3 image
View docker-rpi3-image-setup
# 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
@dkarchmer
dkarchmer / sample-arduino-101-notify-random.ino
Created Jul 10, 2016
Sample Arduino 101 code advertising BLE characteristic with 'BLERead | BLENotify'
View sample-arduino-101-notify-random.ino
//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 / datatable-django-template-example.html
Created Jun 27, 2016
Example of a Django Template instantiating a Data Table
View datatable-django-template-example.html
{% 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>