Skip to content

Instantly share code, notes, and snippets.

View xiantail's full-sized avatar

Ken M. Xu xiantail

  • Tokyo, JAPAN
View GitHub Profile
@xiantail
xiantail / books.csv
Last active December 25, 2015 00:25
Introducing Python / Exercise 8.4 - source cvs file (good example:books2.csv, bad example:books.csv)
author book
J R R Tolkien The Hobbit
Lynne Truss Eats, Shoots & Leaves
@xiantail
xiantail / bottle1.py
Created December 25, 2015 05:20
Introducing Python / Chapter 9
from bottle import route, run
@route('/')
def home():
return "It isn't fancy, but it's my home page"
run(host='localhost', port=9999)
@xiantail
xiantail / bottle2.py
Created December 25, 2015 05:35
Introducing Python / Chapter 9
from bottle import route, run, static_file
@route('/')
def main():
return static_file('index.html', root='.')
run(host='localhost', port=9999)
@xiantail
xiantail / bottle3.py
Created December 25, 2015 05:45
Introducing Python / Chapter 9
from bottle import route, run, static_file
@route('/')
def main():
return static_file('index.html', root='.')
@route('/echo/<thing>')
def echo(thing):
return "Say hello to my littel friend: %s" % thing
@xiantail
xiantail / bottle_text.py
Created December 25, 2015 05:59
Introducing Python / Chapter 9 Bottle
import requests
resp = requests.get('http://localhost:9999/echo/Mothra')
if resp.status_code == 200 and \
resp.text == 'Say hello to my little friend: Mothra':
print('It worked! That almost never happens!')
else:
print('Argh, got this:', resp.text)
@xiantail
xiantail / flask1.py
Created December 25, 2015 12:57
Introducing Python / Chapter 9 - Flask
from flask import Flask
app = Flask(__name__, static_folder='.', static_url_path='')
@app.route('/')
def home():
return app.send_static_file('index.html')
@app.route('/echo/<thing>')
def echo(thing):
@xiantail
xiantail / flask2.html
Created December 25, 2015 13:16
Introducing Python / Chapter 9 - Flask
<html>
<head>
<title>Flask2 Example</title>
</head>
<body>
Say hello to my little friend: {{ thing }}
</body>
</html>
@xiantail
xiantail / flask3.html
Created December 25, 2015 13:39
Introducing Python / Chapter 9 Flask
<html>
<head>
<title>Flask3 Example</title>
</head>
<body>
Say hello to my little friend: {{ thing }}.
Alas, in just destroyed {{ place }}!
</body>
</html>
@xiantail
xiantail / flask3b.py
Created December 25, 2015 13:49
Introducing Python / Chapter 9 - Flask
from flask import Flask, render_template, request
app = Flask(__name__, static_folder='.', static_url_path='')
@app.route('/')
def home():
return app.send_static_file('index.html')
@app.route('/echo/')
def echo():
@xiantail
xiantail / flask3c.py
Created December 25, 2015 13:57
Introducing Python / Chapter 9 - Flask
from flask import Flask, render_template, request
app = Flask(__name__, static_folder='.', static_url_path='')
@app.route('/')
def home():
return app.send_static_file('index.html')
@app.route('/echo/')
def echo():