Skip to content

Instantly share code, notes, and snippets.

View figure002's full-sized avatar
🏠
Working from home

Serrano Pereira figure002

🏠
Working from home
View GitHub Profile
@figure002
figure002 / sqla_bug_test.py
Last active August 29, 2015 14:07
Demonstration of a possible SQLAlchemy bug
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Demonstrate a possible bug in SQLAlchemy.
Setting the `echo` argument of sqlalchemy.create_engine() crashes some versions
of SQLAlchemy. Tested with Python 2.7.6. See results for SQLAlchemy versions
below.
Setting ENGINE_ECHO to True or False (depending on your SQLAlchemy version)
# colored stream handler for python logging framework (use the ColorStreamHandler class).
# based on:
# http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output/1336640#1336640
# Copyright (c) 2014 Markus Pointner
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@figure002
figure002 / gist:7487a97808a870f41804
Last active August 29, 2015 14:03
Eliminating subqueries
-- How to eliminate the following sub queries?
INSERT INTO photos_tags (photo_id, tag_id) VALUES (?, (SELECT id FROM tags WHERE name=?));
-- Becomes:
INSERT INTO photos_tags (photo_id, tag_id) SELECT ?, id FROM tags WHERE name=?;
# -*- coding: utf-8 -*-
import codecs
import subprocess
from fdfgen import forge_fdf
from django.template import Template, loader
from django.template.loader import find_template, LoaderOrigin
class PdfTemplateError(Exception):