Skip to content

Instantly share code, notes, and snippets.

View fmasanori's full-sized avatar

Fernando Masanori fmasanori

View GitHub Profile
@fmasanori
fmasanori / hello_world.tpl
Last active December 19, 2015 07:59
tutorial bottle 02 template
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p>
Welcome {{username}}
<p>
<ul>
@fmasanori
fmasanori / tutorial bottle 03.py
Created July 3, 2013 21:26
tutorial bottle 03
import bottle
@bottle.route('/')
def home_page():
mythings = ['apple', 'orange', 'banana', 'peach']
return bottle.template('hello_world2', {'username':'Masanori',
'things':mythings})
@bottle.post('/favorite_fruit')
def favorite_fruit():
fruit = bottle.request.forms.get('fruit')
@fmasanori
fmasanori / hello_world2.tpl
Created July 3, 2013 21:28
tutorial bottle 03 template hello world2
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p>
Welcome {{username}}
<p>
<ul>
@fmasanori
fmasanori / fruit_selection.tpl
Created July 3, 2013 21:29
tutorial bottle 03 template fruit_selection
<!DOCTYPE html>
<html>
<head>
<title>Fruit Selection Confirmation</title>
</head>
<body>
<p>
Your favorite fruit is {{fruit}}
</body>
</html>
@fmasanori
fmasanori / tutorial bottle 04.py
Last active February 24, 2016 22:37
tutorial bottle 04
import bottle
@bottle.route('/')
def home_page():
mythings = ['apple', 'orange', 'banana', 'peach']
return bottle.template('hello_world2', {'username':'Masanori',
'things':mythings})
@bottle.post('/favorite_fruit')
def favorite_fruit():
fruit = bottle.request.forms.get('fruit')
@fmasanori
fmasanori / create_student_collection.js
Created July 3, 2013 21:34
create student collection
use school
var types = ['exam', 'homework', 'quiz']
for (student_id = 0; student_id < 100; student_id++) {
for (type=0; type < 3; type++) {
var r = {'student_id':student_id,
'type':types[type],
'score':Math.random() * 100};
db.scores.insert(r)
}
@fmasanori
fmasanori / query mongo.py
Last active March 5, 2018 12:33
query mongo
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
scores = db.scores
def find():
query = {'type': 'exam'}
@fmasanori
fmasanori / query2 mongo.py
Last active March 5, 2018 12:39
query2 mongo
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
scores = db.scores
def find():
query = {'type': 'exam'}
selector = {'student_id': 1, '_id': 0}
@fmasanori
fmasanori / query3 mongo.py
Last active December 19, 2015 08:08
query3 mongo.py
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
scores = db.scores
def find():
query = {'type': 'exam', 'score':{'$gt':50, '$lt':70}}
selector = {'student_id': 1, 'score':1, '_id': 0}
@fmasanori
fmasanori / reddit insert mongo.py
Last active March 6, 2018 23:06
reddit insert mongo
import json
from urllib.request import urlopen
import pymongo
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.reddit
stories = db.stories
reddit_page = urlopen('http://www.reddit.com/r/Python/.json')