SlideShare a Scribd company logo
1 of 49
Build a
Better
Python Web
APP
MongoDB
• Much fasterthan SQL databases
• No needto learnquery languages*and setups
• Easier toscale whendesignedproperly
Install pymongo
pip install pymongo
easy_install pymongo
Hello World
from pymongo import MongoClient
client = MongoClient("localhost", 27017)
db = client.databasename
Step
from pymongo import MongoClient
Import MongoClient from pymongo
client = MongoClient("localhost", 27017)
Connect to the mongodb server at the IP address and port defined
db = client.databasename
Access a specific database in the mongodb server
collection = db.collectionname
Access a specific collection (table in SQL) in the selected db
Basic DB Operations
•Create
•Read
•Update
•Delete
Create
@route("/user/list")
def listuser():
usercursor = db.users.find({},{"_id":False})
users = list(usercursor)
return {"users":users}
Step
usercursor = db.users.find({},{"_id":False})
Find allentries in the collection named users and do not show the _id field
users = list(usercursor)
Convert the cursor object into a list,which we can be converted to a jsonobject
return {"users":users}
Return the list of users to the browser
The Query Format
db.collectionname.find(filter,projection)
Filter is the expression that needs to be true an element to be included
Examples:
• {} = will return all
• {“name”:”paolo”} = will only return entries with name exactly to“paolo”
• {“name”:”paolo”, “age”:{“$lte”:30}} = will only return entries with names exactly “paolo” and age
is less thanor equal to 30
See more filter operators here: https://docs.mongodb.com/manual/reference/operator/query/
Read
Via query string
@route('/sum')
def sum():
total = 0
start = request.query.get("start")
end = request.query.get("end")
for i in range(start,end):
total += i
return "Sum of "+str(start) + " to " + str(end) + " = " +
str(total)
Visit: localhost:8001/sum?start=1&end=10
Inputs in Bottle
Via POST body
@route('/login', method="POST")
def login():
username = request.forms.get("username")
password = request.forms.get("password")
acceptedpasswords = ["gloopgroup", "devconph" ,
"adventuretime"]
if password in acceptedpasswords:
return "Welcome "+ username
else:
return "Unauthorized"
Visit: localhost:8001/login using login page
Activity 1
Create a calculatorapi:
http://localhost:8001/operation/operand1/operand2
will return the value of
operand1 <operation> operand2
Example:
/subtraction/10/2 will output 8
Common Return TYPES
PlainText
Similar to whatwe were doing earlier
Common Return TYPES
Binary
Whenreturning fileslike images, video, audio, pdfs…
Common Return TYPES
JSON
The common return type for APIs
Example:FB API
/{userid}/friends
{
"data": [
{
"name": "Terence Pua",
"id": "608407"
},
{
"name": "Gene Paul Quevedo",
"id": "10153785024974240"
},
{
"name": "Jc Velasquez",
"id": "722462218"
},
{
"name": "Jomel C. Imperio",
"id": "779287017"
}
],
"summary": {
"total_count": 770
}
}
Common Return TYPES
HTML
Returnweb pages with dynamic/static content
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/QAPage">
<head>
<title>regex - Validate email address in JavaScript? - Stack Overflow</title>
<link rel="shortcut icon" href="//cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d">
<link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a">
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
<meta name="twitter:card" content="summary">
<meta name="twitter:domain" content="stackoverflow.com"/>
<meta property="og:type" content="website" />
<meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/Sites/stackoverflow/img/apple-
touch-icon@2.png?v=73d79a89bded&a" />
<meta name="twitter:title" property="og:title" itemprop="title name" content="Validate email address in JavaScript?" />
<meta name="twitter:description" property="og:description" itemprop="description" content="How can an email address be validated
in JavaScript?" />
<meta property="og:url" content="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript"/>
<link rel="canonical" href="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript" />
Returning JSON Object
JSON
Simplyreturn a dictionary or list
@route("/json")
def jason():
return {"lastname":"bourne", "alias":"David Webb"}
Returning Static HTML
HTML
Use static_file from bottle
@route("/loginpage")
def loginpage():
return static_file("login.html", root=".")
Testing the POST Handler
Visit localhost:8081/loginpage
Type your nameand use any of theseas passwordg
gloopgroup, devconph, adventuretime
Click submit
The POST Request Cycle
<form action="/login" method="POST">
Method dictates what kind of request happens when submitted
Action tells the browser where to submit the request
<input type="text" name="username">
Adds a text input that will be associated to the username field
<input type="password" name="password">
Adds a password inputthat willbe associatedto the password field
<input type="submit">
Adds a button that submits the form whenclicked
Returning Dynamic HTML
HTML
Use a templatingengine:
• Library thatcan substitutevariables intoa templatequickly and cleanly
• Isolates thedesigner’s job of designing and thecoder’s job of coding
Install Tenjin
pip install tenjin
easy_install tenjin
Using Tenjin
from gevent import monkey;
monkey.patch_all()
from bottle import run, route, request
import tenjin
from tenjin.helpers import *
@route("/introduction/<name>/<age>/<work>")
def template1(name, age, work):
context = {"name":name, "age":age, "work":work}
return engine.render("introduction.html", context);
engine = tenjin.Engine(path=['.'])
run(server='gevent', host="localhost", port=8001, debug=True)
The template
<!doctype html>
<html lang="en">
<head>
<title>Login</title>
</head>
<body>
<h1>${name}</h1>
<h2>Age:${age}<h2>
<h2>Work:${work}<h2>
</body>
</html>
Step
from gevent import monkey;
monkey.patch_all()
from bottle import run, route, request
import tenjin
from tenjin.helpers import *
Import alllibraries, including tenjin and all helper methods
@route("/introduction/<name>/<age>/<work>")
Define a route for the url, and define variables in it
def template1(name, age, work):
Declare a request handler and receive the variables from the url
Step
context = {"name":name, "age":age, "work":work}
Define a context variable, which is a dictionary of values that will be substituted into the template
return engine.render("introduction.html", context);
Render the template called introduction.html using the context variable named context, and return it to
the browser
engine = tenjin.Engine(path=['.'])
Instructs the templating engine to look for the templates in the directories listed in path
Step (Inside the template)
<!doctype html>
<html lang="en">
<head>
<title>Login</title>
</head>
<body>
<h1>${name}</h1>
<h2>Age:${age}<h2>
<h2>Work:${work}<h2>
</body>
</html>
{
"name":"Paolo",
"age":"30",
"work":"Synergist"
}
+
Displaying Lists
@route("/spell/<word>")
def template1(word):
letters = list(word)
context = {"letters":letters, "word":word}
return engine.render("speller.html", context);
Step
@route("/spell/<word>")
Define a route that accepts a variable assigned to word
def speller(word):
Define a handler that accepts avariable named word
letters = list(word)
Convert the text string into a listobject. From a string “word”, it becomes a list [“w”, “o”, “r”, “d”]
Step
context = {"letters":letters}
Define a context variable, which contains the listof letters we just created
return engine.render("speller.html", context);
Render the template called speller.html using the context variable named context, and return it to the
browser
Step (Inside the template)
<?py for letter in letters: ?>
Loop on the elements of the list named letters
<h3>${letter}</h3><br>
Display the element letter along with the html
<?py #endfor ?>
Denote where the loop ends inthe template
<a href="/greet/${word}">greet ${word}</a>
Create a link that willcall the greet API we created earlier
{"letters":["s", "u", "s", "h", "i"]}
Highlighting Names
@route("/profiles/<name>")
def profile(name):
users = [
{"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30,
"work":"Futurist"},
{"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30,
"work":"Synergist"}
]
context = {"users":users, "name":name}
return engine.render("profiles.html", context)
Step
users = [
{"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"},
{"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"}
]
Define a list of dictionaries, with each dictionary objectcontaining information about a user. It contains information
name,url of the image, age, and work
context = {"users":users, "name":name}
Define a conext containing the name to behighlighted, and the list of users
return engine.render("profiles.html", context)
Render the template named profiles.html with the context
Step (Inside the template)
<?py for user in users: ?>
Loop on the elements of the list named users, each element in the listcan be referred to using the user
variable
<div style="height:100px;">
Create a div element in the html to contain one user element
<img src="${user['image']}" style="float:left;
height:100%;"/>
Place an image in the html coming from the url defined in user[‘image’]
Step (Inside the template)
<?py if name==user["name"]: ?>
Compare the current user’s name to the name entered in the url
<strong>Name: ${user['name']}</strong>
Thishappens when the above condition istrue, display the name asbold characters
<?py else: ?>
Add an else handler that executes if condition is not met
Step (Inside the template)
Name: ${user['name']}
This happens when primary condition is not met, display the user’s name without any decorations
<?py #endif ?>
Denote where the if statement ends
Make a Sushi Menu
Create a menu using allthe sushiitems in the sushilistvariable
Display the image and name of the sushi
When the menu item is clicked, it should display another page containingthe name, image, price, and
rating of the sushi(defined in the sushilistvariable)
The most creative presentation of the menu wins aprize
Activity 1
pip install gevent
pip install bottle
Cost per Mille =
• Cost per 1000 impressions
• Abuse of statistics
• i.e. Magic
• i.e. It sucks
• Not based on empirical measured data
ADVERTISING!
Eyeballs
cost
How many are watching
me right now?
How many are paying attention?
How many are interested?
How many are still reading this part?
How about now?
Now?
ROUTER ON
PROMISCUOUS MODE
DEVICEs SENDING
PROBE REQUESTS
PYTHON
+TCPDUMP
We get this
Pilot Installation
23000
Passers-by
39%
viewed
10%
Finished
Meh…
Map movement
Geofencing alternative
Detection
perimeter
snoop
turn off your phones
when going to the lagoon

More Related Content

What's hot

Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDMichele Capra
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworkingwaynehartman
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSencha
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networkingVitali Pekelis
 
Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Masha Edelen
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...Codemotion
 
Javascript call ObjC
Javascript call ObjCJavascript call ObjC
Javascript call ObjCLin Luxiang
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsMichele Capra
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Eric Palakovich Carr
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Naresha K
 
Power of Simplicity in FW/1
Power of Simplicity in FW/1Power of Simplicity in FW/1
Power of Simplicity in FW/1Masha Edelen
 
DevOps and Chef
DevOps and ChefDevOps and Chef
DevOps and ChefPiXeL16
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Adam Tomat
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 

What's hot (20)

Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDD
 
Url programming
Url programmingUrl programming
Url programming
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworking
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Javascript call ObjC
Javascript call ObjCJavascript call ObjC
Javascript call ObjC
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 Apps
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015
 
Power of Simplicity in FW/1
Power of Simplicity in FW/1Power of Simplicity in FW/1
Power of Simplicity in FW/1
 
DevOps and Chef
DevOps and ChefDevOps and Chef
DevOps and Chef
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 

Similar to Python Code Camp for Professionals 3/4

Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and PythonPiXeL16
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QAAlban Gérôme
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Startedguest1af57e
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsAlex Eftimie
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™Nicola Iarocci
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Neelkanth Sachdeva
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
 

Similar to Python Code Camp for Professionals 3/4 (20)

Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QA
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Nodejs.meetup
Nodejs.meetupNodejs.meetup
Nodejs.meetup
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshops
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 

More from DEVCON

Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...DEVCON
 
The A1 by Christian John Felix
The A1 by Christian John FelixThe A1 by Christian John Felix
The A1 by Christian John FelixDEVCON
 
Developing Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDeveloping Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDEVCON
 
Smart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenSmart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenDEVCON
 
Progressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoProgressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoDEVCON
 
How to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatHow to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatDEVCON
 
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoPayment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoDEVCON
 
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...DEVCON
 
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaSecuring Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaDEVCON
 
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweTalk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweDEVCON
 
Pokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinPokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinDEVCON
 
Docker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDocker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDEVCON
 
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoApplying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoDEVCON
 
Quick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasQuick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasDEVCON
 
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...DEVCON
 
Creating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenCreating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenDEVCON
 
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...DEVCON
 
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoRain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoDEVCON
 
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteFundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteDEVCON
 
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...DEVCON
 

More from DEVCON (20)

Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
 
The A1 by Christian John Felix
The A1 by Christian John FelixThe A1 by Christian John Felix
The A1 by Christian John Felix
 
Developing Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDeveloping Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ Realubit
 
Smart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenSmart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl Malangen
 
Progressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoProgressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent Convento
 
How to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatHow to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin Balabat
 
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoPayment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
 
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
 
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaSecuring Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
 
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweTalk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
 
Pokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinPokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo Balbin
 
Docker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDocker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin Arcilla
 
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoApplying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
 
Quick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasQuick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan Contreras
 
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
 
Creating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenCreating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl Malangen
 
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
 
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoRain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
 
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteFundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
 
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Python Code Camp for Professionals 3/4

  • 2. MongoDB • Much fasterthan SQL databases • No needto learnquery languages*and setups • Easier toscale whendesignedproperly
  • 3. Install pymongo pip install pymongo easy_install pymongo
  • 4. Hello World from pymongo import MongoClient client = MongoClient("localhost", 27017) db = client.databasename
  • 5. Step from pymongo import MongoClient Import MongoClient from pymongo client = MongoClient("localhost", 27017) Connect to the mongodb server at the IP address and port defined db = client.databasename Access a specific database in the mongodb server collection = db.collectionname Access a specific collection (table in SQL) in the selected db
  • 7. Create @route("/user/list") def listuser(): usercursor = db.users.find({},{"_id":False}) users = list(usercursor) return {"users":users}
  • 8. Step usercursor = db.users.find({},{"_id":False}) Find allentries in the collection named users and do not show the _id field users = list(usercursor) Convert the cursor object into a list,which we can be converted to a jsonobject return {"users":users} Return the list of users to the browser
  • 9. The Query Format db.collectionname.find(filter,projection) Filter is the expression that needs to be true an element to be included Examples: • {} = will return all • {“name”:”paolo”} = will only return entries with name exactly to“paolo” • {“name”:”paolo”, “age”:{“$lte”:30}} = will only return entries with names exactly “paolo” and age is less thanor equal to 30 See more filter operators here: https://docs.mongodb.com/manual/reference/operator/query/
  • 10. Read Via query string @route('/sum') def sum(): total = 0 start = request.query.get("start") end = request.query.get("end") for i in range(start,end): total += i return "Sum of "+str(start) + " to " + str(end) + " = " + str(total) Visit: localhost:8001/sum?start=1&end=10
  • 11. Inputs in Bottle Via POST body @route('/login', method="POST") def login(): username = request.forms.get("username") password = request.forms.get("password") acceptedpasswords = ["gloopgroup", "devconph" , "adventuretime"] if password in acceptedpasswords: return "Welcome "+ username else: return "Unauthorized" Visit: localhost:8001/login using login page
  • 12. Activity 1 Create a calculatorapi: http://localhost:8001/operation/operand1/operand2 will return the value of operand1 <operation> operand2 Example: /subtraction/10/2 will output 8
  • 13. Common Return TYPES PlainText Similar to whatwe were doing earlier
  • 14. Common Return TYPES Binary Whenreturning fileslike images, video, audio, pdfs…
  • 15. Common Return TYPES JSON The common return type for APIs Example:FB API /{userid}/friends { "data": [ { "name": "Terence Pua", "id": "608407" }, { "name": "Gene Paul Quevedo", "id": "10153785024974240" }, { "name": "Jc Velasquez", "id": "722462218" }, { "name": "Jomel C. Imperio", "id": "779287017" } ], "summary": { "total_count": 770 } }
  • 16. Common Return TYPES HTML Returnweb pages with dynamic/static content <!DOCTYPE html> <html itemscope itemtype="http://schema.org/QAPage"> <head> <title>regex - Validate email address in JavaScript? - Stack Overflow</title> <link rel="shortcut icon" href="//cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"> <link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> <meta name="twitter:card" content="summary"> <meta name="twitter:domain" content="stackoverflow.com"/> <meta property="og:type" content="website" /> <meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/Sites/stackoverflow/img/apple- touch-icon@2.png?v=73d79a89bded&a" /> <meta name="twitter:title" property="og:title" itemprop="title name" content="Validate email address in JavaScript?" /> <meta name="twitter:description" property="og:description" itemprop="description" content="How can an email address be validated in JavaScript?" /> <meta property="og:url" content="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript"/> <link rel="canonical" href="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript" />
  • 17. Returning JSON Object JSON Simplyreturn a dictionary or list @route("/json") def jason(): return {"lastname":"bourne", "alias":"David Webb"}
  • 18. Returning Static HTML HTML Use static_file from bottle @route("/loginpage") def loginpage(): return static_file("login.html", root=".")
  • 19. Testing the POST Handler Visit localhost:8081/loginpage Type your nameand use any of theseas passwordg gloopgroup, devconph, adventuretime Click submit
  • 20. The POST Request Cycle <form action="/login" method="POST"> Method dictates what kind of request happens when submitted Action tells the browser where to submit the request <input type="text" name="username"> Adds a text input that will be associated to the username field <input type="password" name="password"> Adds a password inputthat willbe associatedto the password field <input type="submit"> Adds a button that submits the form whenclicked
  • 21. Returning Dynamic HTML HTML Use a templatingengine: • Library thatcan substitutevariables intoa templatequickly and cleanly • Isolates thedesigner’s job of designing and thecoder’s job of coding
  • 22. Install Tenjin pip install tenjin easy_install tenjin
  • 23. Using Tenjin from gevent import monkey; monkey.patch_all() from bottle import run, route, request import tenjin from tenjin.helpers import * @route("/introduction/<name>/<age>/<work>") def template1(name, age, work): context = {"name":name, "age":age, "work":work} return engine.render("introduction.html", context); engine = tenjin.Engine(path=['.']) run(server='gevent', host="localhost", port=8001, debug=True)
  • 24. The template <!doctype html> <html lang="en"> <head> <title>Login</title> </head> <body> <h1>${name}</h1> <h2>Age:${age}<h2> <h2>Work:${work}<h2> </body> </html>
  • 25. Step from gevent import monkey; monkey.patch_all() from bottle import run, route, request import tenjin from tenjin.helpers import * Import alllibraries, including tenjin and all helper methods @route("/introduction/<name>/<age>/<work>") Define a route for the url, and define variables in it def template1(name, age, work): Declare a request handler and receive the variables from the url
  • 26. Step context = {"name":name, "age":age, "work":work} Define a context variable, which is a dictionary of values that will be substituted into the template return engine.render("introduction.html", context); Render the template called introduction.html using the context variable named context, and return it to the browser engine = tenjin.Engine(path=['.']) Instructs the templating engine to look for the templates in the directories listed in path
  • 27. Step (Inside the template) <!doctype html> <html lang="en"> <head> <title>Login</title> </head> <body> <h1>${name}</h1> <h2>Age:${age}<h2> <h2>Work:${work}<h2> </body> </html> { "name":"Paolo", "age":"30", "work":"Synergist" } +
  • 28. Displaying Lists @route("/spell/<word>") def template1(word): letters = list(word) context = {"letters":letters, "word":word} return engine.render("speller.html", context);
  • 29. Step @route("/spell/<word>") Define a route that accepts a variable assigned to word def speller(word): Define a handler that accepts avariable named word letters = list(word) Convert the text string into a listobject. From a string “word”, it becomes a list [“w”, “o”, “r”, “d”]
  • 30. Step context = {"letters":letters} Define a context variable, which contains the listof letters we just created return engine.render("speller.html", context); Render the template called speller.html using the context variable named context, and return it to the browser
  • 31. Step (Inside the template) <?py for letter in letters: ?> Loop on the elements of the list named letters <h3>${letter}</h3><br> Display the element letter along with the html <?py #endfor ?> Denote where the loop ends inthe template <a href="/greet/${word}">greet ${word}</a> Create a link that willcall the greet API we created earlier {"letters":["s", "u", "s", "h", "i"]}
  • 32. Highlighting Names @route("/profiles/<name>") def profile(name): users = [ {"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"}, {"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"} ] context = {"users":users, "name":name} return engine.render("profiles.html", context)
  • 33. Step users = [ {"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"}, {"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"} ] Define a list of dictionaries, with each dictionary objectcontaining information about a user. It contains information name,url of the image, age, and work context = {"users":users, "name":name} Define a conext containing the name to behighlighted, and the list of users return engine.render("profiles.html", context) Render the template named profiles.html with the context
  • 34. Step (Inside the template) <?py for user in users: ?> Loop on the elements of the list named users, each element in the listcan be referred to using the user variable <div style="height:100px;"> Create a div element in the html to contain one user element <img src="${user['image']}" style="float:left; height:100%;"/> Place an image in the html coming from the url defined in user[‘image’]
  • 35. Step (Inside the template) <?py if name==user["name"]: ?> Compare the current user’s name to the name entered in the url <strong>Name: ${user['name']}</strong> Thishappens when the above condition istrue, display the name asbold characters <?py else: ?> Add an else handler that executes if condition is not met
  • 36. Step (Inside the template) Name: ${user['name']} This happens when primary condition is not met, display the user’s name without any decorations <?py #endif ?> Denote where the if statement ends
  • 37. Make a Sushi Menu Create a menu using allthe sushiitems in the sushilistvariable Display the image and name of the sushi When the menu item is clicked, it should display another page containingthe name, image, price, and rating of the sushi(defined in the sushilistvariable) The most creative presentation of the menu wins aprize
  • 38. Activity 1 pip install gevent pip install bottle
  • 39. Cost per Mille = • Cost per 1000 impressions • Abuse of statistics • i.e. Magic • i.e. It sucks • Not based on empirical measured data ADVERTISING! Eyeballs cost
  • 40. How many are watching me right now? How many are paying attention? How many are interested? How many are still reading this part? How about now? Now?
  • 41.
  • 42. ROUTER ON PROMISCUOUS MODE DEVICEs SENDING PROBE REQUESTS
  • 48. snoop
  • 49. turn off your phones when going to the lagoon

Editor's Notes

  1. This is our current project onewatt. It’s a device that can save you up to 40% in your electricity bills by utilizing fluctuations in electricicty prices in WESM throughout the day. How?
  2. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  3. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  4. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  5. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  6. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  7. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  8. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  9. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  10. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  11. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  12. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  13. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  14. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  15. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  16. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  17. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  18. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  19. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  20. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  21. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  22. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  23. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  24. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  25. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  26. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  27. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  28. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  29. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  30. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  31. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  32. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  33. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  34. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  35. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  36. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  37. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  38. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  39. One of the key metrics used in advertising is the number of eyeballs gained by an ad. Makes sense, since advertisers are paying to have their ads seen by the most amount of people. The problem with this though is that this number, or Cost per Mille, is an abuse of statistics, it is not based on a solid methodology. So back then we did this media wall project in Shanghai. we wanted to prove how many people saw the ad, and how long people were looking at it. So we devised a way to have more empirical data.
  40. As of now, I can empirically estimate about ___________ watching me right now.   (turn on device and get count)
  41. The setup is actually quite simple. You can even do it with a router, but for this purpose, I used a pi, connected to a wifi dongle, and this cute little screen i salvaged from an old tv, all powered by a power bank. Very mcgyvery.
  42. This wifi transmitter is set to promiscuous mode, para syang carinderia na bukas sa lahat ng gutong kumain, actually worse, bukas kahit sa mga walang planong kumain. Using this, I am able to sniff all the traffic being trasmitted by all the dvices, specifically probe requests, within a certain range, (with this range varying based on the yyy used).
  43. The CPU, running python, gets the output of tcpdump, mining all the sniffed mac addresses and adding timestamps to each record withing the vicinity, without them installing anything on their device or being aware. So right now I am getting all the mad accdresses of the devices of this group right here, since they are withing x meters form me, which I can now use to check for uniqueness, use for idnetification or use in whatever evil scheme I plan. Sounds excting diba? Borderline snooping.
  44. We ran this on 2 pilot sites, one in Zhngshan park, and the other in Lujiazhui station. Using my setup, on the average, there were 23000 people who pass by our screens everyday, 36% of which stopped and watched for at least 2 secs, and around 10% stayed finished the 15 second ad.
  45. So, especially for the group here <referto prev group>, so what if you got our mac addrsses, that doesn’t sound too bad, are there other possible application of this?
  46. I have used this device in stores to measure foot traffic. I can identify how a customer moves between shelves, and identifying which items attract the most views. Which is important data for a retailer or advertiser.
  47. You can also use this as a replacemnt for gps in geofencing. By attenuating the broadcast range to a specific area. You can then identify new and returning customers to your shop, and instruct your staff to be more accommodating to new customers going in.
  48. And the most fun thing to do with this s probably just snoop. Imagine if we install one of these in each classroom. Using simple data such as class schedules, we can then relate a mac address to a specific student. Imagine then if we leave this device in the lagoon area. We will now have a list of people visiting that spot at say 10pm onwards. Who is meeting who, who is coming in in groups of 2 or even people coming in groups of 3 or more.
  49. So in summary, turn off your phones when going to the lagoon.