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

@JoshCrosby
JoshCrosby / spark_boiler_collab.py
Created June 6, 2022 20:02
spark boiler plate for google colab.
import os
# Find the latest version of spark 3.0 from http://www.apache.org/dist/spark/ and enter as the spark version
# For example:
# spark_version = 'spark-3.0.3'
spark_version = 'spark-3.<enter version>'
os.environ['SPARK_VERSION']=spark_version
# Install Spark and Java
!apt-get update
!apt-get install openjdk-11-jdk-headless -qq > /dev/null
## 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 / get_all_s3_objects.py
Created November 5, 2020 14:52
Get more than 1000 objects for list objects
# https://stackoverflow.com/questions/54314563/how-to-get-more-than-1000-objects-from-s3-by-using-list-objects-v2/54314628
def get_all_s3_objects(s3, **base_kwargs):
continuation_token = None
while True:
list_kwargs = dict(MaxKeys=1000, **base_kwargs)
if continuation_token:
list_kwargs['ContinuationToken'] = continuation_token
response = s3.list_objects_v2(**list_kwargs)
yield from response.get('Contents', [])
if not response.get('IsTruncated'): # At the end of the list?
@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