Skip to content

Instantly share code, notes, and snippets.

@brutus
brutus / servbench.py
Created July 24, 2012 13:23
Very basic test server to try some stuff.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Serv Bench
Very basic test server to try some stuff.
"""
import sys
``ab -r -n 200 -c 200 http://localhost:8080/``
* pure sockets (max 5 connections, sleeptime=0.25ms)
Time taken for tests: 16.932 seconds
Requests per second: 11.81 [#/sec] (mean)
Failed requests: 507
* pure sockets (max 500 connections, sleeptime=0.25ms)
Time taken for tests: 50.088 seconds
Requests per second: 3.99 [#/sec] (mean)
Failed requests: 0
* threads (max 500 connections, sleeptime=0.25ms)
@brutus
brutus / decode_13.py
Created August 6, 2012 13:28
tsw decode
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import string
trans = string.maketrans(
string.lowercase,
string.lowercase[13:] + string.lowercase[:13]
@brutus
brutus / wtf-html5.py
Created November 8, 2012 11:58
HTML5 in WTForms
# -*- coding: UTF-8 -*-
"""
WTForms HTML5 Widgets
~~~~~~~~~~~~~~~~~~~~~
This modul adds HTML5 widgets to WTForms_.
It supports the new INPUT types for fields and also sets some of the
new INPUT attributes automatically (based on widget type and what kind of
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
lvm2
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 584 kB of archives.
After this operation, 1182 kB of additional disk space will be used.
Get:1 http://archive.raspbian.org/raspbian/ wheezy/main lvm2 armhf 2.02.95-7+rpi1 [584 kB]
Fetched 584 kB in 1s (577 kB/s)
Selecting previously unselected package lvm2.
DPI scale: 1
startup, version: 3047 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /home/brutus
packages path: /home/brutus/Dokumente/.config/sublime-text-3/Packages
state path: /home/brutus/Dokumente/.config/sublime-text-3/Local
hardware concurrency: 4
zip path: /opt/sublime_text/Packages
zip path: /home/brutus/Dokumente/.config/sublime-text-3/Installed Packages
found 7 files for base name Default.sublime-keymap
[pep8]
ignore = E111,E121,E127,E128,E501
max-line-length = 78
CREATE TABLE songs (
song_id INTEGER NOT NULL,
path VARCHAR(250) NOT NULL CHECK (TRIM(path) <> ''),
PRIMARY KEY (song_id)
);
CREATE TABLE commits (
commit_id INTEGER NOT NULL,
user VARCHAR(24) NOT NULL CHECK (TRIM(user) <> ''),
device VARCHAR(48) NOT NULL CHECK (TRIM(device) <> ''),
songcommits_table = Table(
'songcommits', Base.metadata,
Column('commit_id', Integer, ForeignKey('commits.commit_id')),
Column('song_id', Integer, ForeignKey('songs.song_id'))
)
class Commit(Base):
__tablename__ = 'commits'

Here is the query I use to get the data:

q = db.query(Stat, Song, Commit).join(Song).join(Commit)

Well, I actually use something like db.query(Stat.rating, Stat.play_count, Song.path, ....

Now I can filter the results like this:

if user:
  q = q.filter(Commit.user == user)