Skip to content

Instantly share code, notes, and snippets.

@sesh
sesh / urls2.0.md
Created January 19, 2018 20:52
Django URLs 2.0 (MelbDjango Talk)

Django URLs 2.0


Django 2.0

  • Released December, 2017
  • Major features:
    • Only supports Python 3.4 and above
  • Mobile-friendly admin interface
@sesh
sesh / admin.py
Last active July 18, 2020 05:53
Django Custom User Model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from .models import User
class CustomUserAdmin(UserAdmin):
fieldsets = (
(None, {'fields': ('email', 'password')}),
// Pace your settings in this file to overwrite the default settings
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"window.zoomLevel": 0,
"files.insertFinalNewline": true,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
}
  • 1password
  • bitbar
  • Caffiene
  • Dash
  • f.lux
  • Handbrake
  • Hemmingway App
  • Homebrew
  • ImageOptim
  • iStat Menus
@sesh
sesh / TUNE.py
Created March 9, 2017 04:10
Download audio files from youtube links in a reddit thread
#!/usr/bin/env python3
"""
Download audio files from youtube links in a reddit thread.
Works a treat on /r/music/
Usage:
./TUNE.py <url>
Requirements: youtube-dl, beautifulsoup4, python>=3.5

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"
},