Skip to content

Instantly share code, notes, and snippets.

@curzona
curzona / bdd.feature
Created November 6, 2013 06:12
pytest-bdd 0.6.1 vs 0.6.2 stacktrace comparison.
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too
@curzona
curzona / README.txt
Last active August 29, 2015 13:57
Build EDK2 in vagrant box with GCC46
# Creates a virtual machine and builds the EDK2 source
# VirtualBox and Vagrant must be installed first
vagrant box add base http://files.vagrantup.com/precise64.box
vagrant init
vagrant up
vagrant ssh
sudo apt-get update
sudo apt-get install build-essential git uuid-dev iasl
git clone https://github.com/curzona/edk2.git
@curzona
curzona / invert.py
Created March 8, 2014 17:42
Invert a bijective dictionary
dict(zip(d.values(), d.keys()))
@curzona
curzona / struct.py
Created March 8, 2014 17:43
Deeply convert dictionary to object(s)
class Struct:
def __init__(self, **entries):
for k, v in entries.items():
if isinstance(v, dict):
entries[k] = Struct(**v)
self.__dict__.update(entries)
d = {'a':{'b':1, 'c':2}, 'd':1}
@curzona
curzona / logging.py
Created March 8, 2014 17:44
Experimentation with python progress output loggers
import sys
import time
import logging
class Logger(logging.Logger):
indent = 0
def __init__(self, name, level=logging.NOTSET):
logging.Logger.__init__(self, name, level)
@curzona
curzona / test_xmlrpclib.py
Created March 8, 2014 17:45
Recipe for testing a xmlrpc interface with server and client.
import sys
import socket
from threading import Thread
if sys.version_info >= (3,0):
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.client import ServerProxy
else:
from SimpleXMLRPCServer import SimpleXMLRPCServer
from xmlrpclib import ServerProxy
@curzona
curzona / config_dict.py
Created March 8, 2014 17:46
Read config file into a dictionary with ConfigParser
import ConfigParser
def parser_config(filename):
dict = {}
config = ConfigParser.ConfigParser()
config.optionxform = str
config.read(filename)
for section in config.sections():
@curzona
curzona / logger.py
Created March 8, 2014 17:46
Logger with indentation and progress.
import sys
import time
import logging
class Logger(logging.Logger):
indent = 0
def __init__(self, name, level=logging.NOTSET):
logging.Logger.__init__(self, name, level)
@curzona
curzona / prompt.py
Created March 8, 2014 17:47
Prompt the user for a value.
import sys
import types
castor = {types.IntType:int, types.LongType:long, types.FloatType:float, types.BooleanType:bool}
def ask(message, default):
sys.stdout.write(message + " [" + str(default) + "]:")
input = sys.stdin.readline().strip()
if input == "":
@curzona
curzona / interactive.py
Created March 8, 2014 17:48
Recipe for interactive python command line application (REPL).
import sys
from optparse import OptionParser
def command(options, args):
function, parameters = args[0], args[1:]
print "You typed: {0}({1})".format(function, parameters)
def interactive(options, args):
print "Python interactive window. Type $help for a list of commands."