Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
liquidgenius / Query.py
Last active May 15, 2019 01:51
A simple class that utilizes chained methods to query a MySQL table for designated columns. All records are returned. Inspired by pandas.
import pymysql
from pprint import pprint as pprint
__author__ = "Liquidgenius"
class Query:
def __init__(self, host, port, user, password, schema):
self.host = host
self.port = port
self.user = user
@liquidgenius
liquidgenius / asyncio_loops.py
Created May 10, 2019 01:20 — forked from lars-tiede/asyncio_loops.py
asyncio + multithreading: one asyncio event loop per thread
import asyncio
import threading
import random
def thr(i):
# we need to create a new loop for the thread, and set it as the 'default'
# loop that will be returned by calls to asyncio.get_event_loop() from this
# thread.
loop = asyncio.new_event_loop()
@liquidgenius
liquidgenius / download.py
Created May 9, 2019 16:07 — forked from garnaat/download.py
Use multiprocess to download objects from S3
"""
"""
import multiprocessing
import boto
import os
import sys
import datetime
import logging
import Queue
@liquidgenius
liquidgenius / papermill-papermill-s3.py
Created May 9, 2019 16:04
Papermill Utility for working with S3
# -*- coding: utf-8 -*-
"""Utilities for working with S3."""
from __future__ import unicode_literals
import logging
import threading
import zlib
import six
from boto3.session import Session
@liquidgenius
liquidgenius / docker-help.md
Created April 30, 2019 06:34 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@liquidgenius
liquidgenius / s3gzip.py
Created March 18, 2019 22:29 — 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
@liquidgenius
liquidgenius / boto3-gzip.py
Created March 18, 2019 22:25 — forked from tobywf/boto3-gzip.py
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""
@liquidgenius
liquidgenius / pendulum_to_pandas.py
Created February 27, 2019 03:26
Converts a Pendulum datetime to a Pandas datetime
def pendulum_to_pandas(pend_dt):
"""Converts a Pendulum datetime to a Pandas datetime
Parameters
-----------
pend_dt (Pendulum.datetime): Any Pendulum datetime. Pendulum datetimes include
nanoseconds that Pandas does not support.
Returns
--------
@liquidgenius
liquidgenius / pipenv_cheat_sheet.py
Created January 27, 2019 10:43
A cheat sheet of commands to make using pipenv easy.
# Pipenv Cheat Sheet
## Install pipenv
```
pip3 install pipenv
```
## Activate
```
pipenv shell
```
@liquidgenius
liquidgenius / generate_pd_timestamp_series.py
Created November 8, 2018 15:22
Generates a Pandas compatible Series of Timestamps using the Pendulum module. Addresses the issue where Pendulum Timestamps are not correctly converted to Pandas documented here: https://github.com/sdispater/pendulum/issues/246
import pendulum
import pandas as pd
def generate_pd_timestamp_series(start_year,
start_month,
start_day,
end_year,
end_month,
end_day,
time_zone,