View simple_cors_server.py
#!/usr/bin/env python3 | |
# encoding: utf-8 | |
"""Use instead of `python3 -m http.server` when you need CORS""" | |
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
class CORSRequestHandler(SimpleHTTPRequestHandler): | |
def end_headers(self): | |
self.send_header('Access-Control-Allow-Origin', '*') |
View eternal-march.py
from datetime import date | |
ordinal = lambda n: "%d%s" % (n, "tsnrhtdd" [(n // 10 % 10 != 1) * (n % 10 < 4) * n % 10::4]) | |
dom = date.today() - date(year=2020, month=3, day=1) | |
print(f"Today is March {ordinal(dom.days)}, 2020") |
View pre-commit
#!/usr/bin/env PYTHONIOENCODING=utf-8 python | |
# encoding: utf-8 | |
"""Git pre-commit hook which lints Python, JavaScript, SASS and CSS""" | |
from __future__ import absolute_import, print_function, unicode_literals | |
import os | |
import subprocess | |
import sys |
View paramiko-using-ssh-config.py
client = paramiko.SSHClient() | |
client._policy = paramiko.WarningPolicy() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh_config = paramiko.SSHConfig() | |
user_config_file = os.path.expanduser("~/.ssh/config") | |
if os.path.exists(user_config_file): | |
with open(user_config_file) as f: | |
ssh_config.parse(f) |
View register-qualys-assetview-connector-accounts.py
#!/usr/bin/env python3 | |
""" | |
Bulk register AWS Accounts with Qualys AssetView | |
Given a list of account IDs, registers them and prints CSV output of the Account | |
ID and External ID in the format expected by the account setup Terraform code. | |
A list of accounts to register can be obtained like this:: | |
$ grep -vf <(csvgrep --invert-match --columns 'External ID' --regex '^$' account-setup/qualys-assetview-accounts.csv | csvcut -c 'Account ID' | sed 1d) \ |
View custom-log-filtering-and-formatting.py
#!/usr/bin/env python | |
# encoding: utf-8 | |
from pprint import pformat, pprint | |
import logging | |
class PasswordMaskingFilter(logging.Filter): | |
"""Demonstrate how to filter sensitive data:""" |
View ocr-file.py
def ocr_file(filename, languages, output_base, temp_dir): | |
log.info("Launching tesseract on %s", filename) | |
output = subprocess.check_output(['tesseract', filename, output_base, | |
'-l', '+'.join(languages), TESSERACT_CONFIG], | |
cwd=temp_dir, | |
stderr=subprocess.STDOUT) | |
with OCR_STORAGE.open('%s/%s/%s.log' % (item_id, group, index), 'w') as log_f: | |
log_f.write(output) |
View test-coverage.py
#!/usr/bin/env python | |
""" | |
Run Django Tests with full test coverage | |
This starts coverage early enough to get all of the model loading & | |
other startup code. It also allows you to change the output location | |
from $PROJECT_ROOT/coverage by setting the $TEST_COVERAGE_OUTPUT_DIR | |
environmental variable. | |
""" |
View eternal-march.py
from datetime import date | |
ordinal = lambda n: "%d%s" % (n, "tsnrhtdd" [(n // 10 % 10 != 1) * (n % 10 < 4) * n % 10::4]) | |
dom = date.today() - date(year=2020, month=3, day=1) | |
print(f"Today is March {ordinal(dom.days)}, 2020") |
View ansible.cfg
[defaults] | |
interpreter_python = auto_silent | |
vault_password_file=get_vault_password_from_keyring | |
[ssh_connection] | |
# Enabling pipelining reduces the number of SSH operations required to | |
# execute a module on the remote server. This can result in a significant | |
# performance improvement when enabled, however when using "sudo:" you must | |
# first disable 'requiretty' in /etc/sudoers | |
# |
NewerOlder