Skip to content

Instantly share code, notes, and snippets.

View maxwillzq's full-sized avatar

John maxwillzq

  • Google
View GitHub Profile
@maxwillzq
maxwillzq / classinheritExample.py
Created December 10, 2012 20:50
Base1 and Base2 inherit common calss BaseBase. Then myClass inherit the base1 and base2. Show how the function is searched.
class BaseBase(object):
def method(self):
print "BaseBase"
a = BaseBase()
a.method()
class Base1(BaseBase):
pass
class A(object):
def __init__(self):
print "A"
super(A, self).__init__()
class B(object):
def __init__(self):
print "B"
super(B, self).__init__()
@maxwillzq
maxwillzq / diff-like.py
Created December 13, 2012 02:36
diff like utitlity
# -*- coding: utf-8 -*-
""" Command line interface to difflib.py providing diffs in four formats:
* ndiff: lists every line and highlights interline changes.
* context: highlights clusters of changes in a before/after format.
* unified: highlights clusters of changes in an inline format.
* html: generates side by side comparison with change highlights.
"""
@maxwillzq
maxwillzq / LinkedList.py
Created December 14, 2012 17:49
A class about LinkedList
import sys
from opus7.exception import *
#{
class LinkedList(object):
"""
Linked list class.
"""
#}@head
# file test.py
import cmd
class HelloWorld(cmd.Cmd):
def do_greet(self,person=''):
print "hello,",person
def help_greet(self):
print '\n'.join(['greet [person]',
'greet the named person',
])
def complete_greet(self,text,line,begidx,endix):
#Example
import functools
@functools.total_ordering
class Job(object):
def __init__(self,priority,descr):
self.priority = priority
self.descr = descr
def __eq__(self,other):
#descriptor example
class RevealAccess(object):
def __init__(self,initval=None,name='var'):
self.val = initval
self.name = name
def __get__(self,obj,objtype):
print "Retrieving",self.name
return self.val
@maxwillzq
maxwillzq / Python overview code sample.py
Created January 13, 2013 06:27
Day 0 Overview of python
#code sample
# from wiki.python.org/moin/SimplePrograms
# "1 line: Output"
print "hello,world"
# 2 lines: input,assignment
name= raw_input('What is your name?\n')
print 'Hi %s.' % name
class QuickFindUF(object):
def __init__(self,N):
self.__id = []
for i in range(N):
self.__id.append(i)
def connected(self,p,q):
return self.__id[p] == self.__id[q]
class WeightedQuickUnionUF(object):
def __init__(self,N):
self.__id = []
self.sz = []
for i in range(N):
self.__id.append(i)
self.sz.append(1)
def root(self,i):
while(i!=self.__id[i]):