Google Apps Engine Tips

Rollback

If an update for GAE (Google App Engine) doesn’t complete it will cause an error (similar to : Another transaction by user xxxx  is already in progress for this app and major version. That user can undo the transaction with appcfg.py’s “rollback” command.) and not allow you to upload new updates. The rollback can de done with a batch file. A faster solution to fix this problem is incrementing the version number in the app.yaml file and activating the new version in the online console. The same error arise if you want to delete an a app with failed update. The only solution in this case is to do the rollback.

Google App Engine (GAE)

Google App Engine

GAE (Google App Engine) is a platform for developing and hosting web applications in Google-managed data centers. It was first released as a beta version in April 2008. GAE is cloud computing technology. It virtualizes applications across multiple servers and data centers. GAE is Platform as a Service while AWS (Amazon Web Services) is Infrastructure as a Service.

GAE is free up to a certain level of used resources. Fees are charged for additional storage, bandwidth, or CPU cycles required by the application.

The applications of the logged Google developer are available at https://appengine.google.com/

List of GAE applications

The dashboard allows to manage the different applications (quotas, instances, logs, cron jobs, task queues, blacklists, datastore, blob viewer, settings, permissions, billing, resources, …). A very efficient feature is the version control based on the app.yaml file :

GAE version control

Another useful feature is the error logging :

GAE error logging reports

YAML and MVC

YAML is a human-readable data serialization format that takes concepts from programming languages such as C, Perl, Python, ideas from XML and the data format of electronic mail. YAML was first proposed by Clark Evans in 2001, who designed it together with Ingy döt Net and Oren Ben-Kiki.

MVC (Model–view–controller) is a software architecture considered as an architectural pattern used in software engineering. The pattern isolates “domain logic” (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns). MVC was first described in 1979 by Trygve Reenskaug, then working on Smalltalk at Xerox PARC.

Python conventions

last update : March 31, 2011

Module names

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__. Every Python module has it’s __name__ defined and if this is ‘__main__’, it implies that the module is being run standalone. The function called main doesn’t have any special significance in Python. However, it is common practice to organize a program’s main functionality in a function called main and call it with code similar to the following:

def main():
    # the main code goes here

if __name__ == "__main__":
    main()

Comments

There are two styles of comments in python :

# single line comments

" " " multiple

line

comments " " "

Multiline comments, enclosed by triple-quotes, are used to embed doc strings, for example in a class school. If you declare an object t=school and then t . __doc__ or t (help), the embedded comments are returned. Triple-quotes should not be used to comment out large blocks of Python code.

Self argument of methods

The first argument of a method is usually called self. This is nothing more than a convention: the name self has absolutely no special meaning to Python.  Programs that are not following these convention are less readable to other Python programmers and may fail in class browser programs which rely upon such a convention.

Unicode

In Python source code, Unicode literals are written as strings prefixed with the ‘u’ or ‘U’ character:

u'abcdefghijk'

Raw Strings

Raw strings are written as strings prefixed with the ‘r’ or ‘R’ character. Raw strings don’t treat the backslash as a special character. Every character you put into a raw string stays the way you wrote it.

r'/user/'

Indentation

Indentation (leading whitespaces) in Python counts. Every block structure — controls, classes, functions, etc. — must be indented the same number of times for their level in the program. Convention is to use four spaces (without tabs) for each level of indentation.

Line continuation

To break a long statement into several lines, the line continuation character (backslash) can be used at the end of the breaked physical lines (explicit line joining). This syntax is however outdated and should be avoided. Expressions in parentheses, square brackets or curly braces can be split over more than one physical line without using backslashes (implicit line joining). A line ending in a backslash cannot carry a comment, but implicitly continued lines can carry comments. The indentation of implicit continuation lines is not important.

Django : high-level Python Web framework

Django was designed to make common Web-development tasks fast and easy. Django adheres to the DRY (Don’t repeat yourself) principle.

Django comes with an object-relational mapper in which you describe your database layout in Python code. Other useful features are a caching framework that integrates with memcached or other backends and a syndication framework that makes creating RSS and Atom feeds as easy as writing a small Python class.

Django has a rich documentation and great tutorials. An active community gives answers to common questions and hints to solve problems.

The Google App Engine provides a Python runtime environment including Django as a third-party library. I started yesterday evening to host a first Facebook application, designed with Python and Django,  on the Google App Server.

Django was originally developed at World Online, the Web department of a newspaper in Lawrence, Kansas, USA. Django is now run by an international team of volunteers.

The main elements of the Django Template Language are :

  • variables :  {{section.title}}   the content is replaced by the title attribute of the section object
  • filters : {{name|ower}}   the content is replaced by the lowercase string of the name; there are about 30 built-in filters; custom template filters can be created
  • tags :  {% doit %}  tags are more versatile than variables;  tags can be used for loops, conditions, …; there are about 24 built-in tags; custom template tags can be created
  • comments :  {#my comment#}  only for single-line comments
  • decorators : @my_decorator   – a decorator is a function that wraps the decorated function  in yet another function, allowing you to run code both before and after the main function
  • template inheritance : {%block identifier%} …….. {%endblock%}   the content of the block named identifier in the base template can be overridden by the content specified in child templates

target=”_blank” validation

target=”_blank” is not valid code within webpages with a strict doctype declaration.

A valid replacement is :

<a href = “http://www.example.com” onclick = “window.open(this.href); return false;”>my link </a>

The onclick=”window.open(this.href); return false;”  is an inbuilt javascript method and needs a <meta> declaration  to work properly in in xml, strict xhtml or html4 source code pages.

<meta http-equiv=”Content-Script-Type” content=”text/javascript”>

target=”_blank” is however 100% valid in HTML5.

Facebook Feed Dialog

The Facebook Feed Dialog prompts a user to publish an individual story to a profile’s feed. This does not require any extended permissions. Every dialog has a method name and parameters. The URL to a dialog always starts with

http://www.facebook.com/dialog/

followed by the name of the dialog and parameters.

To ask a user to post a story to their Wall, the Feed Dialog with required parameters is used :

http://www.facebook.com/dialog/feed?parameters

The following parameters are available :

  • app_id : required application’s identifier
  • redirect_uri : required URL to redirect to after the user clicks a button
  • from : optional ID or username
  • to : optional ID or username
  • message : optional (see Facebook policies) text to prefill the data field that the user will type in
  • link : link attachment
  • picture : url of picture
  • source : url of media file; if specified, picture will be ignored
  • name : name of the link
  • caption : caption of the link; will appear beneath the name
  • description : description of the link; will appear beneath the capation
  • properties : several JSON objects of key/value pairs; will appear in the post beneath the description; key=string; value=string or JSON object with keys text and href
  • actions : one JSON object with keys name and link; will appear next to the “Comment” and “Like” link under posts

To integrate a Facebook dialog in a webpage, the URL can be constructed on the server or client side. Helper methods are available in the form of Javascript, iOS and Android SDK’s. A Javascript Test Console is available to debug common methods. The tag ?ref=nf is added by the Facebook platform to the links.

Please visit My favorite artist at Leslie’s Artgallery to see a working example of a Facebook dialog.

Pagerank, Content Farms, Search Quality and Black Hat SEO

Last update : June 29, 2013
PageRank is a link analysis algorithm, named after Larry Page and used by the Google Internet search engine, that assigns a numerical weighting to each element of a hyperlinked set of documents. PageRank has been patented; the patent is assigned to Stanford University and exclusively licensed to Google.

The PageRank of a website is shown in the Google toolbar. The PageRank score was however removed by Google in October 2009 from the Webmaster Tools, because Google has been telling people for a long time that they shouldn’t focus on PageRank so much. PageRank is not an important metric for search engine optimisation.

Several providers continue to find the  PageRank data useful and offer free PageRank checkers, for instance at the website www.prchecker.info.

The term content farm is used to describe a company that employs large numbers of often freelance writers to generate large amounts of textual content which is specifically designed to satisfy algorithms for maximal retrieval by automated search engines. Their main goal is to generate advertising revenue through attracting reader page views. Critics allege that content farms provide relatively low quality content.

Search engines see content farms as a problem, as they tend to bring the user to less relevant and lower quality results of the search. On February 24th, 2011, Google announced that they were making a substantial change in their ranking algorithms to purge low-quality informations in the search results.

A black hat is the bad guy in a western movie. In computing slang it refers to a computer hacker. Black Hat search engine optimization is defined as techniques that are used to get higher search rankings in an unethical manner. Some of these techniques are keyword stuffing, invisible (hidden) text, cloaking, duplicate content and doorway pages.

Further informations about the Google search algorithms are available at the scriptol website.