Skip to content

Instantly share code, notes, and snippets.

View matthewdeanmartin's full-sized avatar
🦥
Gotta upgrade the packages

Matthew Martin matthewdeanmartin

🦥
Gotta upgrade the packages
View GitHub Profile
@matthewdeanmartin
matthewdeanmartin / exception_decorator.py
Created February 2, 2015 20:00
Add this and I find out the app is constantly throwing errors that were previously hidden.
import sys
import traceback
# https://stackoverflow.com/questions/6666882/tkinter-python-catching-exceptions
# https://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python
# https://stackoverflow.com/questions/1415812/why-use-kwargs-in-python-what-are-some-real-world-advantages-over-using-named
def handle_tk_errors(method_to_decorate):
def wrapper(*args, **kwargs):
try:
@matthewdeanmartin
matthewdeanmartin / build.bat
Created June 2, 2015 15:58
My Python Build Script
REM assumes pywin, sphynx, nose, virtualenv, and py2exe
pushd %~dp0
REM Version switching
cd C:\Python33
CALL pywin setdefault 3.3
REM Virtual environment
echo %workon_home%
CALL workon nist33
#!/usr/bin/env bash
#ex
# !/usr/bin/env bash -ex
clear
# guarantee expected environment
pyenv local miniconda3-4.0.5
# fails inside .sh script!
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv activate mc-twitter-folk

Keybase proof

I hereby claim:

  • I am matthewdeanmartin on github.
  • I am matthewmartin (https://keybase.io/matthewmartin) on keybase.
  • I have a public key whose fingerprint is 60CC 3DB3 A57C F47B 5543 1D28 6EFF 334F F96B DA42

To claim this, I am signing this object:

# This is not built in to python!
# https://stackoverflow.com/a/28825390/33264
def digit_to_char(digit):
if digit < 10:
return str(digit)
return chr(ord('a') + digit - 10)
def str_base(number, base):
while number > 0:
number, digit = divmod(number, base)
@matthewdeanmartin
matthewdeanmartin / chant.py
Last active October 4, 2018 11:12
Convert arbitrary English text to almost chantable text
# coding=utf-8
import pyphen
dic = pyphen.Pyphen(lang='en')
# nature of reality (prajña)
text = "The removal of suffering then, requires a deep understanding of praj-na. While philosophical analysis of arguments and concepts is clearly necessary to develop this understanding, it is not enough to remove our unskillful mental habits and deeply ingrained prejudices, which require meditation, paired with understanding. According to the Buddha, we need to train the mind in meditation to be able to truly see the nature of reality, which is said to have the marks of suffering, impermanence and not-self. Understanding and meditation are said to work together to 'clearly see' the nature of human experience and this is said to lead to liberation."
line_length = 6
words = text.split(" ")
so_far = 0
@matthewdeanmartin
matthewdeanmartin / test_too_much_stepping.py
Created November 22, 2019 22:01
Parameterized Nose Tests
from nose_parameterized import parameterized
TEST_DATA = [
# and is the default operator
("(Harry and Potter)", "(Harry Potter)"),
("(Harry or Potter)", "(Harry Potter)"),
("(Harry NOT Potter)", "(Harry -Potter)"),
("\"Harry AND STONE\" NOT Potter", "\"Harry AND STONE\" -Potter"),
("\"Harry AND STONE\" NOT Potter", "\"Harry AND STONE\" -Potter"), # to step through this, you must step through them all!
]
from typing import Callable
def try_catch(to_try:Callable, to_catch:Callable, exception_type:Exception, to_finally:Callable):
try:
to_try()
except exception_type as exception:
to_catch(exception)
finally:
to_finally()
@matthewdeanmartin
matthewdeanmartin / check_markdown.sh
Created December 30, 2020 16:28
Markdown lint... next step is to "lint" the English with spell check, grammar check
#!/bin/bash
# npm install tidy-markdown@2.0.4 -g
# npm install -g markdownlint-cli
echo "running tidy-markdown (a node.js package)"
tidy-markdown<README.md >README.fix.md
rm README.md
mv README.fix.md README.md
echo "running markdownlint (a node.js package)"
@matthewdeanmartin
matthewdeanmartin / setuptools_scm weirdness.py
Created January 23, 2021 04:42
This is one weird library
# So how to bump versions with this library if you refuse to
# use setup.py
# and don't want .dev123 junking up your version numbers
from setuptools_scm import get_version
from setuptools_scm.version import guess_next_version
# custom versioning to get rid of .devX logic
def version_scheme(version):
verstr = str(version.tag)
ver = verstr.split(".")