How to assign python variable to Javascript variable in web2py

You might be using following statement to assign python variable to javascript variable on older versions of web2py (<2.9.11), may be because of this question on stackoverflow: http://stackoverflow.com/questions/31216574/how-to-pass-data-from-python-to-javascript-in-web2py var javascript_array = {{=XML(response.json(array))}} 1 var javascript_array =  {{=XML(response.json(array))}} Above statement was working… Read the rest

How to change admin app url in web2py?

This question was asked here How to rename “/admin” to other URL in web2py? For all the web2py applications, web2py admin url is same, i. e. www.example.com/admin or 127.0.0.1:8000/admin. One should prevent access to admin interface  to public or … [Continue reading]

How to do file validation in web2py and write custom validator to validate files?

In this article, I will explain built in validator [crayon-59516fb8d1ab5196509856-i/]  and [crayon-59516fb8d1abb354233475-i/], also a custom validator. It is important to validate file uploaded on server to restrict malicious files like .py .php, … [Continue reading]

How to write custom download controller in web2py?

Suppose we have employee table with resume as uplaod field. And we want to download file on the basis of employee id. Download  url is like [crayon-59516fb8d1ee6714287647-i/] or [crayon-59516fb8d1eed360803964-i/] example: … [Continue reading]

How to password protect PDF file using Python?

We will use python library PyPDF2 to set password to pdf file. To install PyPDF2: [crayon-59516fb8d21f6518125560/] We are using encrypt function of PyPDF2. encrypt(user_password, owner_password=None, use_128bit=True) user_password  – The … [Continue reading]

Memory profiling in Python using memory_profiler

To install memory_profiler: [crayon-59516fb8d24b9083848507/] Profile function/script: Add following line in script to import memory profiler: [crayon-59516fb8d24bf570979456/] Decorate the function you would like to profile with … [Continue reading]

Time profiling in python using cProfile

In this article we will cover following points:  Profile single function Profile complete python script How to read .prof file Profile web2py application To install cprofile on ubuntu use following … [Continue reading]

How to measure performance of code ? – Basic methods

In this article, we will cover some very basic methods to calculate performance of script. In next article we will cover advance tool like cProfile and memory_profiler. What is profiling? Profiling is program analysis that measures, for … [Continue reading]

Size Contest (SPOJ Challenge problem 378)

Given the set of integers, find the sum of all positive integers in it. Solutions can be sent in any language supported by SPOJ except Whitespace. Input t – number of test cases [t < 1000] On each of next t lines given a integer N [-1000 <= … [Continue reading]

Factorial (SPOJ problem 11)

View problem on SPOJ The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the … [Continue reading]