SlideShare a Scribd company logo
1 of 45
Download to read offline
Welcome...
to the inaugural meeting of Chippenham Tech Chat...
Meetup Details
Will be hosted once a month at Mango/Scisys - Methuen Park
Presentations on various topics. If you're interested in doing one
then propose it on the forum
Meetup group
http://www.meetup.com/Chippenham-Tech-Chat/
Google Groups Forum
https://groups.google.com/forum/?fromgroups#!
forum/chippenhamtechchat
Lightweight Web Frameworks
Jonathan Holloway
jholloway@mango-solutions.com
twitter: jph98
Overview
● A brief history of web applications
● Past experience
● An overview of lightweight web frameworks
● An introduction to one web framework and
it's features
● I won't go into
Web Frameworks - A Brief History
● CGI and Perl - circa 1993
● PHP, Coldfusion - circa 1995
● ASP - circa 1998
● JSP and Servlet Spec - circa 1999
● Struts - circa 2001
● Rails - circa 2005
How many are there today?
261 !
* at least
Used Java Servlets and JSP around 1999/2000.
First introduction - somewhat painful.
Then discovered Struts in 2001/2002 (pre 1.0
release). Vowed never to go back to JSP hell.
In 2005/2006 we migrated our legacy Struts apps
to Struts 2. Better still.
SpringMVC came in around the same time.
Past Experience - Cathedrals
Broken down into language (approx)
91 33 31 40
14 22 23 7
Past Experience - Post Java
Then looked at PHP for doing more lightweight
work. Used CakePHP 1.x then looked at
CodeIgniter.
Used Dojo (pre 1.0 release) and Velocity to
build a rich client Javascript application.
Past Experience - First One Pager
Then ended up building a rich client interface in
Google Web Toolkit 1.x
Then around 2007 went along to the Vancouver
Ruby/Rails meetup. Talked about Rails/Merb
then someone mentioned Sinatra.
Then picked up Flask, looked at Ratpack in
Geecon this year
Flask - Python
Really?
Here's what we would have have done back in
the day with Apache Struts...
1. Setup web.xml
2. Created an index.jsp to forward on to my app
3. Setup struts-config.xml and added a form
and action mapping detailing my Action class
4. Create an Action & Action Form class
5. Setup my forward on success
6. Put all this in a predefined folder structure
7. Package it all up into a war file
8. Deploy to Tomcat and Start
then....
9. Fix the stupid errors
10. Deploy again and see Hello World in my
browser. Maybe.
easy...
Others?
There's others !!
There's a bunch of other lightweight web
frameworks in various languages:
● Flask - Python
● Nancy - .NET
● Ratpack - Groovy/Java
● Berliner - CoffeeScript
● Dancer - Perl
Classification of these...
Web Framework Taxonomy
Sinatra, Flask, Berliner, Dancer, Ratpack, Nancy
[Micro Frameworks]
Rails, Django
[Lightweight Frameworks]
Play, Struts 2, Spring MVC
[MOR]
Google Web Toolkit, JSF
[Component Based]
Light
Heavy
Sinatra - Ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
get '/' do
'<b>Hello, world!</b>'
end
Nancy - dot NET
public class SampleModule : Nancy.
NancyModule
{
public SampleModule()
{
Get["/"] = _ => "Hello
World!";
}
}
Ratpack - Groovy
get("/helloworld") {
"Hello, World!"
}
Berliner - Coffeescript
app = require 'berliner'
app.get '/', -> 'Hello, world!'
app.run 4567
Properties of such frameworks?
● Minimalistic by default
● Self contained web server
● Modular with extensions available
Some more on Flask...
Python Flask Architecture
Based on Werkzeug so mod_wsgi based
Built in web server
Uses Jinja2 for templating
Hosting available on heroku, webfaction
Celery integration for async task/job queuing
Flask Extension Modules
Example modules (will cover later):
● Flask admin - generates an admin interface
● Flask login - login mechanism
● Flask cache - simple caching
● Flask couchdb - couchdb module
● Flask lesscss - less CSS template
● Flask lettuce - BDD
● Flask celery - distributed task queue
Extensions registry here:
http://flask.pocoo.org/extensions/
What can I use Flask for?
1. Projects with tight deadlines
2. Prototyping
3. In-house internal applications
4. Applications where system resources are
limited, e.g. VM's hosted on Linode.com
App
Flask App - Log Viewer
A lightweight log viewer application, but without
the overhead of indexing. Provides:
● Access to specific application logs for users
instead of them ssh'ing to the server to "less"
them.
● Retrieve the head or tail a log file
● Search in logs (with grep) for an expression
Flask 0.9 utilising:
● YAML (Yet Another Markup Language) for
configuration
● Jinja 2 templates for content separation
● The LESS dynamic stylesheet module
Virtualenv - for creating an isolated Python
environment to manage dependencies
Python 2.6.1 (CPython)
System Components
Python Modules
Used additional Python wrappers for
Grin - http://pypi.python.org/pypi/grin
● Provides search features (wraps GNU grep)
● Supports regex, before/after context
● File/dir exclusion
Tailer - http://pypi.python.org/pypi/tailer/0.2.1
● Display n lines of the head/tail of a file
● Allows "follow" of a file
Main UI
Templating
<!doctype html>
{% include 'header.html' %}
{% include 'search.html' %}
{% macro genlink(func, filename) -%}
<a href="{{func}}/{{ filename }}/{{ session['grepnumlines'] }}">{{func}}</a>
{%- endmacro %}
{% for filename in session['validfiles']|sort %}
<div class="logfile">
{{ session['validfiles'].get(filename)[0] }} -
{{ genlink('head', filename) }} &nbsp;<span style="color:#cecece">&#124;</span>
&nbsp;
{{ genlink('tail', filename) }}
- {{ session['validfiles'].get(filename)[1] }} bytes
</div>
{% endfor %}
{% include 'footer.html' %}
New route() for grep
@app.route("/grep/", methods=['GET', 'POST'])
def grep():
"""Search through a file looking for a matching phrase"""
# Validate the form inputs
if request is None or request.form is None:
return render_template('list.html',error='no search expression specified')
if request.form['expression'] is None or len(request.form['expression']) == 0:
return render_template('list.html',error='no search expression specified')
expression = request.form['expression'].strip()
output = ""
filepaths = []
output += search_expr(output, filepaths, session.get('validfiles'), expression, request.form['grepbefore'], request.form
['grepafter'])
if not output:
return render_template('list.html', error='No results found for search expression')
expression = expression.decode('utf-8')
highlight = '<span class="highlightmatch">' + expression + '</span>'
highlightedoutput = output.decode('utf-8').replace(expression, highlight)
return render_template('results.html', output=highlightedoutput,filepaths=filepaths,expression=expression)
Search Expression - using grin
def search_for_expression(output, filepaths, validfiles, expression, grepbefore, grepafter):
"""Carry out search for expression (using grep context) on validfiles returning matching files as output"""
options = grin.Options()
options['before_context'] = int(grepbefore)
options['after_context'] = int(grepafter)
options['use_color'] = False
options['show_filename'] = False
options['show_match'] = True
options['show_emacs'] = False
options['show_line_numbers'] = True
searchregexp = re.compile(expression)
grindef = grin.GrepText(searchregexp, options)
for file in validfiles:
filepath = validfiles.get(file)[0]
report = grindef.grep_a_file(filepath)
if report:
output += '<a name="filename' + str(anchorcount) + '"></a><h2>' + filepath + '</h2>'
filepaths.append(filepath)
reporttext = report.split("n")
for text in reporttext:
if text:
output += "line " + text + "<br>"
return output
Search UI
Modules
cache = Cache(app)
cache.init_app(app)
cache = Cache(config={'CACHE_TYPE': 'simple'})
#Use a decorator to cache a specific template with
@cache.cached(timeout=50)
def index():
return render_template('index.html')
Flask Cache
man = CouchDBManager()
man.setup(app)
# Create a local proxy to get around the g.couch namespace
couch = LocalProxy(lambda: g.couch)
# Store a document and retrieve
document = dict(title="Hello", content="Hello, world!")
couch[some_id] = document
document = couch.get(some_id)
Flask CouchDB
from flask_mail import Message
@app.route("/")
def index():
msg = Message("Hello",
sender="from@example.com",
recipients=["to@example.com"])
Flask Mail
from flask import Flask, Response
from flask_principal import Principal, Permission, RoleNeed
app = Flask(__name__)
# load the extension
principals = Principal(app)
# Create a permission with a single Need, in this case a RoleNeed.
admin_permission = Permission(RoleNeed('admin'))
# protect a view with a principal for that need
@app.route('/admin')
@admin_permission.require()
def do_admin_index():
return Response('Only if you are an admin')
Flask Principles
Q&A

More Related Content

What's hot

Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Marcel Chastain
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Mark Hamstra
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2Confiz
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
A History of PHP
A History of PHPA History of PHP
A History of PHPXinchen Hui
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golangdo_aki
 
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTS
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTSCertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTS
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTScpsitgmbh
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Michael Pirnat
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6Webline Infosoft P Ltd
 
Phing: Building with PHP
Phing: Building with PHPPhing: Building with PHP
Phing: Building with PHPhozn
 

What's hot (20)

Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
How PHP works
How PHP works How PHP works
How PHP works
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
PHP Function
PHP Function PHP Function
PHP Function
 
Xmla4js
Xmla4jsXmla4js
Xmla4js
 
PHP Profiling/performance
PHP Profiling/performancePHP Profiling/performance
PHP Profiling/performance
 
ZendCon 08 php 5.3
ZendCon 08 php 5.3ZendCon 08 php 5.3
ZendCon 08 php 5.3
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Ant vs Phing
Ant vs PhingAnt vs Phing
Ant vs Phing
 
Php advance
Php advancePhp advance
Php advance
 
A History of PHP
A History of PHPA History of PHP
A History of PHP
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golang
 
REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTS
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTSCertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTS
CertiFUNcation 2017 Best Practices Extension Development for TYPO3 8 LTS
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6
 
Phing: Building with PHP
Phing: Building with PHPPhing: Building with PHP
Phing: Building with PHP
 

Similar to Lightweight web frameworks

20100707 e z_rmll_gig_v1
20100707 e z_rmll_gig_v120100707 e z_rmll_gig_v1
20100707 e z_rmll_gig_v1Gilles Guirand
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.orgTed Husted
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Ryan Price
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
Using Search API, Search API Solr and Facets in Drupal 8
Using Search API, Search API Solr and Facets in Drupal 8Using Search API, Search API Solr and Facets in Drupal 8
Using Search API, Search API Solr and Facets in Drupal 8Websolutions Agency
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python MeetupAreski Belaid
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
01 overview-and-setup
01 overview-and-setup01 overview-and-setup
01 overview-and-setupsnopteck
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?Wong Hoi Sing Edison
 

Similar to Lightweight web frameworks (20)

Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
20100707 e z_rmll_gig_v1
20100707 e z_rmll_gig_v120100707 e z_rmll_gig_v1
20100707 e z_rmll_gig_v1
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
NodeJS
NodeJSNodeJS
NodeJS
 
Using Search API, Search API Solr and Facets in Drupal 8
Using Search API, Search API Solr and Facets in Drupal 8Using Search API, Search API Solr and Facets in Drupal 8
Using Search API, Search API Solr and Facets in Drupal 8
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Flask Introduction - Python Meetup
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
01 overview-and-setup
01 overview-and-setup01 overview-and-setup
01 overview-and-setup
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
dJango
dJangodJango
dJango
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 

More from Jonathan Holloway

More from Jonathan Holloway (11)

The Role of the Architect
The Role of the ArchitectThe Role of the Architect
The Role of the Architect
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Mockito intro
Mockito introMockito intro
Mockito intro
 
Debugging
DebuggingDebugging
Debugging
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Application design for the cloud using AWS
Application design for the cloud using AWSApplication design for the cloud using AWS
Application design for the cloud using AWS
 
Building data pipelines
Building data pipelinesBuilding data pipelines
Building data pipelines
 
Introduction to JVM languages and Fantom (very brief)
Introduction to JVM languages and Fantom (very brief)Introduction to JVM languages and Fantom (very brief)
Introduction to JVM languages and Fantom (very brief)
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Introduction to using MongoDB with Ruby
Introduction to using MongoDB with RubyIntroduction to using MongoDB with Ruby
Introduction to using MongoDB with Ruby
 

Recently uploaded

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Lightweight web frameworks

  • 1.
  • 2. Welcome... to the inaugural meeting of Chippenham Tech Chat...
  • 3. Meetup Details Will be hosted once a month at Mango/Scisys - Methuen Park Presentations on various topics. If you're interested in doing one then propose it on the forum Meetup group http://www.meetup.com/Chippenham-Tech-Chat/ Google Groups Forum https://groups.google.com/forum/?fromgroups#! forum/chippenhamtechchat
  • 4. Lightweight Web Frameworks Jonathan Holloway jholloway@mango-solutions.com twitter: jph98
  • 5. Overview ● A brief history of web applications ● Past experience ● An overview of lightweight web frameworks ● An introduction to one web framework and it's features ● I won't go into
  • 6. Web Frameworks - A Brief History ● CGI and Perl - circa 1993 ● PHP, Coldfusion - circa 1995 ● ASP - circa 1998 ● JSP and Servlet Spec - circa 1999 ● Struts - circa 2001 ● Rails - circa 2005 How many are there today?
  • 7. 261 ! * at least
  • 8. Used Java Servlets and JSP around 1999/2000. First introduction - somewhat painful. Then discovered Struts in 2001/2002 (pre 1.0 release). Vowed never to go back to JSP hell. In 2005/2006 we migrated our legacy Struts apps to Struts 2. Better still. SpringMVC came in around the same time. Past Experience - Cathedrals
  • 9. Broken down into language (approx) 91 33 31 40 14 22 23 7
  • 10. Past Experience - Post Java Then looked at PHP for doing more lightweight work. Used CakePHP 1.x then looked at CodeIgniter. Used Dojo (pre 1.0 release) and Velocity to build a rich client Javascript application.
  • 11. Past Experience - First One Pager Then ended up building a rich client interface in Google Web Toolkit 1.x Then around 2007 went along to the Vancouver Ruby/Rails meetup. Talked about Rails/Merb then someone mentioned Sinatra. Then picked up Flask, looked at Ratpack in Geecon this year
  • 14. Here's what we would have have done back in the day with Apache Struts...
  • 15. 1. Setup web.xml 2. Created an index.jsp to forward on to my app 3. Setup struts-config.xml and added a form and action mapping detailing my Action class 4. Create an Action & Action Form class
  • 16. 5. Setup my forward on success 6. Put all this in a predefined folder structure 7. Package it all up into a war file 8. Deploy to Tomcat and Start
  • 17. then.... 9. Fix the stupid errors 10. Deploy again and see Hello World in my browser. Maybe.
  • 20. There's others !! There's a bunch of other lightweight web frameworks in various languages: ● Flask - Python ● Nancy - .NET ● Ratpack - Groovy/Java ● Berliner - CoffeeScript ● Dancer - Perl Classification of these...
  • 21. Web Framework Taxonomy Sinatra, Flask, Berliner, Dancer, Ratpack, Nancy [Micro Frameworks] Rails, Django [Lightweight Frameworks] Play, Struts 2, Spring MVC [MOR] Google Web Toolkit, JSF [Component Based] Light Heavy
  • 22. Sinatra - Ruby #!/usr/bin/env ruby require 'rubygems' require 'sinatra' get '/' do '<b>Hello, world!</b>' end
  • 23. Nancy - dot NET public class SampleModule : Nancy. NancyModule { public SampleModule() { Get["/"] = _ => "Hello World!"; } }
  • 24. Ratpack - Groovy get("/helloworld") { "Hello, World!" }
  • 25. Berliner - Coffeescript app = require 'berliner' app.get '/', -> 'Hello, world!' app.run 4567
  • 26. Properties of such frameworks? ● Minimalistic by default ● Self contained web server ● Modular with extensions available
  • 27. Some more on Flask...
  • 28. Python Flask Architecture Based on Werkzeug so mod_wsgi based Built in web server Uses Jinja2 for templating Hosting available on heroku, webfaction Celery integration for async task/job queuing
  • 29. Flask Extension Modules Example modules (will cover later): ● Flask admin - generates an admin interface ● Flask login - login mechanism ● Flask cache - simple caching ● Flask couchdb - couchdb module ● Flask lesscss - less CSS template ● Flask lettuce - BDD ● Flask celery - distributed task queue Extensions registry here: http://flask.pocoo.org/extensions/
  • 30. What can I use Flask for? 1. Projects with tight deadlines 2. Prototyping 3. In-house internal applications 4. Applications where system resources are limited, e.g. VM's hosted on Linode.com
  • 31. App
  • 32. Flask App - Log Viewer A lightweight log viewer application, but without the overhead of indexing. Provides: ● Access to specific application logs for users instead of them ssh'ing to the server to "less" them. ● Retrieve the head or tail a log file ● Search in logs (with grep) for an expression
  • 33. Flask 0.9 utilising: ● YAML (Yet Another Markup Language) for configuration ● Jinja 2 templates for content separation ● The LESS dynamic stylesheet module Virtualenv - for creating an isolated Python environment to manage dependencies Python 2.6.1 (CPython) System Components
  • 34. Python Modules Used additional Python wrappers for Grin - http://pypi.python.org/pypi/grin ● Provides search features (wraps GNU grep) ● Supports regex, before/after context ● File/dir exclusion Tailer - http://pypi.python.org/pypi/tailer/0.2.1 ● Display n lines of the head/tail of a file ● Allows "follow" of a file
  • 36. Templating <!doctype html> {% include 'header.html' %} {% include 'search.html' %} {% macro genlink(func, filename) -%} <a href="{{func}}/{{ filename }}/{{ session['grepnumlines'] }}">{{func}}</a> {%- endmacro %} {% for filename in session['validfiles']|sort %} <div class="logfile"> {{ session['validfiles'].get(filename)[0] }} - {{ genlink('head', filename) }} &nbsp;<span style="color:#cecece">&#124;</span> &nbsp; {{ genlink('tail', filename) }} - {{ session['validfiles'].get(filename)[1] }} bytes </div> {% endfor %} {% include 'footer.html' %}
  • 37. New route() for grep @app.route("/grep/", methods=['GET', 'POST']) def grep(): """Search through a file looking for a matching phrase""" # Validate the form inputs if request is None or request.form is None: return render_template('list.html',error='no search expression specified') if request.form['expression'] is None or len(request.form['expression']) == 0: return render_template('list.html',error='no search expression specified') expression = request.form['expression'].strip() output = "" filepaths = [] output += search_expr(output, filepaths, session.get('validfiles'), expression, request.form['grepbefore'], request.form ['grepafter']) if not output: return render_template('list.html', error='No results found for search expression') expression = expression.decode('utf-8') highlight = '<span class="highlightmatch">' + expression + '</span>' highlightedoutput = output.decode('utf-8').replace(expression, highlight) return render_template('results.html', output=highlightedoutput,filepaths=filepaths,expression=expression)
  • 38. Search Expression - using grin def search_for_expression(output, filepaths, validfiles, expression, grepbefore, grepafter): """Carry out search for expression (using grep context) on validfiles returning matching files as output""" options = grin.Options() options['before_context'] = int(grepbefore) options['after_context'] = int(grepafter) options['use_color'] = False options['show_filename'] = False options['show_match'] = True options['show_emacs'] = False options['show_line_numbers'] = True searchregexp = re.compile(expression) grindef = grin.GrepText(searchregexp, options) for file in validfiles: filepath = validfiles.get(file)[0] report = grindef.grep_a_file(filepath) if report: output += '<a name="filename' + str(anchorcount) + '"></a><h2>' + filepath + '</h2>' filepaths.append(filepath) reporttext = report.split("n") for text in reporttext: if text: output += "line " + text + "<br>" return output
  • 41. cache = Cache(app) cache.init_app(app) cache = Cache(config={'CACHE_TYPE': 'simple'}) #Use a decorator to cache a specific template with @cache.cached(timeout=50) def index(): return render_template('index.html') Flask Cache
  • 42. man = CouchDBManager() man.setup(app) # Create a local proxy to get around the g.couch namespace couch = LocalProxy(lambda: g.couch) # Store a document and retrieve document = dict(title="Hello", content="Hello, world!") couch[some_id] = document document = couch.get(some_id) Flask CouchDB
  • 43. from flask_mail import Message @app.route("/") def index(): msg = Message("Hello", sender="from@example.com", recipients=["to@example.com"]) Flask Mail
  • 44. from flask import Flask, Response from flask_principal import Principal, Permission, RoleNeed app = Flask(__name__) # load the extension principals = Principal(app) # Create a permission with a single Need, in this case a RoleNeed. admin_permission = Permission(RoleNeed('admin')) # protect a view with a principal for that need @app.route('/admin') @admin_permission.require() def do_admin_index(): return Response('Only if you are an admin') Flask Principles
  • 45. Q&A