Skip to content

Instantly share code, notes, and snippets.

petrblahos /
Created October 12, 2012 17:52
Symbolická matematika v Pythonu
class Expression(object):
def __add__(self, rt):
return Plus(self, rt)
def __sub__(self, rt):
return Minus(self, rt)
def __mul__(self, rt):
return Multiply(self, rt)
def __div__(self, rt):
return Divide(self, rt)
petrblahos /
Created November 12, 2012 10:28
SQLAlchemy dialect for renamed columns
import copy
import sqlalchemy.engine.base
import sqlalchemy.dialects.mssql.base
import sqlalchemy.dialects.mssql.pyodbc
class SQLABaanRowProxy(sqlalchemy.engine.base.RowProxy):
def __init__(self, parent, row, processors, keymap):
For all keys starting with "t_" adds also a "t$..." key.
petrblahos /
Created December 6, 2012 19:23
tiny wsgi with webob
from webob import Response
class TinyApp(object):
def __call__(self, environ, start_response):
resp = Response("""<html><body>AHOJ</body></html>""")
return resp(environ, start_response)
if __name__ == '__main__':
from wsgiref.simple_server import make_server
petrblahos /
Created December 6, 2012 19:31
Slightly less tiny webob app
import time
from webob import Request, Response
from webob import exc
def slow_generator():
yield "<html><body><h1>Starting</h1>\n"
for i in range(10):
yield("%s: Hello!!! Hello!!! Hello!!! Hello!!! Hello!!! Hello!!!<br>\n" % (i+1))
petrblahos / gist:4541213
Created January 15, 2013 19:21
import sys
import unittest
class _WritelnDecorator(object):
"""Used to decorate file-like objects with a handy 'writeln' method"""
def __init__(self,stream): = stream
def __getattr__(self, attr):
if attr in ('stream', '__getstate__'):
raise AttributeError(attr)
petrblahos / gist:5050586
Created February 27, 2013 18:59
Small example of usage.
import json
import bottle
def text():
return "Returning text"
def get_data():
sleep 2400
state=`grep "sd[ab] " /proc/diskstats`
echo "starting" >> /haltit
while [ ${same_counter} -le 60 ] ; do
case "$1" in
echo "starting sleep_on_dist" >> /etc/zyxel/storage/sysvol/.debian/root/ssstart
/etc/zyxel/storage/sysvol/.debian/root/ &
echo "started?" >> /etc/zyxel/storage/sysvol/.debian/root/ssstart
import csv
import sqlite3
import sys
db_con = sqlite3.connect(":memory:")
db_con.text_factory = str
def safe_column_name(name):
Modifies the column name so that it only contains alphanumeric
petrblahos /
Created March 19, 2014 18:58
Small Gtk app that toggles images according to the button state.
from gi.repository import Gtk
class LedControl(Gtk.Window):
A simple app that changes images according to the button status.
def __init__(self):
Gtk.Window.__init__(self, title="LED Control")