Skip to content

Instantly share code, notes, and snippets.

View pmclanahan's full-sized avatar

Paul McLanahan pmclanahan

View GitHub Profile
@pmclanahan
pmclanahan / contribute.json
Last active November 25, 2023 02:33
Proposal Schema for contribute.json
{
// required
"name": "Name of the project. (e.g. Bedrock)",
"description": "Awesome website of sweetness",
"repository": {
"type": "git",
"url": "https://github.com/mozilla/bedrock"
},
// optional
@pmclanahan
pmclanahan / vm_manager.sh
Created March 31, 2010 15:36
Allows you to use both VirtualBox and KVM virtualization on the same machine.
#!/bin/sh
# Allows you to use both VirtualBox and KVM virtualization on the same machine.
# I replaced the commands to start both VB and KVM with this script.
# you'll also need to disable both services from starting automatically.
# sudo update-rc.d qemu-kvm disable
# sudo update-rc.d vboxdrv disable
case "$1" in
@pmclanahan
pmclanahan / middleware.py
Created November 22, 2010 19:25
Django 1.2+ middleware that allows you to set cookies from a request object.
from types import MethodType
from django.http import CompatCookie, HttpRequest
def _set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False):
self._resp_cookies[key] = value
self.COOKIES[key] = value
if max_age is not None:
@pmclanahan
pmclanahan / fields.py
Created July 3, 2012 13:27
A Compressed JSON Field for Django.
import zlib
from base64 import b64decode, b64encode
from django.db import models
# django-jsonfield
from jsonfield import JSONField
class CompressedJSONField(JSONField):
@pmclanahan
pmclanahan / managers.py
Created March 7, 2011 23:14
A class to reduce boilerplate for methods that should exist on Django model managers and querysets.
from django.db.models.manager import Manager
class PassThroughManager(Manager):
'''
Inherit from this Manager to enable you to call any methods from your
custom QuerySet class from your manager. Simply define your QuerySet
class, and return an instance of it from your manager's `get_query_set`
method.
@pmclanahan
pmclanahan / hostname_middleware.py
Created August 30, 2011 04:06 — forked from robballou/hostname_middleware.py
Django middleware for enforcing a hostname. Using at epio until they provide options for redirects at the loadbalancers.
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
class EnforceHostnameMiddleware(object):
"""
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts
"""
def process_request(self, request):
@pmclanahan
pmclanahan / sha1certcheck.sh
Created December 22, 2015 18:47
a bash function for checking whether an ssl endpoint is returning a sha1 cert for SSLv3
sha1certcheck() {
cert_type=$( : | openssl s_client -connect ${1}:443 -ssl3 -cipher 'DES-CBC3-SHA' 2>/dev/null <<< Q | openssl x509 -text | grep 'Signature Algorithm' | cut -d ':' -f 2 | uniq)
if [ "${cert_type:1}" = "sha1WithRSAEncryption" ]; then
echo "All's well"
else
echo "Bad cert type: $cert_type"
fi
}
@pmclanahan
pmclanahan / API_DOC.rst
Last active December 20, 2015 05:39
Basket API User Lookup documentation draft.

/news/lookup-user

method: GET
fields: token, or email and api-key
headers: x-api-key (instead of api-key parameter)
returns: { status: ok, user data } on success
         { status: error, desc: <desc> } on error
@pmclanahan
pmclanahan / dedupe_basket.py
Created June 14, 2013 12:38
From @dpoirier: Here's a stab at a script to fix up our Basket data given a set of email-token mappings.
# Draft script to fix the token mappings in the Basket database,
# given a list of valid email-token mappings
from django.db.models import Q
from news.models import Subscriber
# Let's assume we have the data in the form of a dictionary,
# where each key is an email address and its value is the corresponding
@pmclanahan
pmclanahan / new_json_format.md
Created June 12, 2013 01:15
JSON format for SWU.

I believe all the files can be processed into a single JSON file with the following format.

{
    "public-figures": ["first last", "first last", ...],
    "businesses": ["name", ...],
    "organizations": ["name", ...],
    "private-individuals": ["first last", ...],
    "members-of-congress": ["first last", ...]
}