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 April 25, 2024 07:13
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 / 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
@acdha
acdha / custom-log-filtering-and-formatting.py
Created February 26, 2014 21:19
Example of how to filter or apply custom formatting using Python's logging library
#!/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 / Podman as a Docker Desktop replacement.md
Last active September 21, 2023 16:00
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 / update_cloudflare_ingress_groups.py
Last active May 28, 2023 07:12
Ensure that AWS security groups have a list of the current Cloudflare CIDR ranges
#!/usr/bin/env python3
"""
Ensure that every security group tagged with 'AllowCloudflareIngress' has
an ingress rule allowing HTTPS in from every public Cloudflare edge IPv4 and
IPv6 CIDR block.
Note that HTTP is intentionally not enabled: use the always-HTTPS page rule for
that to avoid potential security problems.
"""
@acdha
acdha / newsblur.opml
Created May 15, 2023 14:08
Tech-related NewsBlur subscriptions
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.1">
<!--Generated by NewsBlur - newsblur.com-->
<head>
<title>NewsBlur Feeds</title>
<dateCreated>2023-05-15 14:04:44.095425</dateCreated>
<dateModified>2023-05-15 14:04:44.095425</dateModified>
</head>
<body>
<outline text="Web" title="Web">
@acdha
acdha / collapsed.py
Last active February 20, 2023 14:39
Django Haystack backend support for Solr's Collapsing query parser and Expand component
# encoding: utf-8
"""
Experimental SearchQuerySet exposing Solr's Collapse filter and Expand component
See https://cwiki.apache.org/confluence/display/solr/Collapse+and+Expand+Results
Usage::
sqs = sqs.collapse('item_grouping', sort='"score DESC, wdl_id ASC"')
sqs = sqs.expand(rows=2, fq='django_ct:core.file')
@acdha
acdha / filter_nones.py
Last active January 21, 2023 01:33
Example of how to exclude Nones from JSON-encoded output, optionally destructively
#!/usr/bin/env python3
"""
Example of how to non-destructively remove None values from an object before
JSON serialization
"""
import json
def filter_nones(obj):
@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
{
"plugins": [
"stylelint-order"
],
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4,
"function-comma-newline-after": "always-multi-line",
"function-comma-space-after": "always",
"function-parentheses-newline-inside": "always-multi-line",