Skip to content

Instantly share code, notes, and snippets.

@andialbrecht
andialbrecht / customtreemodel.py
Created January 5, 2013 19:46
Simple script demonstrating a custom Gtk.TreeModel for Gtk 3 (known as GenericTreeModel in PyGtk 2).
#!/usr/bin/env python3
# This script demonstrates a custom TreeModel (known as
# GenericTreeModel in PyGtk 2).
#
# Note: This script requires python-gi (pygobject) >= 3.4.
from gi.repository import GObject, Gtk
@andialbrecht
andialbrecht / models.py
Created March 11, 2011 12:03
Adds Meta option db_column_prefix that prepends a per-model prefix to db column names
# -*- coding: utf-8 -*-
# This hack adds a new Meta option "db_column_prefix". If not None all
# database columns in a model will be prepended with this prefix (the
# database columns, not the attributes). See Person model for an
# example.
#
# Issues:
# - How to set a prefix for a m2m table? - If "through" argument is
# not specified on a M2MField, Django automatically adds a model
-- Calculates some kind of hammond tuning
-- See https://electricdruid.net/technical-aspects-of-the-hammond-organ/
local Ratios = {
{85, 104},
{71, 82},
{67, 73},
{105, 108},
{103, 100},
@andialbrecht
andialbrecht / gist:917126
Created April 13, 2011 07:26
Regex to parse pylint output
# Regex to extract error messages from "pylint -f parseable" output
import re
P_PYLINT_ERROR = re.compile(r"""
^(?P<file>.+?):(?P<line>[0-9]+):\ # file name and line number
\[(?P<type>[a-z])(?P<errno>\d+) # message type and error number, e.g. E0101
(,\ (?P<hint>.+))?\]\ # optional class or function name
(?P<msg>.*) # finally, the error message
""", re.IGNORECASE|re.VERBOSE)
@andialbrecht
andialbrecht / sqlformat_example.html
Created April 15, 2015 15:44
Minimal SQL Format Example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SQLFormat API Example</title>
<!-- Include JQuery library -->
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
@andialbrecht
andialbrecht / gist:8669031
Created January 28, 2014 14:54
Test runner traceback
### This happened because Django was imported from my global site-packages (Django 1.6)
python tests_v2/main.py
make: »uploadv2.pyz« ist bereits aktualisiert.
urls_tests.url_map: (ImportError('No module named defaults',), 'Traceback (most recent call last):\n File "tests_v2/main.py", line 85, in TestRunner\n rslt = m()\n File "/home/andi/devel/rietveldv2/tests_v2/support/test.py", line 76, in run\n new = self.test_func(*self.args, **self.kwargs)\n File "/home/andi/devel/rietveldv2/tests_v2/urls_tests.py", line 16, in url_map\n import urls\n File "/home/andi/devel/rietveldv2/urls.py", line 18, in <module>\n from django.conf.urls.defaults import *\nImportError: No module named defaults\n')
uploadv2/general_tests.archive_contents: 'OK'
cas/default_type_tests.default_map: (ImportError('No module named defaults',), 'Traceback (most recent call last):\n File "tests_v2/main.py", line 85, in TestRunner\n rslt = m()\n File "/home/andi/devel/rietveldv2/tests_v2/support/
# Migrate from sentry-comments to build in notes.
#
# See also https://github.com/andialbrecht/sentry-comments/issues/11
# Especially when you're upgrading from Sentry 6.3.
#
# To run this script:
# sentry --config=your.conf.py shell
# >>> import migratecomments.py
# >>> migratecomments.migrate()
#
@andialbrecht
andialbrecht / fetch_weather.py
Created January 11, 2014 15:52
Weekend fun project. I've copied wlandevices.sh via FTP to my FritzBox, copied the other two scripts to my Raspberry and added a cron that runs fetch_wlanlist.py (sorry for the name) every 5 minutes. The script checks if known devices are close to the wlan router which is located in our living room and greets the (supposed) user with a warm welc…
#!/usr/bin/env python3
import json
import os
from urllib.request import urlopen
URL = 'http://api.openweathermap.org/data/2.5/weather?id=2953398&lang=de'
@andialbrecht
andialbrecht / tulipshell.py
Created May 27, 2013 18:26
Helper to run a background tulip loop in an interpreter session.
# -*- coding: utf-8 -*-
"""Set up an interactive interpreter to have a underlying tulip loop.
The setup() function replaces the default loop policy, that starts a loop only
for the main thread, by a policy that has a single global loop available in any
thread.
The loop will be started when calling setup() in a background thread so that
the main thread could still be used by the interactive shell.
application: your-app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: demo.application