Skip to content

Instantly share code, notes, and snippets.

View todd-cook's full-sized avatar

Todd Cook todd-cook

  • Burlingame
View GitHub Profile
/**
* Feel free to take a few minutes to read About Roman Numerals if you're not familiar:
* https://en.wikipedia.org/wiki/Roman_numerals
*/
public class RomanNumeralConverter {
public static int toArabic(String roman) {
//TODO : Your implementation here
return 1;
@todd-cook
todd-cook / gist:2605d92c4673256d0ec70cb2ea76381d
Last active October 18, 2017 00:07
Useful utility class
"""`counters` module - Utility model objects for results tracking."""
from typing import Any
from typing import Iterator
class Tally:
"""`Tally` class: a simple results counter: allows accumulation and addition of results.
>>> results = Tally(hits=1, misses=1)
>>> print(results)
ls -l | awk '/^-/ && $1=$1' OFS="," >list.csv
import argparse
from textblob import TextBlob
def deboilerplatify(blob):
"""PG boilerplates off"""
end_of_top_boilerplate = "Produced by Anonymous Volunteers"
pos = blob.find(end_of_top_boilerplate)
if pos:
blob = blob[pos + len(end_of_top_boilerplate):].strip()
@todd-cook
todd-cook / gist:32fdb6abdac3fcd0e59189ffc9188574
Created January 11, 2018 21:09
Python keywords and builtins - programmatically
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
>>> import builtins
>>> dir(builtins)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'Not
@todd-cook
todd-cook / gist:834364b2ff3b6fe92b13162862f24143
Created February 2, 2018 01:13
Rotate a block of text from a file
# rotate text in a file, such as banner text
# surprised this isn't a library function, for silly text operations
import sys
import re
def create_matrix(height):
matr = list()
for i in range(0, height):
matr.append(list())
@todd-cook
todd-cook / gist:f1d7d3ecb62e0da079aaa1418ac49cfa
Created February 5, 2019 19:58
Display git branch in terminal title, bash functions
# Add to .bash_profile
function gittitle() {
echo -n -e "\033]0;`git status | awk 'NR==1 {print $3}'`\007"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Some notes on this gist:
# all abstract and base class stuff has been moved to the top of the file so that import resolution
# and IDEs won't complain unnecessarily.
# _get_model_path is default method
# tokenize has been promoted to be a default method, and signatures downstream were made consistent with this;
# -- whether this is a great idea is open to debate
# The default list argument, a subtle bug, has been corrected, e.g. see https://docs.python-guide.org/writing/gotchas/
# the self : object annotation has been removed as it is implied and it confuses IDE.
spondaic 'at si staret' ait 'caelebs sine palmite truncus,
spondaic Aeneae genetrix, vidit quoque triste parari
spondaic Has ubi verborum poenas mentisque profanae
spondaic Hunc ubi laudatos iactantem in sanguine vultus
spondaic Maenala transieram latebris horrenda ferarum
spondaic adiectoque cavae supplentur corpore rugae,
spondaic admotumque fretum remis tellusque repulsa est,
spondaic aversata gemit; certa est exquirere nutrix
spondaic bella instructa gerunt, multumque ab utraque cruoris
spondaic bellaque non transfert, et sunt, qui parcere Troiae
@todd-cook
todd-cook / gist:feddb1d50baa0f2550520a1eeca62e5e
Created March 24, 2020 04:26
Graph Covid-19 cases in US, March
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
dates_infections = {'3/1': 89,
'3/2': 105,
'3/3': 125,
'3/4': 159,
'3/5': 227,
'3/6': 331,
'3/7': 444,