code
stringlengths
1
1.72M
language
stringclasses
1 value
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
# # Copyright (c) 2010 Sony Pictures Imageworks Inc. # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # Redistributions of source code must retain the above copyright # notice, this list of c...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks, Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with ...
Python
#!/usr/bin/env python2.5 #-*- mode: python -*- ##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistrib...
Python
#!/usr/bin/env python2.6 #-*- mode: python -*- ##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistrib...
Python
##-***************************************************************************** ## ## Copyright (c) 2009-2011, ## Sony Pictures Imageworks Inc. and ## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. ## ## All rights reserved. ## ## Redistribution and use in source and binary forms, with ...
Python
#!/usr/bin/env python import time t = time.time() u = time.gmtime(t) s = time.strftime('%a, %e %b %Y %T GMT', u) print 'Content-Type: text/javascript' print 'Cache-Control: no-cache' print 'Date: ' + s print 'Expires: ' + s print '' print 'var timeskew = new Date().getTime() - ' + str(t*1000) + ';'
Python
#!/usr/bin/env python import codecs import re import jinja2 import markdown def process_slides(): with codecs.open('../../presentation-output.html', 'w', encoding='utf8') as outfile: md = codecs.open('slides.md', encoding='utf8').read() md_slides = md.split('\n---\n') print 'Compiled %s slides.' % len(m...
Python
# -*- mode: python -*- a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'z:/home/pankaj/programming/python/billiards/src/billiards/billiards.py'], pathex=['Z:\\mnt\\data\\Program Installers\\Programs\\Programming\\py\\py26win']) pyz = PYZ(a....
Python
#!/usr/bin/env python from distutils.core import setup setup(name='PyBilliards', version=open('VERSION').read().strip(), description='A simple 2D billiards game', long_description='''A simple 2D billiards game written in python using pygame''', classifiers=['Topic :: Games/Entertainment', ...
Python
# -*- coding: utf-8 -*- import logging import os import settings_default # TODO: replace platform specific paths class Settings(object): def __init__(self): self._settings = {} #self.add_from_file(os.path.join('settings_default.py')) self._settings.update(settings_default.settings) ...
Python
#! /usr/bin/env python # -*- coding: utf-8 -*- '''A simple 2D billiards game @authors: prashant agrawal, pankaj pandey (c) 2010 the authors ''' # changelog # pankaj : 17 March, 2010: fixed alignment of the cue with the ball # and made the target of the cue as the ball center instead of the mouse pos # auth...
Python
# -*- coding: utf-8 -*- import pygame, sys, os, random from pygame.locals import * import time from math import * from numpy import * from settings import logging if not pygame.font: print "Warning, fonts disabled!" if not pygame.mixer: print "Warning, sounds disabled!" RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0...
Python
# -*- coding: utf-8 -*- import logging import os import pygame from settings import settings class Theme(object): '''A class to implement themes in pybilliards All other objects using any data must request it from a theme ''' def __init__(self, setting=None, name=None, path=None): if setting ...
Python
# The default system settings import os __datadir = os.path.join(os.path.dirname(__file__),'data') if not os.path.exists(__datadir): import sys try: if sys.frozen == 1: # for executables built using pyinstaller try: __datadir = os.path.join(os.environ['_MEIPASS2...
Python
print 'Content-Type: text/plain' print '' print 'You probably want /tetris ...'
Python
import cgi import datetime import urllib import wsgiref.handlers import random import datetime from django.utils import simplejson from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class Score(db.Model): name=db.StringProperty() ...
Python
# If you're reading this, you're doing it wrong. from random import randint,shuffle print("Philip Daian's Vocab Review Program\nhttp://nerd.nu/, licensed under GPL.") reverse = raw_input("\nReverse or normal mode? ").lower() if "reverse" in reverse: print "Reverse mode. Definitions will show first." revers...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 21:54:45 CST 2009 def mainflow(): n = input() for i in range(n): if i > 0: raw_input() m = input() alist = [] for j in range(m): line = raw_input() a...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 21:54:45 CST 2009 def mainflow(): n = input() for i in range(n): if i > 0: raw_input() m = input() alist = [] for j in range(m): line = raw_input() a...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 24 06:14:08 PM CST 2009 def foo(a, b): a = int(''.join(reversed(str(a)))) b = int(''.join(reversed(str(b)))) return int(''.join(reversed(str(a+b)))) def test(): assert foo(24,1) == 34 assert foo(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 05:18:35 PM CST 2009 def Z(num): r = 0 while num > 0: num /= 5 r += num print r def mainflow(): n = input() for i in range(n): num = input() Z(num) mainflow(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 25 06:09:25 PM CST 2009 def foo(s): m = 1 ms = s for i in range(1, len(s)): s = s[1:] + s[0] #print 'ms=',ms, 's=', s if s < ms: ms = s m = i+1 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 21:54:45 CST 2009 def mainflow(): n = input() for i in range(n): if i > 0: raw_input() m = input() alist = [] for j in range(m): line = raw_input() a...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 22:43:40 CST 2009 from bisect import * import random def get_seeds(max): roots=(4,7) seeds=[] for i in range(1, max+1): for j in range(0, 2**i): n = j m = 0 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 19 10:21:12 AM CST 2009 import math def primes(m): pp = range(2, m+1) p = [] while pp[0] ** 2 <= m: p.append(pp[0]) pp = [e for e in pp if e % pp[0] != 0] p.extend(pp) return p ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 18 05:18:37 PM CST 2009 def fun(num): cnt = 0 for i in xrange(0, 4**num): a = [] s = i for j in xrange(0, num): a.append(s%4) s /= 4 if a.count(0) % 2 =...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 19 10:21:12 AM CST 2009 import math def primes(m): pp = range(2, m+1) p = [] while pp[0] ** 2 <= m: p.append(pp[0]) pp = [e for e in pp if e % pp[0] != 0] p.extend(pp) return p ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 22:43:40 CST 2009 from bisect import * import random def get_seeds(max): roots=(4,7) seeds=[] for i in range(1, max+1): for j in range(0, 2**i): n = j m = 0 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 18 05:18:37 PM CST 2009 def fun(num): cnt = 0 for i in xrange(0, 4**num): a = [] s = i for j in xrange(0, num): a.append(s%4) s /= 4 if a.count(0) % 2 =...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 24 06:14:08 PM CST 2009 def foo(a, b): a = int(''.join(reversed(str(a)))) b = int(''.join(reversed(str(b)))) return int(''.join(reversed(str(a+b)))) def test(): assert foo(24,1) == 34 assert foo(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 25 06:09:25 PM CST 2009 def foo(s): m = 1 ms = s for i in range(1, len(s)): s = s[1:] + s[0] #print 'ms=',ms, 's=', s if s < ms: ms = s m = i+1 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 05:18:35 PM CST 2009 def Z(num): r = 0 while num > 0: num /= 5 r += num print r def mainflow(): n = input() for i in range(n): num = input() Z(num) mainflow(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 24 06:14:08 PM CST 2009 def foo(a, b): a = int(''.join(reversed(str(a)))) b = int(''.join(reversed(str(b)))) return int(''.join(reversed(str(a+b)))) def test(): assert foo(24,1) == 34 assert foo(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 05:18:35 PM CST 2009 def Z(num): r = 0 while num > 0: num /= 5 r += num print r def mainflow(): n = input() for i in range(n): num = input() Z(num) mainflow(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 25 06:09:25 PM CST 2009 def foo(s): m = 1 ms = s for i in range(1, len(s)): s = s[1:] + s[0] #print 'ms=',ms, 's=', s if s < ms: ms = s m = i+1 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 21:54:45 CST 2009 def mainflow(): n = input() for i in range(n): if i > 0: raw_input() m = input() alist = [] for j in range(m): line = raw_input() a...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 22:43:40 CST 2009 from bisect import * import random def get_seeds(max): roots=(4,7) seeds=[] for i in range(1, max+1): for j in range(0, 2**i): n = j m = 0 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 19 10:21:12 AM CST 2009 import math def primes(m): pp = range(2, m+1) p = [] while pp[0] ** 2 <= m: p.append(pp[0]) pp = [e for e in pp if e % pp[0] != 0] p.extend(pp) return p ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 18 05:18:37 PM CST 2009 def fun(num): cnt = 0 for i in xrange(0, 4**num): a = [] s = i for j in xrange(0, num): a.append(s%4) s /= 4 if a.count(0) % 2 =...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 19 10:21:12 AM CST 2009 import math def primes(m): pp = range(2, m+1) p = [] while pp[0] ** 2 <= m: p.append(pp[0]) pp = [e for e in pp if e % pp[0] != 0] p.extend(pp) return p ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 22:43:40 CST 2009 from bisect import * import random def get_seeds(max): roots=(4,7) seeds=[] for i in range(1, max+1): for j in range(0, 2**i): n = j m = 0 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 18 05:18:37 PM CST 2009 def fun(num): cnt = 0 for i in xrange(0, 4**num): a = [] s = i for j in xrange(0, num): a.append(s%4) s /= 4 if a.count(0) % 2 =...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 24 06:14:08 PM CST 2009 def foo(a, b): a = int(''.join(reversed(str(a)))) b = int(''.join(reversed(str(b)))) return int(''.join(reversed(str(a+b)))) def test(): assert foo(24,1) == 34 assert foo(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 25 06:09:25 PM CST 2009 def foo(s): m = 1 ms = s for i in range(1, len(s)): s = s[1:] + s[0] #print 'ms=',ms, 's=', s if s < ms: ms = s m = i+1 ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 20 05:18:35 PM CST 2009 def Z(num): r = 0 while num > 0: num /= 5 r += num print r def mainflow(): n = input() for i in range(n): num = input() Z(num) mainflow(...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 30 08:25:22 CST 2008 import sys, Ice, traceback, time sys.path.append('ice') import fk class WorkerI(fk.Worker): def work(self, cmd, data, current=None): #sys.stdout=sys.stderr print 'cmd=%s time...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 30 06:45:14 CST 2008 import sys, Ice, traceback, time sys.path.append('ice') import fk def init_ic(str): try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy(str) obj = fk.WorkerPrx...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 30 08:25:22 CST 2008 import sys, Ice, traceback, time sys.path.append('ice') import fk class WorkerI(fk.Worker): def work(self, cmd, data, current=None): #sys.stdout=sys.stderr print 'cmd=%s time...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 30 06:45:14 CST 2008 import sys, Ice, traceback, time sys.path.append('ice') import fk def init_ic(str): try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy(str) obj = fk.WorkerPrx...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 26 06:33:24 CST 2008 import sys, struct def test_struct(): print '-'*48, '\nFunc:', sys._getframe().f_code.co_name fmt = 'hhl' s=struct.pack(fmt,1,2,3) print struct.unpack('il', s) buf = 'abcdef'...
Python
#!/usr/bin/env python # @author FAN Kai, Peking University # @date Dec 13 18:59:18 CST 2008 import HTMLParser, htmllib, formatter, re hstr = ' '.join(open('data/any.html').read().split()) class MyHTMLParser(HTMLParser.HTMLParser): def __init__(self): HTMLParser.HTMLParser.__init__(self) s...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 21 05:19:15 CST 2011 import optparse, sys parser = optparse.OptionParser(usage="%prog [options] [args]") parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='make lots of noi...
Python
#!/usr/bin/env python import Tkinter top = Tkinter.Tk() label = Tkinter.Label(top, text='Hello World!') label.pack() Tkinter.mainloop()
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 08 19:31:50 CST 2009 import sys, os def test_dbhash(): print '-'*48, '\nFunc:', sys._getframe().f_code.co_name import dbhash, whichdb fdb='dbhash.tmp' db = dbhash.open(fdb, 'c') for i in range(9)...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 28 03:22:43 PM CST 2008 import ftplib ftp = ftplib.FTP('127.0.0.1') ftp.login() #ftp.login('ftp') #ftp.login('fankai') print ftp.retrlines('LIST') ftp.retrbinary('RETR CHANGES.txt', open('txt', 'wb').write) #print ft...
Python
#!/usr/bin/env python import sys g = 9 def ff(): """function ff. Test basic function The first function""" a = 1 print 'file:', sys._getframe().f_code.co_filename print 'func:', sys._getframe().f_code.co_name print 'stacksize:', sys._getframe().f_code.co_stacksize print 'const...
Python
#!/usr/bin/env python import time, os, timeit try: f = open("data/test.txt", "rb") except IOError: print "data/test.txt not exist." else: print f.name print f.readlines() print f.tell() f.seek(0, 0); print f.read(4) print f.read() finally: f.close() ts = time.clock() f = o...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 28 18:29:49 CST 2008 import timeit, sys def f0(): pass def f1(a): pass def f2(*a): pass def time_random(): print timeit.Timer('random.random()', 'import random').timeit() print timeit.Timer('r...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 26 06:35:16 CST 2008 import sys, readline, atexit, os def save_history(histfile): readline.write_history_file(histfile) class MyCompleter: def __init__(self): self.words = "perl", "pyjamas", "python...
Python
#!/usr/bin/env python import sys, getopt, random from socket import * PORT = 12345 def udp_server(): s = socket(AF_INET, SOCK_DGRAM) s.bind(('', PORT)) while True: print 'Received "%s" from %s.' % s.recvfrom(1024) s.close() def udp_client(str): s = socket(AF_INET, SOCK_DGRAM) HOST...
Python
#!/usr/bin/env python print "Hello, world!" import sys, os import glob print '***Test Sys Module***' print "path =", sys.path print "platform =", sys.platform print "maxint =", sys.maxint print "version =", sys.version print '***Test OS Module***' if (sys.platform == "win"): print os.getpid() print os.getcwd(...
Python
#!/usr/bin/env python # @author FAN Kai, Peking University # @date Dec 23 04:14:34 PM CST 2008 import threading, time, sys, os, random def disp(): print 'Current:', threading.currentThread() print 'pid = ', os.getpid() print 'ppid = ', os.getppid() print 'uid = ', os.getuid() print 'gid = ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@pku.edu.cn), Peking University # @date Dec 25 09:15:15 CST 2008 import sys, collections, heapq, array def test_dict(): print '-'*48, '\nFunc:', sys._getframe().f_code.co_name d = {"user":"fk", "key":"joke", 6:9.9} print d, d["user"], d["key"], d[6] ...
Python
#!/usr/bin/env python # @author FAN Kai, Peking University # @date Dec 16 21:18:52 CST 2008 import scipy.linalg from scipy import array, matrix import time, random n = 4 a = array([random.randint(0, n*n) for e in range(n*n)]) a.resize(n,n) m = matrix(a) #print a*a #print time.clock() im = scipy.linalg.inv(m) a...
Python
#!/usr/bin/env python # @author FAN Kai, Peking University # @date Dec 12 19:55:18 CST 2008 # Test data persistance import shelve,pickle, os import zlib, gzip, zipfile, tarfile import ConfigParser, time import csv, sys, random, timeit file1 = 'test_pickle.dat' file2 = 'test_shelve.dat' file3 = 'test_dbm.dat' ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@pku.edu.cn), Peking University # @date Dec 25 08:49:51 CST 2008 import datetime dd = datetime.timedelta(1,1,1) de = datetime.timedelta(0,6,9) print dd.min print dd.max print dd.resolution print dd+de print td = datetime.date.today() print td print td.min print ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 26 06:32:09 CST 2008 import sys, os, time def test_fork(): print '-'*48, '\nFunc:', sys._getframe().f_code.co_name pid = os.fork() if pid == 0: print 'child', os.getpid() for i in xrange...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 03 07:14:53 CST 2009 import cgi, cgitb, Cookie, os cgitb.enable() if os.environ.has_key('HTTP_COOKIE'): cstr = os.environ['HTTP_COOKIE'] else: cstr = '' cookie = Cookie.SimpleCookie(cstr) if 'count' in cook...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 29 09:31:11 PM CST 2008 from numpy import * a = array(xrange(1,9), int) b = a.astype('float') print a.shape print a.dtype print a+a print a*a print a/a print a/3 print b/3 c = arange(6, dtype='float') print c d = c *...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Dec 27 17:48:52 CST 2008 from pylab import * subplot(221) plot([0.5,1,2,3], [0.25,1,4,9]) t = arange(0,5,.2) plot(t,t,'r--',t,t**2,'bs') axis([0,4,0,20]) subplot(222) plot([4,5,6]) subplot(223) t = arange(0,3,.1) plot...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Apr 24 14:59:56 CST 2009 import random def average_sim(sim, item, group): if not group: return 1 return sum([sim[item][x] for x in group])/float(len(group)) def kmeans(sim, group_count): num = len(sim) ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date May 23 05:29:50 PM CST 2009 import networkx as nx def draw(g): import matplotlib.pyplot as plt #nx.draw(g) #nx.draw_random(g) nx.draw_circular(g) #nx.draw_spectral(g) plt.show() def gen(): p...
Python
#!/usr/bin/env python import sys, os sys.stdout=sys.stderr def lcs(a, b): print '-'*48, '\nFunc:', sys._getframe().f_code.co_name nr = len(a) + 1 nc = len(b) + 1 c = [[0]*nc for i in range(nr)] s = [['*']*nc for i in range(nr)] for i in range(1, nr): for j in range(1, nc): ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Apr 22 21:07:32 CST 2009 import re, sys def html2text(page): page = re.sub('<script[^<]*</script>', '', page) page_text = re.sub('<[^>]*>|&[^;]*;', '', page) return page_text
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 05 19:40:49 CST 2009 import math def entropy(d): e = 0 for p in d: e -= p*math.log(p, 2) return e print entropy([0.5, 0.5]) print entropy([0.2, 0.8]) print entropy([0.25,0.25, 0.25, 0.25]) print...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Oct 01 17:50:09 CST 2010 cnta = 4 cntb = 5 edges = [[0, 0], [0,1], [1,0]] lines = [0, 0] def find_edge(point, ex): for edge in edges: if edge[0] == point and edge[1] not in includedb: return ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 16 04:02:42 PM CST 2009 import os, time, cPickle class fdb: def __init__(self, path): if os.path.exists(path): f = open(path, 'rb+') pos = int(f.read(8), 16) f.seek(po...
Python
from numpy import matrix from scipy import * A=matrix([[1,0,1,0,0,0],[0,1,0,0,0,0],[1,1,0,0,0,0],[1,0,0,1,1,0],[0,0,0,1,0,1]]) # svd T,s,D=linalg.svd(A) #print T #print D #print 'SIGMA :',s # simplify svd TS=T[0:,0:2] DS=D[0:2] ss=matrix([[0.0,0],[0,0]]) ss[0,0]=s[0] ss[1,1]=s[1] print 'new SIGMA Matrix :' print ss pr...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 10:57:30 AM CST 2009 import random, sys def graph(n, m=0): h = [[m]*(i+1)+[random.randint(1,99) for j in range(i+1, n)] for i in range(n)] g = [[h[j][i]-m for j in range(i)]+[h[i][j]-m for j in range(i, n...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 09:38:47 AM CST 2009 v = range(5) e = [(0,1), (0,2), (0, 3), (0, 4), (1,3), (2, 3), (2, 4), (3, 4)] size = 5 max = 0 maxr = [0]*5 def check(r, index): global max, maxr print 'check', index, r for i i...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 05 17:08:28 CST 2009 import random, sys sys.stdout=sys.stderr size=18 dim=3 k=3 pts=[[random.randint(-9,9) for i in range(dim)] for j in range(size)] print pts s = [None]*3 for i in range(k): s[i] = [p for p i...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 09:38:47 AM CST 2009 v = range(5) e = [(0,1), (0,2), (0, 3), (0, 4), (1,3), (2, 3), (2, 4), (3, 4)] size = 5 max = 0 maxr = [0]*5 def check(r, index): global max, maxr print 'check', index, r for i i...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 05 20:27:18 CST 2009 import random def random_shuffle(a): size = len(a) for i in range(size-1): t = a[i] s = random.randint(i+1, size-1) a[i] = a[s] a[s] = t def jc(a, b): ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 10:41:19 AM CST 2009 import random def NF(objs): cnt = 1 blank = 1 for w in objs: if w < blank: blank -= w else: cnt += 1 blank = 1 - w print ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 10:57:30 AM CST 2009 import random, sys def graph(n, m=0): h = [[m]*(i+1)+[random.randint(1,99) for j in range(i+1, n)] for i in range(n)] g = [[h[j][i]-m for j in range(i)]+[h[i][j]-m for j in range(i, n...
Python
b=r''' a="b=r"+"'"*3+b+"'"*3 print a+b open('tmp', 'w').write(a+b) ''' a="b=r"+"'"*3+b+"'"*3 print a+b open('tmp', 'w').write(a+b)
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 05 17:08:28 CST 2009 import random, sys sys.stdout=sys.stderr size=18 dim=3 k=3 pts=[[random.randint(-9,9) for i in range(dim)] for j in range(size)] print pts s = [None]*3 for i in range(k): s[i] = [p for p i...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 04 10:41:19 AM CST 2009 import random def NF(objs): cnt = 1 blank = 1 for w in objs: if w < blank: blank -= w else: cnt += 1 blank = 1 - w print ...
Python
#!/usr/bin/env python # @author FAN Kai (fankai@net.pku.edu.cn), Peking University # @date Jan 05 20:27:18 CST 2009 import random def random_shuffle(a): size = len(a) for i in range(size-1): t = a[i] s = random.randint(i+1, size-1) a[i] = a[s] a[s] = t def jc(a, b): ...
Python