Skip to content

Instantly share code, notes, and snippets.

View JoshCrosby's full-sized avatar

Josh Crosby JoshCrosby

View GitHub Profile
@JoshCrosby
JoshCrosby / sqlachemy_session_context.py
Created January 5, 2024 16:20 — forked from naufalafif/sqlachemy_session_context.py
SQLAlchemy Session Context Manager
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from contextlib import contextmanager
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
@JoshCrosby
JoshCrosby / python-zeep-example.md
Created September 6, 2023 22:27 — forked from FilBot3/python-zeep-example.md
Python Zeep SOAP Example Write Up

Python Zeep SOAP Client

First, we'll look at the SOAP URL and see what Prefixes, Global Elements, Global Types, Bindings, and Services are provided by the SOAP Service.

You can do this by running zeep as a CLI tool.

export WSDL_URL="http://www.dneonline.com/calculator.asmx?WSDL"
python -m zeep $WSDL_URL

If .DS_Store was never added to your git repository, simply add it to your .gitignore file.

If you don't have one, create a file called

.gitignore

In your the root directory of your app and simply write

## How to hide API keys from github ##
1. If you have already pushed commits with sensitive data, follow this guide to remove the sensitive info while
retaining your commits: https://help.github.com/articles/remove-sensitive-data/
2. In the terminal, create a config.js file and open it up:
touch config.js
atom config.js
@JoshCrosby
JoshCrosby / biz_day.py
Created April 28, 2021 23:53 — forked from itsff/biz_day.py
Finding next business day in Python
from datetime import datetime, timedelta
def find_next_biz_day(days_away=1,
start=None,
is_holiday=lambda d: False):
"""
Finds a business day that is N days away
:param days_away: Days away (positive or negative)
:param start: Starting date (today if None)
@JoshCrosby
JoshCrosby / cloudwatch.tf
Created September 11, 2020 21:37 — forked from picadoh/cloudwatch.tf
EC2 Instance Scheduling (Stop/Start) with Terraform
### Cloudwatch Events ###
# Event rule: Runs at 8pm during working days
resource "aws_cloudwatch_event_rule" "start_instances_event_rule" {
name = "start_instances_event_rule"
description = "Starts stopped EC2 instances"
schedule_expression = "cron(0 8 ? * MON-FRI *)"
depends_on = ["aws_lambda_function.ec2_start_scheduler_lambda"]
}
# Runs at 8am during working days
"""Extract nested values from a JSON tree."""
def json_extract(obj, key):
"""Recursively fetch values from nested JSON."""
arr = []
def extract(obj, arr, key):
"""Recursively search for values of key in JSON tree."""
if isinstance(obj, dict):
@JoshCrosby
JoshCrosby / s3gzip.py
Created April 16, 2020 20:44 — forked from veselosky/s3gzip.py
How to store and retrieve gzip-compressed objects in AWS S3
# vim: set fileencoding=utf-8 :
#
# How to store and retrieve gzip-compressed objects in AWS S3
###########################################################################
#
# Copyright 2015 Vince Veselosky and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@JoshCrosby
JoshCrosby / s3_select.py
Created April 16, 2020 00:40 — forked from SrushithR/s3_select.py
Sample code to stream data from a JSON file in S3 using S3 select
"""
A sample funtion to perform S3 select operation on a JSON file stored in S3 bucket
The bucket and file names are stored as environment variables
"""
import os
import boto3
def get_data():
"""
Using S3 select to query data from S3
@JoshCrosby
JoshCrosby / log_aws_lambda_event_and_context.py
Created October 9, 2019 22:33 — forked from gene1wood/log_aws_lambda_event_and_context.py
A python AWS Lambda function which logs the contents of the event and context variables passed into the function.
from __future__ import unicode_literals
import logging
import json
logger = logging.getLogger(__name__)
logging.getLogger().setLevel(logging.INFO)
class PythonObjectEncoder(json.JSONEncoder):
"""Custom JSON Encoder that allows encoding of un-serializable objects