Skip to content

Instantly share code, notes, and snippets.

Chris Adams acdha

Block or report user

Report or block acdha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@acdha
acdha / custom-log-filtering-and-formatting.py
Created Feb 26, 2014
Example of how to filter or apply custom formatting using Python's logging library
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:"""
@acdha
acdha / simple_cors_server.py
Last active Feb 2, 2020
Python 3: serve the current directory as HTTP while setting CORS headers for XHR debugging
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', '*')
@acdha
acdha / initial results.txt
Last active Jan 27, 2020
Comparing performance adding rows to a large table using innerHTML, the DOM API, React JSX and, eventually, React.createElement
View initial results.txt
Render using innerHTML took:0.140s; tbody height=536364px
Render using DOM took:0.076s; tbody height=536364px
Render using React took:1.443s; tbody height=536364px
@acdha
acdha / pre-commit
Last active Nov 19, 2019
Git pre-commit hook which runs various code linters. Install this to .git/hooks/pre-commit inside your favorite repos
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
@acdha
acdha / paramiko-using-ssh-config.py
Created Jul 23, 2013
Connecting with paramiko using the user's OpenSSH config
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 enable-autocomplete.js
/*
To avoid polluting the global namespace this uses an anonymous
function which is called with either the URL for an external
JavaScript file or a function. In either case jQuery will be loaded
from the Google CDN before your code is executed so it's free to
depend on jQuery without checking for it and can do things like
jQuery.getScript() to load other components (e.g. jQuery UI),
stylesheets, etc.
*/
(function (target, msg) {
@acdha
acdha / test-coverage.py
Created Jan 28, 2010
A custom Django test runner with support for coverage.py and graceful handling for app selection and various testing gotchas
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.
"""
@acdha
acdha / vertical-centering.css
Last active Sep 5, 2019
How to vertically center arbitrary contents using flexbox with backwards compatibility for IE10, Safari 5.1, Android < 4.4, etc.
View vertical-centering.css
.vertical-center {
display: -moz-box;
-moz-box-align: center;
display: -webkit-box;
-webkit-box-align: center;
display: -ms-flexbox;
-ms-flex-align: center;
display: -webkit-flex;
-webkit-align-items: center;
display: flex;
@acdha
acdha / tasks.json
Last active May 21, 2019
VSCode task for gulp watch output capturing
View tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "gulp",
"task": "watch",
"label": "gulp: watch",
"isBackground": true,
"presentation": {
"reveal": "always",
@acdha
acdha / warm-item-pages.js
Last active May 14, 2019
Simple PhantomJS script to warm multiple pages as fast as possible
View warm-item-pages.js
/*
* Warm a WDL web server by requesting our top pages using a full web browser
*/
var system = require('system');
var page = new WebPage(),
hostnames = [],
items = [],
customHeaders = {};
You can’t perform that action at this time.