Skip to main content

Posts

Showing posts from 2012

Google App Engine with Python 2.7

webapp2 framework   webapp2 is a simple web application framework included in App Engine. It is already installed in the App Engine environment and in the SDK. webapp2 framework has two parts:     one or more RequestHandler classes that process requests and build responses     a WSGIApplication instance that routes incoming requests to handlers based on the  url Consider the below given code import webapp2 class MainPage(webapp2.RequestHandler):     def get(self):         self.response.headers['Content-Type'] = 'text/plain'         self.response.out.write('Hello, webapp World!') app = webapp2.WSGIApplication([('/', MainPage)],                               debug=True) Here MainPage is the request handler map...

Google App Engine

Google App Engine lets you to run web applications on google's infrastructure without any cost. We dont need to maintain any server for our application here. App engine supports application written in several languages. The three important environments for app engine are Java runtime environment , Python runtime environment , Go runtime environment . The main features of  Google App Engine are   Dynamic web serving, with full support for common web technologies  Persistent storage with queries, sorting and transaction Automatic scaling and load balancing APIs for authenticating users and sending email using Google Accounts A fully featured local development environment that simulates Google App Engine on your compute Task queues for performing work outside of the scope of a web request Scheduled tasks for triggering events at specified times and regular intervals The Python Runtime Environment   Here we are going to discuss how to develop and uplo...

Lisp Interpreter in Javascript

Let us discuss the basic concept behind the lisp interpreter using javascript. Those who are new to javascript can go throw some  basics and the complete code of our interpreter program given  here . Let us go through each functions one by one. Function Env: This function defines the environment for a variable used in execution. The function find(variable) in line number 4  will find the correct environment of execution for the variable. If the variable is defined in the existing environment, the current environment is considered, else the function is called recursively to the outer environments untill the correct environment is found. This property is known as lexical scoping. Function addGlobal: This functions defines the global environment. Basic math functions such as '+', '*' etc are defined in the global environment. Other than these 21 basic functions, some other math functions such as sin,cos,log etc are also included in the global environment as shown belo...

Lisp Interpreter in Python

Here we are going to discuss about the lisp interpreter written in python by  Peter Norvig . The complete code is given  here . Purpose of a language interpreter   A language interpreter has two main divisions termed as parsing and execution. Parsing: A parser programme converts the input programme into an internal representation after analyzing the syntactic correctness of the programme. In most of the interpreters the internal representation will be a tree like structure which resembles with the nesting structures of the input programme. Consider the example given below, he output after the parser programme will be as followes.            >>> program = "(begin (define r 3) (* 3.141592653 (* r r)))"            >>> parse(program)            ['begin', ['define', 'r', 3], ['*', 3.141592653, ['*', 'r', '...

Functional Programming in Scala: Getting Started

Functional Programming is becoming increasingly popular because it offers an attractive method for exploiting parallelism for multicore and cloud computing. As the name indicates functional programming focuses on the functions. A functional programming language is one which does not have mutable variables, assignments, loops, and other imperative control structures. Some of the important functional programming languages are   Lisp, Scheme, Racket, Clojure SML, Ocaml, F# Haskell (full language) Scala Smalltalk, Ruby (!) REPL(Read-Eval-Print)   An interactive shell or REPL lets one write expressions and responds with their value. Scala REPL can be started by typing >scala For example; >scala 23+34 57 >scala def length = 10   length: Int >scala def breadth = 20 breadth: Int >scala length*breadth 200 Parameters and Return type in def Definition may consist of parameters. Sometimes return types are also specified in the definition....

Abstraction Using Higher Order Procedures

Procedures are, in effect, abstractions that describe compound operations on numbers independent of the particular numbers. Yet even in numerical processing we will be severely limited in our ability to create abstractions if we are restricted to procedures whose parameters must be numbers. Often the same programming pattern will be used with a number of different procedures. To express such patterns as concepts, we will need to construct procedures that can accept procedures as arguments or return procedures as values. Procedures as arguments Procedures are often used as the arguments of an another procedure. This provides a higher level of abstraction in programming. For example consider a procedure to find out the sum of squares of numbers between a range. The procedures inc and square are used as the arguments of the procedure sum, which is generalised as follows.                 (define (inc...

Elements of Programming in Scheme

A powerful programming language provides a framework to interpret our ideas of processes. It generally combines small procedures to complex ones. Usually there are three steps to accomplish this. primitive expressions , which represent the simplest entities the language is concerned with, means of combination , by which compound elements are built from simpler ones, and means of abstraction , by which compound elements can be named and manipulated as units. Some very basic ideas in manipulating with the data are given below. Expressions   A very simple expression is a number. Simple expressions are combined to form complex ones. For example:                   (+ 2  3  4) is an expression where + is the operation and 2,3,4 are the oparents. The expression can be made more complex by combining simple expressions as given below:              ...

Unit Testing

Unit tests are typically written and run by software developers to ensure that code meets its design and behaves as intended. It is important to write the unit test code early and update it as the application code changes. Unit testing is very important in all phases of the development cycle. Unit Testing: Benefits Finds Problems easily              In test-driven development, unit tests are created before the code itself             is written. When the tests pass, that code is considered complete. Facilitates change             Unit testing method allows the program to change in the future and             make sure that it works properly. Simplifies integration             By testing the parts of a program first and then testing the sum of its...

Python : Basic Conventions

While we write any code, the predominant matter to be noticed is that the readability of our code is very much important. Even if our code is logically correct, it is not considered to be perfect if it is difficult to understand. It is said that our code is read much more often than its written. So here are some very basic conventions to be followed while writing any python program. Python Enhancement Proposal(PEP)  8 describes the style guide for python code. Reading The Zen of Python will be interesting as well as informative before you move on. Indentation Use four spaces per each indentation level Preferably use only white spaces for indentation and never mix up tabs and spaces Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent. Limit the maximum number of characters to be 79 in a line.         ...