Skip to content

Instantly share code, notes, and snippets.

import java.util.Comparator;
import java.util.List;
public class SlowSort {
public static <T extends Comparable<? super T>> void slowSort(T[] array) {
slowSort(array, 0, array.length);
}
public static <T> void slowSort(T[] array, Comparator<? super T> comparator) {
@mavc
mavc / json_parser.py
Created October 1, 2012 18:46
pyparsing and ply demonstration
import re
from ply import lex, yacc
from ply.lex import TOKEN
import pyparsing as pp
# First, let's define a pyparsing parser for JSON.
class JSONPyParsing(object):
# pylint: disable-msg=W0104,E0213
@mavc
mavc / jsonparser.py
Created September 29, 2012 05:00
pyparsing demonstration
"""
Sample JSON decoder for demonstrating how to use pyparsing.
"""
import pyparsing as pp
# JSON types are number, string, boolean, object, array, and null.
# A boolean is either the literal 'true' or the literal 'false'. Set a
# parsing action that just replaces it with the Python equivalent.
boolean = (
@mavc
mavc / boyermoore.py
Created November 1, 2011 03:32
Boyer-Moore string search
'''
Boyer-Moore exact string search, implemented from the description
given in:
http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/bmen.htm
'''
def _bad_character_shift(pat):
''' Calculates the bad character shift as the distance of the
@mavc
mavc / pdict.py
Created October 10, 2011 23:30
Priority Queue
'''
Created on 2011-10-09
Modified Python Recipe: http://code.activestate.com/recipes/522995/
@author: mavc
'''
from heapq import heapify, heappop, heappush
__all__ = ['PriorityDict']