The way this solution inspects the flask context at the time of record formatting, rather than creation, is evil. Here is a better solution: https://gist.github.com/danielrichman/1acbbd66166ab857c404
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostgreSQLConnection(psycopg2.extensions.connection): | |
""" | |
A custom `connection_factory` for :func:`psycopg2.connect`. | |
This | |
* puts the connection into unicode mode (for text) | |
* modifies the :meth:`cursor` method of a :class:`psycopg2.connection`, | |
facilitating easy acquiring of cursors made from | |
:cls:`psycopg2.extras.RealDictCursor`. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/daniel/venv/bin/python | |
import sys | |
import os | |
import couchdbkit | |
password_filename = os.path.join(os.path.dirname(sys.argv[0]), 'couch') | |
with open(password_filename) as f: | |
couch_uri = f.readline().strip() | |
server = couchdbkit.Server(couch_uri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from flask import request, session, abort, Markup | |
@app.template_global('csrf_token') | |
def csrf_token(): | |
""" | |
Return the CSRF token for the current session | |
If not already generated, session["_csrf_token"] is set to a random | |
string. The token is used for the whole life of the session. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.template_filter('sidsplit') | |
def sidsplit(sid, chunk_size=10): | |
n = len(sid) / chunk_size | |
chunks = [sid[i * chunk_size : (i + 1) * chunk_size] for i in range(n)] | |
if len(sid) % chunk_size: | |
chunks.append(sid[n * chunk_size:]) | |
return Markup('<wbr>').join(chunks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.template_global('show_which_pages') | |
def show_which_pages(page, pages, show=5): | |
""" | |
Work out which page numbers to display | |
Pages are numbered 1 to pages, inclusive. | |
page: the current page | |
pages: the total number of pages. | |
show: maximum number of pages to show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
from subprocess import Popen, PIPE | |
from email.mime.text import MIMEText | |
from email import message_from_string | |
from poplib import POP3_SSL | |
emails = [ | |
('[email protected]', 'pop.mail.yahoo.com'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import glob | |
import gzip | |
import datetime | |
logfiles = glob.glob("/var/log/exim4/mainlog*") | |
time_format = "%Y-%m-%d %H:%M:%S" | |
def all_lines(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2013 Daniel Richman; GNU GPL 3 */ | |
/* gcc -Wall -Werror -pedantic -O2 -o tail_dmesg tail_dmesg.c */ | |
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <sys/klog.h> | |
#include <unistd.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Copyright (C) 2010 Daniel Richman | |
* This is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |