This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/binary" | |
"flag" | |
"fmt" | |
"log" | |
"net" | |
"sync" | |
"time" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from sqlalchemy import create_engine, Column, Integer, Index, event | |
from sqlalchemy.ext.declarative import declarative_base, declared_attr | |
engine = create_engine('postgresql://slava:slavapw@localhost:5432/test', echo=True) | |
Base = declarative_base() | |
class BaseModel(Base): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
app = Flask(__name__) | |
@app.route('/') | |
def hello_world(): | |
return render_template('test.txt') | |
if __name__ == '__main__': | |
app.jinja_env.add_extension('jinja2.ext.do') | |
app.run(debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine, Column, Integer, MetaData, Table, String | |
from sqlalchemy.sql import select, Select, ColumnCollection | |
engine = create_engine('sqlite:///:memory:', echo=True) | |
metadata = MetaData() | |
class RearrangeSelect(Select): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
from pyramid.config import Configurator | |
from pyramid.events import NewRequest | |
from pyramid.events import subscriber | |
from pyramid.events import ApplicationCreated | |
from pyramid.httpexceptions import HTTPFound | |
from pyramid.session import UnencryptedCookieSessionFactoryConfig | |
from pyramid.authentication import AuthTktAuthenticationPolicy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Realworldish Benchmark: | |
jinja 0.0009 seconds | |
mako 0.0008 seconds | |
django 0.0067 seconds | |
genshi 0.0144 seconds | |
(venv)slava@slava-air ~/src/jinja2/examples/rwbench $ python rwbench.py | |
Realworldish Benchmark: | |
jinja 0.0013 seconds | |
mako 0.0012 seconds | |
django 0.0066 seconds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import six | |
from six.moves import zip | |
import struct | |
uint = lambda x: x & 0xffffffff | |
uhex = lambda x: hex(x & 0xffffffff) | |
str_to_int = lambda x: struct.unpack("<i", x)[0] | |
int_to_str = lambda x: struct.pack("<i", sign_int(x)) | |
sign_int = lambda x: x if x < 0x7FFFFFFF else x - 0x100000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template_string | |
MAIN_TEMPLATE = """ \ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{{ message }}</title> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template_string | |
MAIN_TEMPLATE = """ \ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>{{ message }}</title> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
from werkzeug.exceptions import RequestEntityTooLarge | |
app = Flask(__name__) | |
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 # 4 Kb limit | |
app.config['DEBUG'] = True | |
@app.route("/", methods=["GET", "POST"]) | |
def hello(): | |
try: |