import pandas as pd
import numpy as np
View models.py
from moneyed import Money | |
from psycopg2.extras import register_composite | |
from psycopg2.extensions import register_adapter, adapt, AsIs | |
MoneyValue = register_composite( | |
'money_value', | |
connection.cursor().cursor, | |
globally=True | |
).type |
View 2a-Leaflet-marker-emoji.html
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Leaflet - Emoji marker</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/> | |
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script> | |
<style> | |
.mymarker { font-size: 50px; } |
View models.py
from django.db import models | |
from django.db.models import Avg | |
class Blog(models.Model): | |
name = models.CharField(max_length=100) | |
rating = models.DecimalField(max_digits=5, decimal_places=2, null=True) | |
def __str__(self): | |
return self.name |
View pycon8_conference_talk_ranking.md
View process_memory_usage_osx.sh
# On Linux we can use native GNU time, on OSX we have to install gnu-time | |
# manually, since native time doesn't measure memory. | |
# http://man7.org/linux/man-pages/man1/time.1.html | |
# http://braumeister.org/formula/gnu-time | |
$ brew install gnu-time | |
# can be called via gtime, since time is a bash command | |
# %M - Maximum resident set size of the process during its lifetime, in Kbytes. |
View chromelogger.py
""" | |
License: MIT - https://opensource.org/licenses/MIT | |
ChromeLogger is a protocol which allows sending logging messages to the Browser. | |
This module implements simple support for Django. It consists of two components: | |
* `LoggingMiddleware` which is responsible for sending all log messages | |
associated with the request to the browser. | |
* `ChromeLoggerHandler` a python logging handler which collects all messages. |
View trigram_migration.py
# -*- coding: utf-8 -*- | |
# XXX this is actually useful for very special use cases, e.g. misspel suggestions: | |
# https://www.postgresql.org/docs/9.6/static/pgtrgm.html#AEN180626 | |
from __future__ import unicode_literals | |
from django.db import migrations | |
from django.contrib.postgres.operations import TrigramExtension | |
class Migration(migrations.Migration): | |
operations = [ |
View a2dp.py
#! /usr/bin/env python3.5 | |
""" | |
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04 and also debian jessie, with bluez5. | |
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197 | |
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone. | |
This will be only fixes the bluez5 problem mentioned above . |
View test_unmanaged_models.md
Scenario
- Django 1.9 application with two databases:
- Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to
False
'managed': False
- Default database holding django specific tables (e.g. auth_user, django_content_type, etc)
- Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to
Testing Woes
- For testing I want to re-create the legacy database tables. In other words, during
python manage.py test
, tell Django to set "managed" toTrue
- There are several excellent blog posts on how to set "managed" to
True
during tests:
- There are several excellent blog posts on how to set "managed" to
View signals.py
# coding:utf-8 | |
import gc | |
import inspect | |
import weakref | |
from django.core.management.base import BaseCommand, CommandError | |
from django.dispatch import Signal | |
from django.dispatch.weakref_backports import WeakMethod | |
from optparse import make_option |
NewerOlder