Skip to content

Instantly share code, notes, and snippets.

TIL from reading an early Jan post on the Django mailing list. Turns out that PyPI is making a whole bunch of data available on Google BigQuery.

In a subsequent post, Alex Gaynor gave us a query that extracts Python versions used to download a package on PyPI in the previous two weeks:

SELECT
  REGEXP_EXTRACT(details.python, r"^([^\.]+\.[^\.]+\.[^\.]+)") as python_version,
  COUNT(*) as download_count,
FROM
#!/usr/bin/env python
from urllib import urlopen
content = urlopen('http://markets.brntn.me').read().decode()
clinton = float(content.split('Clinton:<span class="text-right">')[-1].split('%')[0])
trump = float(content.split('Trump:<span class="text-right">')[-1].split('%')[0])
updated = content.split('Updated: ')[-1].split('\n')[0]
@sesh
sesh / base.html
Created August 2, 2016 02:54
My base.html for Django Projects
{% load static %}<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}base.html via @sesh{% endblock %}</title>
<!-- Favicons in 32x32 and 16x16 -->
@sesh
sesh / faq.md
Created July 21, 2016 10:44 — forked from shangxiao/faq.md
django faq

Frequently asked questions:

  • Why shouldn't i use mysql? / mongo?
  • Should I use jinja, I read it's faster?
  • Should I use sqlalchemy, I read it's superior?
  • How do i make this thing happen in parallel/not wait for xxx to finish?
  • Why does django ask for a default? (But my table has no data in it wtf django!?!)
    • FunkyBob | I think, perhaps, it's time I wrote a blog post on "why does a migration adding a field need a default?"
  • Why do I need to commit my migrations? Why can't I just run makemigrations on the server?
  • migrations are source, makemigrations is a helper which takes you part way
  • i've seen people accidentally lose their migrations on production…  oops now what?
@sesh
sesh / election-data.json
Created May 9, 2016 11:07
Election Data from The Guardian
This file has been truncated, but you can view the full file.
{
"sheets": {
"rawData": [
{
"date": "17/03/1996",
"pollster": "Newspoll",
"sample": "1000",
"LNP2PP": "59.81964336",
"ALP2PP": "40.18035664"
},
@sesh
sesh / minimal_vulnerable.py
Last active March 10, 2016 04:44
minimal_vulnerable.py
"""
An example for MelbDjango 2.8 by Brenton C.
This demonstrates both the most minimal possible Django implementation:
https://github.com/rnevius/minimal-django
And an exploit of the security issue fixed with Django 1.9.3:
https://www.djangoproject.com/weblog/2016/mar/01/security-releases/
To run locally simple install Django < 1.9.3 (or Django < 1.8.10) in a virtualenv and run:
@sesh
sesh / easypass.py
Created February 17, 2016 04:31
Easy Passwords
import random
def easypass(length=2, joiner='-'):
with open('wordlist.txt') as f:
words = f.readlines()
return joiner.join([random.choice(words).strip() for x in range(length)])
if __name__ == '__main__':
from django.conf.urls import include, url
from django.contrib import admin
ADMIN_URLS = [
'wp-admin/', # wordpress
'admin.php',
'login.php',
'phpmyadmin/',
'admin/login.php',
@sesh
sesh / tests.py
Last active August 29, 2015 14:27 — forked from mekhami/tests.py
class ProjectViewsTest(TestCase):
def setUp(self):
self.project = Project.objects.create(name='google')
self.client = Client()
def test_project_display_context_data(self):
response = self.client.get('/project/{}/'.format(self.project.slug))
self.assertIn('form', response.context)
@sesh
sesh / tests_form_defaults.py
Created August 4, 2015 22:39
Django Form Defaults
from django.db import models
from django import forms
from django.test import TestCase, RequestFactory
from .models import BooleanTestModel
"""
models.py