Skip to content

Instantly share code, notes, and snippets.

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
petrblahos / gtk_leds1.py
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")
self.set_border_width(6)
@petrblahos
petrblahos / gtk2.py
Created March 25, 2014 19:19
Small python gtk sample.
from gi.repository import Gtk, GLib
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")
self.set_border_width(6)
@petrblahos
petrblahos / tab_petr_ver1.py
Created March 29, 2014 18:46
Textual table
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
def make_text_table(row_count, column_width):
print "+",
for width in range(5):
print "-",
for width in range(2):
print "+",
for width in range(column_width):
print "-",
print "+"
'''
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
def make_text_table(row_count, column_width):
"""
Makes a textual table with the numbered rows and 2 columns. The first
column is 5 characters wide, the 2nd and 3rd columns are column_width
characters wide.
Params:
row_count The number of rows. The rows are then numbered
1 to row_count
column_width The width of the second and third column.
"""
@petrblahos
petrblahos / sym_in_py.py
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
petrblahos / sqlabaan.py
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
petrblahos / tiny1.py
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