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__':
sudo apt-get install unzip;
wget -O /tmp/chromedriver.zip http://chromedriver.googlecode.com/files/chromedriver_linux64_19.0.1068.0.zip && sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/;
@sesh
sesh / gist:7132492
Last active December 26, 2015 09:49
MelbDjango website, basic requirements

Phase 1

Hosted on Heroku (we can use my account for now).

Ability to make Posts

  • Posts should have a published date

Ability to make Events (could be a subclass of Post?)

  • has a date, time, duration and location
  • can have many speakers

MySQL: dumped

Maybe you've read some of the [PHP hate] (http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/) that's out there. I used to write PHP and you know, it works, you can get things done. The same goes for MySQL. I kind of feel like in this day and age MySQL is the relational database analogue of the [lingering legacy of the PHP singularity] (http://www.codinghorror.com/blog/2012/06/the-php-singularity.html).

Basically, MySQL works and you can definitely use it to build and run successful applications. Facebook uses it. But the important point to consider is that Postgres ..... is better. It's more or less a fact. How and why? Well there are numerous articles out there for you to google up but [here's a screencast] (http://www.youtube.com/watch?v=1PoFIohBSM4) that gives you a reasonable breakdown, by example.

So just like I left PHP behind, now I've left MySQL behind. You could say I've mysqldumped it forever. Now, [WHO'S COMIN WITH ME?!] (http://www.youtube.com/wat