Skip to content

Instantly share code, notes, and snippets.

View jwhitlock's full-sized avatar

John Whitlock jwhitlock

View GitHub Profile
@jwhitlock
jwhitlock / convert_ga_pageview_export.py
Last active May 23, 2016 16:49
Convert a Google Analytics page view export to a useful CSV file
#!/usr/bin/env python
# Convert data from a Google Analytics export
# In GA: Behavior -> Site Content -> All Pages
# Adjust time range
# Change Show Rows to desired content
# Export -> CSV
from __future__ import print_function, unicode_literals
from collections import namedtuple
from datetime import timedelta
import csv
@jwhitlock
jwhitlock / editor-content.css
Last active June 21, 2016 23:38
Files that change with kuma PR #3852
/*!
* Font Awesome 4.1.0 by @davegandy - http://fontawesome.io - @fontawesome
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
*/@font-face{font-family:'FontAwesome';src:url(../../styles/libs/font-awesome/fonts/fontawesome-webfont.eot?v=4.1.0);src:url(../../styles/libs/font-awesome/fonts/fontawesome-webfont.eot?#iefix&v=4.1.0) format('embedded-opentype'),url(../../styles/libs/font-awesome/fonts/fontawesome-webfont.woff?v=4.1.0) format('woff'),url(../../styles/libs/font-awesome/fonts/fontawesome-webfont.ttf?v=4.1.0) format('truetype'),url(../../styles/libs/font-awesome/fonts/fontawesome-webfont.svg?v=4.1.0#fontawesomeregular) format('svg');font-weight:normal;font-style:normal}i[class*=" icon-"],i[class^=icon-]{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.icon-2x{font-size:2em}.icon-3x{fo
@jwhitlock
jwhitlock / keybase.md
Created July 9, 2016 20:37
Keybase.io proof

Keybase proof

I hereby claim:

  • I am jwhitlock on github.
  • I am jwhitlock (https://keybase.io/jwhitlock) on keybase.
  • I have a public key ASCM4TsGA3GcuQEIzhaDIRygGVov0DnLlcY522ujF7ZCVwo

To claim this, I am signing this object:

@jwhitlock
jwhitlock / fix01_show_constraint_violations.sql
Created August 25, 2016 00:21
SQL scripts for Bug 1293718
-- These have bad data in production
SELECT COUNT(*) AS account_emailaddress_orphan_users FROM `account_emailaddress` WHERE NOT EXISTS (SELECT * from `auth_user` WHERE `auth_user`.`id` = `account_emailaddress`.`user_id`);
SELECT * FROM `account_emailaddress` WHERE NOT EXISTS (SELECT * from `auth_user` WHERE `auth_user`.`id` = `account_emailaddress`.`user_id`);
SELECT COUNT(*) AS django_admin_log_orphan_content_types FROM `django_admin_log` WHERE NOT EXISTS (SELECT * FROM `django_content_type` WHERE `django_content_type`.`id` = `django_admin_log`.`content_type_id`);
SELECT * FROM `django_admin_log` WHERE NOT EXISTS (SELECT * FROM `django_content_type` WHERE `django_content_type`.`id` = `django_admin_log`.`content_type_id`);
SELECT COUNT(*) AS socialaccount_socialtoken_orphan_accounts FROM `socialaccount_socialtoken` WHERE NOT EXISTS (SELECT * FROM `socialaccount_socialaccount` WHERE `socialaccount_socialaccount`.`id` = `socialaccount_socialtoken`.`account_id`);
SELECT * FROM `socialaccount_socialtoken` WHERE
@jwhitlock
jwhitlock / .env
Last active November 15, 2016 23:22
Config files for using "sample" as the database name for Kuma development
COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml
@jwhitlock
jwhitlock / purge_docs.py
Created November 17, 2016 16:04
MDN/Kuma: Purge old deleted documents
# Run in ./manage.py shell_plus
from datetime import datetime, timedelta
last_week = datetime.now() - timedelta(days=7)
to_purge = Document.deleted_objects.filter(modified__lt=last_week)
print("%d documents to purge" % to_purge.count())
for doc in to_purge:
assert doc.deleted
print("Purging document '%s'" % doc.get_full_url())
doc.purge()
@jwhitlock
jwhitlock / cleanup_stale_contenttypes.py
Last active November 29, 2016 18:28
Cleanup stale ContentType content, Kuma
# Run in a shell_plus session
def scan_old_cts(dry_run=True):
for ct in ContentType.objects.order_by('id'):
if ct.model_class() is None:
ct_relations(ct, dry_run)
def ct_relations(ct, dry_run):
relations = [
('KeyAction', 'keyaction_set'),
@jwhitlock
jwhitlock / ask_ks_authors.py
Last active January 4, 2017 16:51
Send an email to KumaScript authors, asking about GitHub author information.
from django.core.mail import send_mail
from kuma.wiki.models import Revision
template = u"""\
Hi %(username)s,
I'm writing to ask three questions:
* Do you want credit for the edits you made to MDN's Kumascript macros when\
we move the archive to GitHub?
@jwhitlock
jwhitlock / process_tags.py
Last active January 10, 2017 19:10
Remove unused tags, and merge "duplicate" tags
# Designed to be pasted in a Django shell session
# Bug 1293749 - Add missing UNIQUE KEY indexes in production
# Some tags are duplicates according to collation, such as "Tag" and "tag"
# Prefer the tag with the most usage, falling back to smallest ID
# Drop unused tags, to simplify tag administration
tag_relations = (
(Tag, 'taggit_taggeditem_items', 'tags'),
(DocumentTag, 'wiki_taggeddocument_items', 'tags'),
(LocalizationTag, 'wiki_localizationtaggedrevision_items', 'localization_tags'),
@jwhitlock
jwhitlock / clear_it.py
Created January 24, 2017 23:07
Kuma: Clear a set of keys from memcache
# This works with Kuma's memcache implementation
from django.core.cache import caches
def clear_keys(prefix):
memcache = caches['memcache']
raw_memcache = memcache._cache
items = 100000
slabs = raw_memcache.get_stats('slabs')
max_slabs = max([int(report[1]['active_slabs']) for report in slabs])
deleted = 0