Skip to content

Instantly share code, notes, and snippets.

View verbalhanglider's full-sized avatar

Tyler Danstrom verbalhanglider

View GitHub Profile

Keybase proof

I hereby claim:

  • I am verbalhanglider on github.
  • I am verbalhanglider (https://keybase.io/verbalhanglider) on keybase.
  • I have a public key ASByzzfduMJMFY7VjNTMTDDjscvDkZxUqKnn6ScU_eaRhwo

To claim this, I am signing this object:

@verbalhanglider
verbalhanglider / temp_directory_tree.py
Last active May 12, 2018 16:32
Function to create a temporary directory with a defined directory tree
from tempfile import TemporaryDirectory
from os import _exit, mkdir
from io import BytesIO
def make_temp_tree():
td = TemporaryDirectory()
mkdir(join(td.name, 'ALTO'))
mkdir(join(td.name, 'JPEG'))
mkdir(join(td.name, 'TIFF'))
new_img1 = Image.new(mode='RGB', size=(128,128), color='blue')
@verbalhanglider
verbalhanglider / custom_iterator.py
Last active April 16, 2018 16:19
A simple example of a custom object with iter
class NewObject:
"""a class to demonsrate making a custom iterable
"""
def __init__(self, some_list):
"""instantiates an instance of the class
Takes parameter passed and sets the value of the property 'a'
:param list some_list: can be a list of anything
@verbalhanglider
verbalhanglider / simple_callback.py
Created April 16, 2018 16:02
An example of using callback functions
"""a real basic and super-contrived example of using callback functions
"""
from sys import argv, stdout
from os import _exit
def conditional_callback_1(a_string):
"""first conditional: change words that start with C to Dog
:param str a_string: the word that is being checked and possibley
@verbalhanglider
verbalhanglider / simple_class_creation_from_classmethod.py
Last active April 12, 2018 18:32
An example of using classmethod
class SimpleClass:
"""a new class to hold one property that has a value that is an int
"""
def __init__(self, some_param):
"""initializes a new instance of the class
:param int some_param: an integer to store on the new instance
"""
self.a = some_param
@verbalhanglider
verbalhanglider / argparse_with_custom_action.py
Created April 12, 2018 17:53
A tutorial example of A CLI module using an argparse.Action class instance to find all files in a directory tree
"""a tutorial example of A CLI module using an argparse.Action class instance to find all files in a directory tree
"""
from argparse import Action, ArgumentParser
from sys import argv, stderr, stdout
from os import _exit, scandir
from os.path import exists, isdir
__VERSION__ = "1.0.0"
@verbalhanglider
verbalhanglider / recursive_scandir_with_argparse.py
Last active April 12, 2018 17:56
A basic CLI module using argparse library to find and print out all files in a directory tree
"""a tutorial example of A CLI module using argparse to find all files in a directory tree
"""
from argparse import ArgumentParser
from sys import argv, stderr, stdout
from os import _exit, scandir
from os.path import exists
__VERSION__ = "1.0.0"
@verbalhanglider
verbalhanglider / recursive_scandir.py
Last active April 12, 2018 17:40
A basic recursive function using scandir to walk a directory tree
"""a tutorial example of a recursive function using scandir
"""
from sys import argv, stderr, stdout
from os import scandir
from os.path import exists
def find_all_the_files(path):
"""a recursive function to take a path on a disk and find all the files in a complicated directory tree