Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
@acdha
acdha / simple_cors_server.py
Last active March 22, 2025 19:47
Python 3: serve the current directory as HTTP while setting CORS headers for XHR debugging
#!/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 March 18, 2025 09:12
Comparing performance adding rows to a large table using innerHTML, the DOM API, React JSX and, eventually, React.createElement
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 / apache-log-to-redshift.py
Last active March 8, 2025 12:03
Load Apache combined format log files into AWS Redshift for analysis
#!/usr/bin/env python
# encoding: utf-8
"""
Convert Apache-compatible web log files to be easily loaded in AWS Redshift
Provide filenames to Apache combined format log files (.gz transparently handled) and outputs gzip compressed
tab-separated files which can be loaded into Redshift.
Output files will not be overwritten if they already exist, making bulk-conversion tasks repeatable::
#!/usr/bin/env -S uv run
# /// script
# dependencies = [
# "boto3",
# ]
# ///
"""
Report marketplace AMIs across all of the accounts in an Organization
Assumes AWS credentials for an account which has permission to query a Config
@acdha
acdha / curl-ttfb.sh
Created November 28, 2011 23:03
Use curl to measure and report HTTP response times (pre-, start- and total transfer)
#!/bin/bash
#
# Report time to first byte for the provided URL using a cache buster to ensure
# that we're measuring full cold-cache performance
while (($#)); do
echo $1
curl -so /dev/null -H "Pragma: no-cache" -H "Cache-Control: no-cache" \
-w "%{http_code}\tPre-Transfer: %{time_pretransfer}\tStart Transfer: %{time_starttransfer}\tTotal: %{time_total}\tSize: %{size_download}\n" \
"$1?`date +%s`"
@acdha
acdha / chupalambda
Created October 18, 2024 00:25
AWS Lambda sucker - handy for introspecting your Lambda packages
#!/bin/bash
set -e -u -o pipefail
LAMBDA="$1"
if [ -z "$LAMBDA" ]; then
echo "Usage: $0 lambda-function-name" > /dev/stderr; exit 1
fi
@acdha
acdha / ocr-file.py
Created March 17, 2014 22:49
Fragment of code used to process images with Tesseract OCR
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)
@acdha
acdha / Podman as a Docker Desktop replacement.md
Last active July 13, 2024 06:05
Instructions for using Podman as a Docker.app replacement on MacOS

Podman as a Docker Desktop alternative

Prerequisites

  1. Install Homebrew from https://brew.sh

Install Podman

$ brew install podman
@acdha
acdha / get-unicode-blocks.py
Created June 12, 2015 22:32
Ways to get the name of a Unicode block for a character in Python
#!/usr/bin/env PYTHONIOENCODING=utf-8 python
# encoding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import os
import re
import requests
@acdha
acdha / pre-commit
Last active April 18, 2024 02:22
Git pre-commit hook which runs various code linters. Install this to .git/hooks/pre-commit inside your favorite repos
#!/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