Skip to content

Instantly share code, notes, and snippets.

View jg75's full-sized avatar

James Garner jg75

  • Amber Engine
  • Michigan
View GitHub Profile
@jg75
jg75 / pointer_example.cpp
Created April 17, 2019 14:51
pass by reference vs pass by value
#include <iostream>
using namespace std;
struct record_t
{
int id;
};
void Mutable(record_t &record);
@jg75
jg75 / client_handler.py
Created April 29, 2019 16:07
Handles responses from boto3 client methods that can or can't be paginated and yields the results.
"""Boto3 client response handler."""
import boto3
class ClientHandler:
"""Boto3 client response handler."""
__slots__ = ["client", "method", "key", "paginator"]
def __init__(self, client, method, key):
"""Override."""
@jg75
jg75 / client_handler.py
Created April 29, 2019 16:14
Handles responses from boto3 client methods that can or can't be paginated and yields the results.
"""Boto3 client response handler."""
import boto3
class ClientHandler:
"""Boto3 client response handler."""
__slots__ = ["client", "method", "key"]
def __init__(self, client, method, key):
"""Override."""
@jg75
jg75 / super_mro.py
Last active May 2, 2019 18:13
super's behavior and method resolution order in multiple inheritance
"""
MRO (Method Resolution Order) with multiple inheritance is resolved via
a linearization algorithm that flattens a tree. In some cases, super()
is not bound to a classes superclass, but instead to a sibling depending
on the object's MRO.
"""
class Base:
def __init__(self, field, **kwargs):
@jg75
jg75 / threadpool_example.py
Last active May 16, 2019 15:39
threading and multiprocessing, two great tastes that taste great together
"""Threading vs. Multiprocessing thread pools example."""
import argparse
import logging
import multiprocessing.pool
import random
import threading
import time
logging.basicConfig(
"""An example of procedurally generated music using FoxDot."""
from atexit import register
from FoxDot import Clock, pluck, p1
def fibonacci(n):
"""Get a list of numbers in the fibonacci sequence."""
step = 1 if n >= 0 else -1
seq = [0, 1]
@jg75
jg75 / rekognition.py
Created May 20, 2019 17:51
Playing with AWS Rekognition
"""Playing with AWS Rekognition."""
import argparse
import hashlib
import json
import logging
import boto3
logging.basicConfig(
@jg75
jg75 / test_things.py
Last active May 29, 2019 18:52
PyTest ExampleMemoized function embedded in a handler function
from unittest import mock
import thing
import pytest
@pytest.fixture()
def mock_client(monkeypatch, request):
"""Mock the client."""
@jg75
jg75 / static-website-cdn-template.yml
Created August 19, 2019 19:47
CloudFormation Template: S3 static website, CloudFront CDN, CloudFront origin access identity, optional alternate domain name and ACM certificate
AWSTemplateFormatVersion: 2010-09-09
Description: Cloudformation Template
Parameters:
S3BucketParameter:
Description: S3 Bucket
Type: String
AliasParameter:
Description: CNAME (alternate domain names)
@jg75
jg75 / lambda_handler.js
Created October 16, 2019 20:13
Serverless VPC lambda skeleton
'use strict';
console.log('Loading function');
exports.handler = async (event, context) => {
console.log('Received event:', JSON.stringify(event, null, 2));
let responseBody = {
message: "This is a message",
input: event
};