Skip to content

Instantly share code, notes, and snippets.

View sanscore's full-sized avatar

Grant Welch sanscore

  • San Jose, CA
View GitHub Profile
@sanscore
sanscore / letter_boxed.py
Last active August 11, 2020 23:00
NYTimes Puzzle Solvers
#!/usr/bin/env python
import re
from textwrap import indent, fill
def dict_words():
"""ALL THE WORDS!!1"""
re_dict_words = r"^[a-z]{4,}$"
with open("/usr/share/dict/words") as words_file:
content = words_file.read() # .lower()
@sanscore
sanscore / backoff.py
Last active June 15, 2019 04:23
Python "backoff" decorator
def backoff(test_func, reason=None):
def decorator(func):
@wraps(func)
def inner(*args, **kwargs):
if test_func(*args, **kwargs):
return None
result = None
for wait_secs in [0, 1, 4, 9, 16, 32, 64, 128, 256, None]:
result = func(*args, **kwargs)
@sanscore
sanscore / commit-msg
Last active July 10, 2017 18:26
git commit-msg hook to verify the line lengths of the message
#!/usr/bin/env bash
#
# Usage:
# Copy to your /usr/share/git-core/templates/hooks directory,
# and to any existing git repos.
#
# Copy to existing git repos (except those with existing 'commit-msg'):
# find $HOME -name '.git' -type d -exec test '!' -e "{}/hooks/commit-msg" ';' \
# -exec cp /usr/share/git-core/templates/hooks/commit-msg "{}/hooks" ';'
#
@sanscore
sanscore / post-checkout
Last active June 5, 2017 18:36
git post-checkout hook to assign work/personal email address
#!/usr/bin/env bash
#
# Usage:
# Personalize: WORK_DIR, WORK_EMAIL, PUBLIC_EMAIL, etc.
# Copy to your /usr/share/git-core/templates/hooks directory,
# and to any existing git repos.
#
# Unset user.{name,email}
# git config --global --unset user.name
# git config --global --unset user.email
@sanscore
sanscore / conftest.py
Last active December 31, 2019 11:51
print(...) tracing for pytest.
import inspect
import pytest
def pytest_addhooks(pluginmanager):
print(inspect.currentframe().f_code.co_name)
def pytest_namespace():
@sanscore
sanscore / selenium_fx50_1_0.py
Last active January 6, 2017 22:25
Fx50.1.0 FirefoxProfile Proxy Settings cause https://www.python.org to be considered "Insecure".
# Repro "unknown" issue with GeckoDriver and Firefox 48+
# Setup Details:
# Firefox 50.1.0
#
# Selenium Server Standalone v3.0.1
# GeckoDriver 0.12.0
#
# Python 2.7.12
# pip freeze:
@sanscore
sanscore / json-pretty.rb
Last active July 3, 2016 20:40
A pretty JSON parser.
#!/usr/bin/env ruby
# gem: gem install json_cat
# project: https://github.com/sanscore/json_cat
# rubygems: https://rubygems.org/gems/json_cat
require 'time'
require 'json'
require 'optparse'
require 'rainbow'