Programming Methods & Algorithms scripts - Top 4 Download

Programming Methods & Algorithms script downloads

ASTVisitor generator

This script parses the online documentation for compiler.ast and generate code for a skeletal ASTVisitor class that includes stubs for all of the various visitNODE functions that you might need in a visitor, along with comments in each function that list that node type's attributes. ...
Python

Solving the Metaclass Conflict

Any serious user of metaclasses has been bitten at least once by the infamous metaclass/metatype conflict. This script contains a general recipe to solve the problem, as well as some theory and some examples. ...
Python

Readable switch construction

Python's lack of a 'switch' statement has garnered much discussion and even a PEP. The most popular substitute uses dictionaries to map cases to functions, which requires lots of defs or lambdas. While the approach shown in this script may be O(n) for cases, it aims to duplicate C's original 'switch' functionality ...
Python

Numeric base converter

This is a traditional base converter with the twist that it accepts any strings as the digits for the input and output bases. Besides all the normal base-converts, you can now create compact versions of huge numbers by converting them to a base that uses all the letters and numbers for ...
Python

Arithmetic coder

Arithmetic coder script is a simple but slow way of compression using arithmetic coding. ...
Python

How to disable debug logging in release version

When you release your program to client, its a good idea to disable all the debug messages. It is possible via custom configuring debug levels at all modules, but may be implemented using a simple wrapper around logging.getnted usinfunction. ...
Python

Format warnings for Visual Studio

Visual Studio can be configured to invoke a Python script during your build process. If you need to do this, you'll likely want to report errors and warnings in a way that Visual Studio will understand. This script uses the standard Python warnings framework, and installs a custom warning message formatter that ...
Python

Logging to a Jabber account

This script contains a handler class which sends a Jabber message for each logging event. If you have long-running scripts on many remote machines and you want to be alarmed if one of them crashes, use the JabberHandler to log it to your account. ...
Python

Curried functions

This script is a class to allow programmers to curry functions, so that arguments can be supplied one at a time instead of all at once. E.g., if  F = Curry(lambda a,b: a b), then F(1,2) == F(1)(2). ...
Python

Changing file attributes on windows

The win32api module offers SetFileAttributes whiles allows you to make changes to a file in windows. You can set a file to be read only, archive, hidden, etc. This script is simple and convenient to use. ...
Python

Finding the convex hull of a set of 2D points

This simple code calculates the convex hull of a set of 2D points and generates EPS files to visualise them. ...
Python

Implementation of sets using sorted lists

This script implements set operations using sorted lists as the underlying data structure. Advantages: - Space savings -- lists are much more compact than a dictionary based implementation. - Flexibility -- elements do not need to be hashable, only __cmp__ is required. - Fast operations depending on the ...
Python

Yet another Set class for Python

This script is a pure Pythonic implementation of a set class. The syntax and methods implemented are, for the most part, borrowed from PEP 218. ...
Python

Treat the Win32 Registry like a Python dict

This class wraps most of the win32api functions for accessing a registry. It will read and write all win32 registry types, and will de/serialize python objects to registry keys when a string or integer representation is not possible. ...
Python

Rating class with mapping interface

Rating class with mapping interface script deals with items sorted by value and accessed by key or rating index. ...
Python

Composite design pattern using dictionaries

The script illustrates the composite design pattern by using hierarchical dictionaries. It can be used to process hierarchical, tree-based data structures using Python dictionaries. ...
Python

Tail Call Optimization Decorator

This function decorates a function with tail call optimization. It does this by throwing an exception if it is it's own grandparent, and catching such exceptions to fake the tail call optimization. This function fails if the decorated function recurses in a non-tail contexif the de >/ ...
Python

Pythologic Prolog syntax in Python

Some of Python's powerful meta-programming features are used to enable writing Python functions which include Prolog-like statements. Such functions load a Prolog-like database. When coupled with a suitable inference engine for logic databases, this is a way to add logical programming -- the last unsupported major paradigm -- to Python. This ...
Python

An interval mapping data structure

This structure is a kind of dictionary which allows you to map data intervals to values. You can then query the structure for a given point, and it returns the value associated to the interval which contains the point.Boundary values don't need to be an integer ; in the test unit ...
Python

Poker hand primitives

This script handles logic for detecting straights and groups of repeats in the presence of wildcards and hands with more than five cards. ...
Python