Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@messa
messa / .pythonrc.py
Created September 16, 2009 14:33
My settings
"""
Startup script for Python interactive mode
Add these two lines to .bashrc:
PYTHONSTARTUP="$HOME/.pythonrc.py"
export PYTHONSTARTUP
"""
import sys, os, readline, atexit
@messa
messa / eight_queens_solver.py
Created September 18, 2009 13:58
AI examples. Not very fast/clever, no heuristic.
#!/usr/bin/env python
class EightQueens:
def __init__(self):
self.array = 64 * [-1]
def get(self, x, y):
return self.array[x + y * 8]
@messa
messa / .gitignore
Created November 18, 2009 16:26
SVN log with diffs
*.pyc
@messa
messa / data.xml
Created January 6, 2010 22:04
Python XML example (etree)
<doc>
<person no="1234">
<name>Tomáš</name>
<surname>Těžký</surname>
</person>
<person no="7">
<name>Standa</name>
<surname>Blábol</surname>
</person>
</doc>
#!/usr/bin/env python
"""
Usage:
./rtail.py user@host:path/foo.log bar.log host2:/path/baz.log
"""
import optparse
import os
@messa
messa / lepl-example.py
Created May 5, 2010 12:00
lepl (Python parsing module) example
#!/usr/bin/env python2.6
from lepl import *
retezec = String() | String("'")
cislo = Digit()[1:] > (lambda chars: int("".join(chars)))
slovnik = Delayed()
klicSlovniku = retezec | cislo
hodnotaSlovniku = retezec | cislo | slovnik
all: a b
echo a
time ./a
time ./a
echo b
time ./b
time ./b
a: a.cc
g++ -O2 -o a a.cc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Až moc jednoduchý textový editor.
Vlevo je seznam úryvků, dvojklikem na nějaký se úryvek vloží do textu.
"""
import pygtk
pygtk.require("2.0")
#! /usr/bin/python
# -*- coding: UTF-8 -*-
import settings
import urllib
import xml.etree.ElementTree as etree
class getTags:
def __init__(self):
@messa
messa / qtexample.py
Created August 5, 2010 12:20
I just wanted to test and show something about processEvents
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()