際際滷

際際滷Share a Scribd company logo
Cross Domain Web
Mashups with JQuery
and Google App Engine




Andy McKay. Clearwind Consulting
http://clearwind.ca
Also known as
A bunch of cool buzz words to try and describe
    some of the stuff Im doing these days
   and get me in to talk at cool conferences
Cross Domain
   JQuery
 App Engine
Cross Domain
   JQuery
 App Engine
mashup
a web page or application that combines data
  from two or more external online sources
reusable web applications
that aren't SOAP and WSDL

"The three chief virtues of a programmer are: Laziness,
         Impatience and Hubris. Larry Wall
back in time...
Zope 2
Plone
 Rails
Django
rewriting things constantly
 is good for billable hours
small web applications
    returning xml
Ajax


 browser: rails.site.ca


                                 server: another.ca

browser: django.site.ca
there's a problem
Single origin policy
browser: clearwind.ca                           server: some.other.ca

The same origin policy prevents document or script loaded from one origin from getting
or setting properties of a document from a different origin.
-- From http://www.mozilla.org/projects/security/components/same-origin.html
1. proxy


browser: clearwind.ca   server: clearwind.ca   server: some.other.ca
2. hacks

  鍖ash
 iframe
document
  script
3. JSONP

JavaScript Object Notation
       with Padding
Example: json-time
                 By Simon Willison
           http://json-time.appspot.com/
http://github.com/simonw/json-time/tree/master
JSON
{
    "tz": "America/Chicago",
    "hour": 3,
    "datetime": "Tue, 19 May 2009 03:06:50 -0500",
    "second": 50,
    "error": false,
    "minute": 6
}
JSONP

process_time({
  "tz": "America/Chicago",
  "hour": 3,
  "datetime": "Tue, 19 May 2009 03:09:09 -0500",
  "second": 9,
  "error": false,
  "minute": 9
})
Cross Domain
   JQuery
 App Engine
JQuery for json-time


var url = "http://json-time.appspot.com/timezones.json?"

$.getJSON(url + "callback=?",
        function (json) {
          ...
        });
JSON time demo
Complete JSON time demo
$(document).ready(function() {
    var url = "http://json-time.appspot.com";

      function showTime(data) {
          $.getJSON(url + "/time.json?tz=" + $("#zones").val() + '&callback=?',
              function (json){
                  $("#zones-msg").text('The time is now ' + json["datetime"] + '.');
              });
      };

      $.getJSON(url + "/timezones.json?callback=?",
          function (json) {
              var zones = $("#zones");
              for (var k = 0; k < json.length; k++) {
                  zones.append("<option>" + json[k] + "</option>");
              };
              zones.bind("change", showTime)
          });
});
Cross Domain
   JQuery
 App Engine
Easiest deployment
  Best scalability
  Minimal effort
Not straight Python
Has it's limitations and quirks
And it's free
Example Mashup
  The coolest technology of 2006
          Google Maps
The most hyped technology of 2009
               Twitter
Twitter messages with a map
 by hash tag eg: #owv2009
Step 1:
Assign hash tag to location
geohashtag.appspot.com




browser: geohashtag.appspot.com   server: geohashtag.appspot.com
Model

from google.appengine.ext import db

class Tag(db.Model):
    name = db.StringProperty(required=True)
    geostring = db.StringProperty(required=True)
Issue
You cannot do an inequality test on two 鍖elds in one query.
                     Or use GeoPt.

               GeoHash solves this problem:
           http://en.wikipedia.org/wiki/Geohash
JSON

     tag.json (returns location for a tag)
bounds.json (returns all the tags in a rectangle)
Geohashtag demo
Step 2:
Parse RSS into JSONP
atomtojsonp.appspot.com




browser: atomtojsonp.appspot.com                 server: search.twitter.com
                         server: atomtojsonp.appspot.com
Proxy?
    Because twitter doesn't have JSON export
Other services like Google RSS or Yahoo YQL have
                     problems

  But checkout: http://developer.yahoo.com/yql/
   and http://code.google.com/apis/ajaxfeeds/
No Model

Quite common for
  App Engine
Just feedparser
                  http://www.feedparser.org/


class JSONHandler(webapp.RequestHandler):
    def get(self):
        url = self.request.get("url")
        data = feedparser.parse(url)
        if self.request.get("callback"):
            data = "%s(%s)" % (self.request.get("callback"), data)
        self.response.out.write(data)
JSON

twitter.json (smaller twitter version for a search term)
         atom.json (a whole atom 鍖le for a url)
Atomtwojsonp demo
Step 3:
Mash it up
geojsontweet.appspot.com


browser: geojsontweet.appspot.com   server: maps.google.com




browser: geojsontweet.appspot.com
geojsontweet.appspot.com


browser: geojsontweet.appspot.com     server: maps.google.com




browser: geojsontweet.appspot.com   server: geohashtag.appspot.com




browser: geojsontweet.appspot.com
geojsontweet.appspot.com


browser: geojsontweet.appspot.com                server: maps.google.com




browser: geojsontweet.appspot.com              server: geohashtag.appspot.com




browser: geojsontweet.appspot.com                server: search.twitter.com
                         server: atomtojsonp.appspot.com
No Model
In fact, completely static HTML
  (with JS, no server side code)
Some Javascript
function move() {
        var bounds = map.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();

       var url = map_details.tags_domain + '/bounds.json?nelat=';
       url += ne.lat() + '&nelon=' + ne.lng();
       url += '&swlon=' + sw.lng() + '&swlat=' + sw.lat() + '&callback=?'

       if (map_details.last_url != url) {
           map_details.last_url = url
           $.getJSON(url,
               function(json) {
                   if (json) {
                       for (var k = 0; k < json.length; k++) {
                           ...
Some more Javascript

function twitter() {
    var tag = null;
    for (var obj in tags) {
        var url = map_details.atom_domain + '/twitter.json?tag=' + obj +
'&callback=?'
        $.getJSON(url,
            function(json) {
                var tweet = null;
                for (var k = 0; k < json.length; k++) {
                     ....
際際滷show
     http://鍖owplayer.org/tools/scrollable.html


$("#tweets-" + tweet["tag"]).parent().scrollable({
    interval: 4000,
    loop: true,
    speed: 600,
    onBeforeSeek: function() {
        this.getItems().fadeTo(300, 0.2);	 	
    },
    onSeek: function() {
        this.getItems().fadeTo(300, 1);
    }
});
Geojsontweet demo
Serious issues
Trust
You are executing someone else's JavaScript
     in your site. Better be trustworthy.
Single points of failure?
Single points of failure?
Enterprise
Internal servers?
huhu
Questions?
Code: http://svn.clearwind.ca/public/projects/presentations
                 Email: andy@clearwind.ca

More Related Content

What's hot (20)

PDF
rx.js make async programming simpler
Alexander Mostovenko
PPTX
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
PDF
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Sages
PDF
async/await in Swift
Peter Friese
PDF
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
Codemotion
PDF
Code is Cool - Products are Better
aaronheckmann
PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
PDF
Wrangling WP_Cron - WordCamp Grand Rapids 2014
cklosowski
PDF
Large Scale Log Analytics with Solr (from Lucene Revolution 2015)
Sematext Group, Inc.
PDF
Web Scraping with Python
Paul Schreiber
PDF
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
Anton
PDF
World of Logging
Christian Grobmeier
PDF
ABCD firebase
PDF
Fake My Party
Tanja Otto
PDF
Boom! Promises/A+ Was Born
Domenic Denicola
PDF
React for Beginners
Derek Willian Stavis
PDF
Scrapy workshop
Karthik Ananth
PDF
Pydata-Python tools for webscraping
Jose Manuel Ortega Candel
PPTX
Realm - Phoenix Mobile Festival
DJ Rausch
PDF
Downloading the internet with Python + Scrapy
Erin Shellman
rx.js make async programming simpler
Alexander Mostovenko
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Sages
async/await in Swift
Peter Friese
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
Codemotion
Code is Cool - Products are Better
aaronheckmann
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
Wrangling WP_Cron - WordCamp Grand Rapids 2014
cklosowski
Large Scale Log Analytics with Solr (from Lucene Revolution 2015)
Sematext Group, Inc.
Web Scraping with Python
Paul Schreiber
How to Scrap Any Website's content using ScrapyTutorial of How to scrape (cra...
Anton
World of Logging
Christian Grobmeier
ABCD firebase
Fake My Party
Tanja Otto
Boom! Promises/A+ Was Born
Domenic Denicola
React for Beginners
Derek Willian Stavis
Scrapy workshop
Karthik Ananth
Pydata-Python tools for webscraping
Jose Manuel Ortega Candel
Realm - Phoenix Mobile Festival
DJ Rausch
Downloading the internet with Python + Scrapy
Erin Shellman

Similar to huhu (20)

KEY
CouchDB on Android
Sven Haiges
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
PDF
OneRing @ OSCamp 2010
Qiangning Hong
PPTX
Ajax for dummies, and not only.
Nerd Tzanetopoulos
PDF
mobl
zefhemel
PPTX
Spicy javascript: Create your first Chrome extension for web analytics QA
Alban G辿r担me
PDF
The Big Picture and How to Get Started
guest1af57e
PDF
Future of Web Apps: Google Gears
dion
KEY
JavaScript Growing Up
David Padbury
PPTX
Designing REST API automation tests in Kotlin
Dmitriy Sobko
PDF
soft-shake.ch - Hands on Node.js
soft-shake.ch
PDF
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weling
PDF
Bonnes pratiques de d辿veloppement avec Node js
Francois Zaninotto
PDF
Integrating React.js Into a PHP Application
Andrew Rota
PDF
Os Pruett
oscon2007
PDF
Node.js - async for the rest of us.
Mike Brevoort
PDF
Build web application by express
Shawn Meng
KEY
Writing robust Node.js applications
Tom Croucher
PDF
08 ajax
Ynon Perek
PPTX
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
zmulani8
CouchDB on Android
Sven Haiges
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
OneRing @ OSCamp 2010
Qiangning Hong
Ajax for dummies, and not only.
Nerd Tzanetopoulos
mobl
zefhemel
Spicy javascript: Create your first Chrome extension for web analytics QA
Alban G辿r担me
The Big Picture and How to Get Started
guest1af57e
Future of Web Apps: Google Gears
dion
JavaScript Growing Up
David Padbury
Designing REST API automation tests in Kotlin
Dmitriy Sobko
soft-shake.ch - Hands on Node.js
soft-shake.ch
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weling
Bonnes pratiques de d辿veloppement avec Node js
Francois Zaninotto
Integrating React.js Into a PHP Application
Andrew Rota
Os Pruett
oscon2007
Node.js - async for the rest of us.
Mike Brevoort
Build web application by express
Shawn Meng
Writing robust Node.js applications
Tom Croucher
08 ajax
Ynon Perek
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
zmulani8
Ad

More from Dung Tr動董ng (14)

TXT
Test
Dung Tr動董ng
PPTX
My cool new 際際滷show!
Dung Tr動董ng
TXT
畛 c動董ng kh坦a lu畉n
Dung Tr動董ng
PPTX
My cool new 際際滷show!
Dung Tr動董ng
PPTX
9-1-13
Dung Tr動董ng
TXT
My cool new 際際滷show! thu
Dung Tr動董ng
DOC
珂畛i
Dung Tr動董ng
DOCX
畛 c動董ng kh坦a lu畉n
Dung Tr動董ng
PDF
344444
Dung Tr動董ng
PPTX
Up th畛 c叩i m畛i
Dung Tr動董ng
PPTX
際際滷show!
Dung Tr動董ng
PPTX
際際滷show m畛i up n竪. ^_^
Dung Tr動董ng
PPTX
new 際際滷show!
Dung Tr動董ng
PPTX
My cool new 際際滷show!
Dung Tr動董ng
My cool new 際際滷show!
Dung Tr動董ng
畛 c動董ng kh坦a lu畉n
Dung Tr動董ng
My cool new 際際滷show!
Dung Tr動董ng
My cool new 際際滷show! thu
Dung Tr動董ng
珂畛i
Dung Tr動董ng
畛 c動董ng kh坦a lu畉n
Dung Tr動董ng
Up th畛 c叩i m畛i
Dung Tr動董ng
際際滷show!
Dung Tr動董ng
際際滷show m畛i up n竪. ^_^
Dung Tr動董ng
new 際際滷show!
Dung Tr動董ng
My cool new 際際滷show!
Dung Tr動董ng
Ad

huhu