This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# run 'python num_line.py -v' to see doctest results. | |
# Howard Hamilton | |
# 17 March 2014 | |
def number_line(L, I): | |
''' | |
Update number line intervals with addition of new interval. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# trie.py | |
# | |
# create trie data structure | |
# | |
class Node(object): | |
""" | |
Node element of trie data structure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# commit_transfer.py | |
# | |
# I wrote this script in order to transfer commits between branches in a less painful way. The use | |
# case is rebasing a working branch on its parent in order to use changes that have been pushed there. | |
# Yes, a rebase does preserve history, but only if you haven't already pushed the branch to a remote. | |
# If you have, it's best to create a fresh branch from the parent and transfer the commits there. | |
# | |
# My tasks are tracked in JIRA, so I write all of my commits with the following convention: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An outline for identifying N players with similar summary statistics to a player of interest. | |
A list of candidate players is compiled by filtering on position and end-of-season age. | |
Summary statistics are scaled to z-scores, which are the inputs to the machine learning model. | |
This algorithm uses K-Nearest Neighbor, but other algorithms (eg K-Means Clustering) can be substituted. | |
(c) 2015 Soccermetrics Research LLC | |
This code is licensed under the terms of the MIT License (http://choosealicense.com/licenses/mit/) | |
""" | |
from sklearn.neighbors import NearestNeighbors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A Python context to move in and out of directories. | |
Copyright 2016-2020, Howard Hamilton. | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | |
associated documentation files (the "Software"), to deal in the Software without restriction, in- | |
cluding without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do | |
so, subject to the following conditions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegexpReplacer(object): | |
""" | |
Take in list or dictionary of regex patterns and substitutes, and apply them to text with a map. | |
""" | |
def __init__(self, patterns): | |
if type(patterns) is dict: | |
self.patterns = [(re.compile(r"{}".format(regex)), patterns['replace']) | |
for regex in patterns['pattern']] | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import subprocess | |
from io import BytesIO | |
def execute_command(cmd, ns=__name__, shell_flag=False): | |
""" | |
Execute command using a subprocess, and write streaming output to the screen. | |
:param cmd: Command-line statement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree | |
from lxml.builder import E | |
if __name__ == "__main__": | |
with open('sample.xml') as f: | |
xml = f.read() | |
new_xml = E.Wrapper(etree.XML(xml)) | |
print(etree.tostring(new_xml, pretty_print=True)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"disable_existing_loggers": false, | |
"formatters": { | |
"default": { | |
"format": "%(asctime)s - %(name)s - %(levelname)s: %(message)s" | |
}, | |
"console": { | |
"format": "%(name)-12s: %(message)s" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# unique list of dictionaries | |
# --------------------------- | |
# This problem comes up when I bulk insert records into databases | |
# because I can't check for existence of records (they don't exist yet, too slow, etc) | |
# | |
# I typically use a set to make list elements unique, but dicts and lists themselves | |
# can't be inserted in sets because they're mutable and thus unhashable. | |
# | |
# Solution is to make a tuple of the dict's items and insert it in set, | |
# then create dicts from each member of the set. |
OlderNewer