Skip to content

Instantly share code, notes, and snippets.

Avatar

Petr Messner messa

View GitHub Profile
View .pythonrc.py
"""
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 Sep 18, 2009
AI examples. Not very fast/clever, no heuristic.
View eight_queens_solver.py
#!/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 / data.xml
Created Jan 6, 2010
Python XML example (etree)
View data.xml
<doc>
<person no="1234">
<name>Tomáš</name>
<surname>Těžký</surname>
</person>
<person no="7">
<name>Standa</name>
<surname>Blábol</surname>
</person>
</doc>
View rtail.py
#!/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
lepl (Python parsing module) example
View lepl-example.py
#!/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
View Makefile
all: a b
echo a
time ./a
time ./a
echo b
time ./b
time ./b
a: a.cc
g++ -O2 -o a a.cc
View simpleeditor.py
#!/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")
View getTags.py
#! /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 Aug 5, 2010
I just wanted to test and show something about processEvents
View qtexample.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()