Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / dms_source_endpoints.sh
Last active March 21, 2019 20:10
Create AWS DMS source endpoints
#! /bin/bash
# Connect to mongo db's via an ssh tunnel,
# get a list of dbs to create DMS source endpoints
# dms_source_endpoints.sh port proxy [ name:dns:port ... ]
create-ssh-tunnel() {
local endpoint=$1
ssh -L $tunnel_port:$endpoint $proxy -N &
echo $!
@jg75
jg75 / efs-user-data.sh
Created March 14, 2019 19:29
Setup EFS on EC2
yum install -y amazon-efs-utils; mkdir -p /efs; mount -t efs fs-id:/ /efs
"""
Sum of multiples.
l the limit
m the multiple
c the count the number of multiples (l / m)
s the sum of (mc + mc^2) / 2 for each multiple of m to l
for multiple multiples, subtract the sum of the multiples
that are common between the multiples
@jg75
jg75 / ec2-docker-install.sh
Created February 27, 2019 17:00
How to install docker on an EC2 instance
# Needs to run as root
yum update -y
amazon-linux-extras install docker
systemctl enable docker
usermod -a -G docker ec2-user
# The above can go into user-data,
# but you'll still need to reboot because of the group add
reboot
@jg75
jg75 / gist:95b04ca2131ba13a88ff29fe21e7b979
Created February 21, 2019 14:10
AmberEngine colors for slack
#444043,#444043,#F0A141,#ffffff,#df6d33,#Ffffff,#57c1ad,#cb2c42
@jg75
jg75 / ECS-Agent-UserData
Created January 7, 2019 20:08
UserData for ECS Agent on EC2 instances
#!/bin/bash
echo ECS_CLUSTER=My-Cluster >> /etc/ecs/ecs.config
echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config
"""Multiprocessing and threading."""
import logging
import multiprocessing.pool
import random
import threading
import time
logging.basicConfig(
level=logging.INFO,