Skip to content

Instantly share code, notes, and snippets.

View WindfallLabs's full-sized avatar

Garin Wally WindfallLabs

View GitHub Profile
@WindfallLabs
WindfallLabs / logger.py
Created June 5, 2023 20:29
A logging utility
"""logger.py
Author: Garin Wally; May 9, 2023
This file provides a utility for creating logger objects for logging messages to a file.
"""
import datetime as dt
import logging
from pathlib import Path
# Strategy Pattern for GIS Data Processing
# As derived from:
# https://refactoring.guru/design-patterns/strategy/python/example#lang-features
from abc import ABC, abstractmethod
class Strategy(ABC):
# Using ABC (Abstract-Base-Class) and @abstractmethod forces
# the user to redefine the "main" method
@WindfallLabs
WindfallLabs / df_to_markdown.py
Created September 6, 2019 17:15
Convert DataFrame to Markdown (string)
import re
import pandas as pd
def df_to_markdown(df, index=False):
"""Converts a pandas DataFrame to a Markdown string.
Args:
df (DataFrame): dataframe to convert
index (bool): optionally, keep the DataFrame index (default False)
@WindfallLabs
WindfallLabs / pdf_page_cleaner.py
Created July 25, 2019 03:13
Reads a page from a PDF by page number and cleans the contents
import re
import string
import PyPDF2
def clean_pdf_text(pdfobj, page_num):
# Get text from PDF object by page number
page_text = pdfobj.getPage(page_num).extractText()
# Remove double-spaces
page_text = page_text.replace(" ", " ")
@WindfallLabs
WindfallLabs / my_tweaks.zs
Last active November 12, 2019 05:58
ZenScript for MC Recipies
///// Variables
///// Removals
///// Replacements/Alterations
import minetweaker.item.IIngredient;
///////////////////////////////////////////////////////////////////////////////
// Variables
///////////////////////////////////////////////////////////////////////////////
@WindfallLabs
WindfallLabs / make_config.py
Created August 7, 2017 21:08
Makes a geojson-dashboard config.json file from an input geojson file.
# -*- coding: utf-8 -*-
"""
Makes a geojson-dashboard config.json file from an input geojson file.
Author: Garin Wally; Aug 2017
Use:
> python make_config.py us_bounds.json
"""
import os
@WindfallLabs
WindfallLabs / switch.py
Last active November 27, 2016 15:35
A Python implementation of JavaScript switches
"""
swtich.py -- JS switches in Python (proof of concept)
Author: Garin Wally; Nov 2016
Just took the JavaScript tutorial at codecademy and thought switches were
pretty cool, so I coded one up in Python.
I have to admit, this implementation is not great, not pretty, and likely
not shorter than a standard if/elif/else block.
"""
@WindfallLabs
WindfallLabs / get_users.py
Created July 7, 2016 15:21
get_users.py -- Searches Window's /Users/ file for write-accessable user folders
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
get_users.py -- Searches Window's /Users/ file for write-accessable user folders
and returns a list of write-accessible folder names (i.e. likely user name).
"""
import os
def get_users():
import locale
n = unicode(raw_input().decode(locale.getpreferredencoding()))
# Where the input is `José`
@WindfallLabs
WindfallLabs / dump_tests.py
Created May 26, 2016 21:34
Test apsw shell.py for `.dump > file.sql` functionality
# -*- coding: utf-8 -*-
import os
import codecs
from subprocess import Popen, PIPE
import apsw
db = "test.sqlite"
sqlite = "sqlite3_test.sql"