code
stringlengths
1
1.72M
language
stringclasses
1 value
""" Setup your Routes options here """ import os from routes import Mapper def make_map(global_conf={}, app_conf={}): root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) map = Mapper(directory=os.path.join(root_path, 'controllers')) # This route handles displaying the error page a...
Python
#
Python
from paste import httpexceptions from paste.cascade import Cascade from paste.urlparser import StaticURLParser from paste.registry import RegistryManager from paste.deploy.config import ConfigMiddleware, CONFIG from paste.deploy.converters import asbool from pylons.error import error_template from pylons.middleware im...
Python
import os import pylons.config import webhelpers from forlater.config.routing import make_map def load_environment(global_conf={}, app_conf={}): map = make_map(global_conf, app_conf) # Setup our paths root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = {'root_path': root_p...
Python
""" Helper functions All names available in this module will be available under the Pylons h object. """ from webhelpers import * from pylons.helpers import log from pylons.i18n import get_lang, set_lang
Python
from pylons import Response, c, g, cache, request, session from pylons.controllers import WSGIController from pylons.decorators import jsonify, validate from pylons.templating import render, render_response from pylons.helpers import abort, redirect_to, etag_cache from pylons.i18n import N_, _, ungettext import forlate...
Python
header_txt = """\ <html> <head> <title>4l8r%(title)s</title> <script src="/js/prototype.js" type="text/javascript"></script> <script src="/js/scriptaculous.js" type="text/javascript"></script> <style> a:link {color: #990000} a:visited {color: #990000} a:hover {color: #CC6666} a:active {color: #CC6666} h1 { font-famil...
Python
from xml.dom.minidom import * class Entry: def __init__(self, id=0, questions=[]): self.id = id self.questions = questions[:] def _to_xml(self, d): e = d.createElement('entry') e.setAttribute('id', str(self.id)) for q in self.questions: e.appendChild(q._to_xm...
Python
import re class Globals(object): def __init__(self, global_conf, app_conf, **extra): """ Globals acts as a container for objects available throughout the life of the application. One instance of Globals is created by Pylons during application initialization and is availabl...
Python
#!python """Bootstrap setuptools installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from ez_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools...
Python
#!python """Bootstrap setuptools installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from ez_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools...
Python
from ez_setup import use_setuptools use_setuptools() from setuptools import setup, find_packages setup( name='Forlater', version="0.8.5", #description="", #author="", #author_email="", #url="", install_requires=["Pylons>=0.9.5"], packages=find_packages(), package_data={ 'for...
Python
#!/usr/bin/python # Load the WSGI application from the config file from paste.deploy import loadapp wsgi_app = loadapp('config:/usr/lib/cgi-bin/4l8r/production.ini') # Deploy it using FastCGI if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(wsgi_app).run()
Python
#!/usr/bin/python # Load the WSGI application from the config file from paste.deploy import loadapp wsgi_app = loadapp('config:/usr/lib/cgi-bin/4l8r/production.ini') import os, sys def run_with_cgi(application): environ = dict(os.environ.items()) environ['wsgi.input'] = sys.stdin environ['wsgi.errors...
Python
#!/usr/bin/python # Load the WSGI application from the config file from paste.deploy import loadapp wsgi_app = loadapp('config:/usr/lib/cgi-bin/4l8r/production.ini') # Deploy it using FastCGI if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(wsgi_app).run()
Python
#!/usr/bin/python # Load the WSGI application from the config file from paste.deploy import loadapp wsgi_app = loadapp('config:/usr/lib/cgi-bin/4l8r/production.ini') import os, sys def run_with_cgi(application): environ = dict(os.environ.items()) environ['wsgi.input'] = sys.stdin environ['wsgi.errors...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: plot.py # $Date: Thu Mar 13 20:23:07 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> import pyximport pyximport.install() import datafilter from sample_and_record import get_db_conn import matplotlib.pyplot as plt from matplotlib import dates import sys imp...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: daemon.py # $Date: Mon Mar 03 09:35:26 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> from sample_and_record import insert_db_entry import time MIN_UPTIME = 120 SAMPLE_DELTA = 300 def get_uptime(): with open('/proc/uptime') as fin: return map(f...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: dataproc.py # $Date: Tue Mar 11 00:25:03 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> import math class LinearFunction(object): k = None b = None def __init__(self, x0, y0, x1, y1): self.k = (y1 - y0) / (x1 - x0) self.b = y0 - ...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: sample_and_record.py # $Date: Wed Mar 12 23:03:06 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> from gevent import monkey monkey.patch_all() import gevent import re import json import urllib2 import subprocess import os import os.path import sqlite3 import ...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: update_db.py # $Date: Tue Mar 11 00:07:07 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> import sys sys.path.append('..') from sample_and_record import get_db_conn, init_db from dataproc import aqi2concentration, lowratio2concentration def update_db(): ...
Python
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # $File: datafilter.pyx # $Date: Thu Mar 13 19:08:46 2014 +0800 # $Author: jiakai <jia.kai66@gmail.com> cimport cython from libc.stdlib cimport malloc, free from libc.math cimport exp cdef: int FILTER_SIGMA = 1800 int FILTER_RADIUS = 3 * FILTER_SIGMA double F...
Python
# -*- coding: utf-8 -*- from __future__ import with_statement # This isn't required in Python 2.6 __metaclass__ = type from contextlib import closing, contextmanager import os, sys, traceback import os.path from mod_python import apache, util from util import parse_qs today = date.today ver = sys.version_inf...
Python
# # jQuery File Tree # Python/Django connector script # By Martin Skou # import os import urllib def dirlist(request): r=['<ul class="jqueryFileTree" style="display: none;">'] try: r=['<ul class="jqueryFileTree" style="display: none;">'] d=urllib.unquote(request.POST.get('dir','c:\\temp...
Python
from sys import stdin x, = map(float, stdin.readline().strip().split()) print abs(x)
Python
from sys import stdin a, b = map(int, stdin.readline().strip().split()) print b, a
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print n*(n+1)/2
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) print "%.3lf" % ((a+b+c)/3.0)
Python
from sys import stdin n = stdin.readline().strip().split()[0] print '%c%c%c' % (n[2], n[1], n[0])
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) money = n * 95 if money >= 300: money *= 0.85 print "%.2lf" % money
Python
from sys import stdin from math import * x1, y1, x2, y2 = map(float, stdin.readline().strip().split()) print "%.3lf" % hypot((x1-x2), (y1-y2))
Python
from sys import stdin f, = map(float, stdin.readline().strip().split()) print "%.3lf" % (5*(f-32)/9)
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) a = (4*n-m)/2 b = n-a if m % 2 == 1 or a < 0 or b < 0: print "No answer" else: print a, b
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a: print "yes" elif a + b <= c or a + c <= b or b + c <= a: print "not a triangle" else: print "no"
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print ["yes", "no"][n % 2]
Python
from sys import stdin from math import * n, = map(int, stdin.readline().strip().split()) rad = radians(n) print "%.3lf %.3lf" % (sin(rad), cos(rad))
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) a.sort() print a[0], a[1], a[2]
Python
from sys import stdin from math import * r, h = map(float, stdin.readline().strip().split()) print "Area = %.3lf" % (pi*r*r*2 + 2*pi*r*h)
Python
from sys import stdin from calendar import isleap year, = map(int, stdin.readline().strip().split()) if isleap(year): print "yes" else: print "no"
Python
s = i = 0 while True: term = 1.0 / (i*2+1) s += term * ((-1)**i) if term < 1e-6: break i += 1 print "%.6lf" % s
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) print "%.5lf" % sum([1.0/i/i for i in range(n,m+1)])
Python
from sys import stdin from decimal import * a, b, c = map(int, stdin.readline().strip().split()) getcontext().prec = c print Decimal(a) / Decimal(b)
Python
from itertools import product from math import * def issqrt(n): s = int(floor(sqrt(n))) return s*s == n aabb = [a*1100+b*11 for a,b in product(range(1,10),range(10))] print ' '.join(map(str, filter(issqrt, aabb)))
Python
from sys import stdin from math import * n = int(stdin.readline().strip()) print sum(map(factorial, range(1,n+1))) % (10**6)
Python
from sys import stdin def cycle(n): if n == 1: return 0 elif n % 2 == 1: return cycle(n*3+1) + 1 else: return cycle(n/2) + 1 n = int(stdin.readline().strip()) print cycle(n)
Python
for abc in range(123, 329): big = str(abc) + str(abc*2) + str(abc*3) if(''.join(sorted(big)) == '123456789'): print abc, abc*2, abc*3
Python
from sys import stdin print len(stdin.readline().strip())
Python
from sys import stdin def solve(a, b, c): for i in range(10, 101): if i % 3 == a and i % 5 == b and i % 7 == c: print i return print 'No answer' a, b, c = map(int, stdin.readline().strip().split()) solve(a, b, c)
Python
from sys import stdin data = map(int, stdin.readline().strip().split()) n, m = data[0], data[-1] data = data[1:-1] print len(filter(lambda x: x < m, data))
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) print "%d %d %.3lf" % (min(a), max(a), float(sum(a)) / len(a))
Python
from sys import stdin n = int(stdin.readline().strip()) print "%.3lf" % sum([1.0/x for x in range(1,n+1)])
Python
from itertools import product sol = [a*100+b*10+c for a,b,c in product(range(1,10), range(10), range(10)) if a**3+b**3+c**3 == a*100+b*10+c] print '\n'.join(map(str, sol))
Python
from sys import stdin n = int(stdin.readline().strip()) count = n*2-1 for i in range(n): print ' '*i + '#'*count count -= 2
Python
#! /usr/bin/env python # coding=utf-8 ############################################################################# # # # File: common.py # # ...
Python
#! /usr/bin/env python # coding=utf-8 ############################################################################# # # # File: proxy.py # # ...
Python
#!/usr/bin/env python import sys, os # do the UNIX double-fork magic, see Stevens' "Advanced # Programming in the UNIX Environment" for details (ISBN 0201563177) try: pid = os.fork() if pid > 0: # exit first parent sys.exit(0) except OSError, e: print >>sys.stderr, "fo...
Python
#!/usr/bin/env python # coding:utf-8 # Based on GAppProxy 2.0.0 by Du XiaoGang <dugang@188.com> # Based on WallProxy 0.4.0 by hexieshe <www.ehust@gmail.com> from __future__ import with_statement __version__ = '1.8.11' __author__ = "{phus.lu,hewigovens}@gmail.com (Phus Lu and Hewig Xu)" __config__ = 'proxy.ini' try...
Python
#!/usr/bin/env python # # Copyright 2007 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law o...
Python
#!/usr/bin/env python # # Copyright 2007 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law o...
Python
#import sys,os def main: return if __name__ == '__main__': main()
Python
import xmlrpclib from SimpleXMLRPCServer import SimpleXMLRPCServer def debug(message): print "[Debug] " + message return "OK" def info(message): print "[Infor] " + message server = SimpleXMLRPCServer(("localhost",8888)) print "Listening on port 8888" server.register_function(debug,"debug") server.serve_for...
Python
import os import sys sys.path.append('/var/www/python/application') os.environ['PYTHON_EGG_CACHE'] = '/var/www/python/application/.python-egg' def application(environ, start_response): status = '200 OK' output = 'path /var/www/python/application' response_headers = [('Content-type', 'text/plain'), ...
Python
s = i = 0 while True: term = 1.0 / (i*2+1) s += term * ((-1)**i) if term < 1e-6: break i += 1 print "%.6lf" % s
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) print "%d %d %.3lf" % (min(a), max(a), float(sum(a)) / len(a))
Python
from sys import stdin from math import * n = int(stdin.readline().strip()) print sum(map(factorial, range(1,n+1))) % (10**6)
Python
from sys import stdin def solve(a, b, c): for i in range(10, 101): if i % 3 == a and i % 5 == b and i % 7 == c: print i return print 'No answer' a, b, c = map(int, stdin.readline().strip().split()) solve(a, b, c)
Python
from itertools import product sol = [a*100+b*10+c for a,b,c in product(range(1,10), range(10), range(10)) if a**3+b**3+c**3 == a*100+b*10+c] print '\n'.join(map(str, sol))
Python
from sys import stdin n = int(stdin.readline().strip()) count = n*2-1 for i in range(n): print ' '*i + '#'*count count -= 2
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) print "%.5lf" % sum([1.0/i/i for i in range(n,m+1)])
Python
from sys import stdin print len(stdin.readline().strip())
Python
from sys import stdin from decimal import * a, b, c = map(int, stdin.readline().strip().split()) getcontext().prec = c print Decimal(a) / Decimal(b)
Python
from itertools import product from math import * def issqrt(n): s = int(floor(sqrt(n))) return s*s == n aabb = [a*1100+b*11 for a,b in product(range(1,10),range(10))] print ' '.join(map(str, filter(issqrt, aabb)))
Python
from sys import stdin data = map(int, stdin.readline().strip().split()) n, m = data[0], data[-1] data = data[1:-1] print len(filter(lambda x: x < m, data))
Python
for abc in range(123, 329): big = str(abc) + str(abc*2) + str(abc*3) if(''.join(sorted(big)) == '123456789'): print abc, abc*2, abc*3
Python
from sys import stdin n = int(stdin.readline().strip()) print "%.3lf" % sum([1.0/x for x in range(1,n+1)])
Python
from sys import stdin def cycle(n): if n == 1: return 0 elif n % 2 == 1: return cycle(n*3+1) + 1 else: return cycle(n/2) + 1 n = int(stdin.readline().strip()) print cycle(n)
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) money = n * 95 if money >= 300: money *= 0.85 print "%.2lf" % money
Python
from sys import stdin from math import * x1, y1, x2, y2 = map(float, stdin.readline().strip().split()) print "%.3lf" % hypot((x1-x2), (y1-y2))
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print ["yes", "no"][n % 2]
Python
from sys import stdin n, m = map(int, stdin.readline().strip().split()) a = (4*n-m)/2 b = n-a if m % 2 == 1 or a < 0 or b < 0: print "No answer" else: print a, b
Python
from sys import stdin from math import * n, = map(int, stdin.readline().strip().split()) rad = radians(n) print "%.3lf %.3lf" % (sin(rad), cos(rad))
Python
from sys import stdin from calendar import isleap year, = map(int, stdin.readline().strip().split()) if isleap(year): print "yes" else: print "no"
Python
from sys import stdin a, b = map(int, stdin.readline().strip().split()) print b, a
Python
from sys import stdin f, = map(float, stdin.readline().strip().split()) print "%.3lf" % (5*(f-32)/9)
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a: print "yes" elif a + b <= c or a + c <= b or b + c <= a: print "not a triangle" else: print "no"
Python
from sys import stdin a = map(int, stdin.readline().strip().split()) a.sort() print a[0], a[1], a[2]
Python
from sys import stdin n, = map(int, stdin.readline().strip().split()) print n*(n+1)/2
Python
from sys import stdin x, = map(float, stdin.readline().strip().split()) print abs(x)
Python
from sys import stdin a, b, c = map(int, stdin.readline().strip().split()) print "%.3lf" % ((a+b+c)/3.0)
Python
from sys import stdin from math import * r, h = map(float, stdin.readline().strip().split()) print "Area = %.3lf" % (pi*r*r*2 + 2*pi*r*h)
Python
from sys import stdin n = stdin.readline().strip().split()[0] print '%c%c%c' % (n[2], n[1], n[0])
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.ext import db from google.appengine.api import users class Categories(db.Expando): """ categories of different places data model """ name = db....
Python
print 'Content-Type: text/plain' print '' print 'Hello, world!'
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.ext import webapp import os # test print envs class PrintEnvironment(webapp.RequestHandler): def get(self): for name in os.environ.keys(): self.respons...
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # import cgi import datetime import logging from google.appengine.ext import db from google.appengine.api import users from google.appengine.ext import webapp from google.appengi...
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.ext import webapp from google.appengine.ext import db import os class Point(db.Expando): """ save a point with a comment """ lat = db.StringProperty(req...
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.ext import db from google.appengine.api import users class Categories(db.Expando): """ categories of different places data model """ name = db....
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.api import urlfetch from google.appengine.ext import webapp # test fetch url class Fetch(webapp.RequestHandler): def get(self): self.response.out.write(""" ...
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # import os import wsgiref.handlers #import cgi import datetime import logging from google.appengine.api import mail from google.appengine.api import memcache from google.appeng...
Python
#!/usr/bin/env python # vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent: # -*- coding: utf-8 -*- # from google.appengine.ext import webapp import os # test print envs class PrintEnvironment(webapp.RequestHandler): def get(self): for name in os.environ.keys(): self.respons...
Python