About Gaurav Vichare

Hi , I am Gaurav : author of this blog , Software engineer and a Photoshop lover . You can connect with me on Facebook , cirlce me on Google or follow on Twitter

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 One should prevent access to admin interface  to public or… Read the rest

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

In this article, I will explain built in validator IS_IMAGE  and  IS_UPLOAD_FILENAME, also a custom validator. It is important to validate file uploaded on server to restrict malicious files like .py .php, .exe bat etc. Web2py provides 2 validators to… Read the rest

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 app_name/custom_download/employee_id or <a href="{{=URL('default', 'custom_download', args = employee_id)}}" download> example: www.example.com/default/custom_download/1 Consider following employee… Read the rest

How to password protect PDF file using Python?

We will use python library PyPDF2 to set password to pdf file. To install PyPDF2: sudo pip install pypdf2 1 sudo pip install pypdf2 We are using encrypt function of PyPDF2. encrypt(user_password, owner_password=None, use_128bit=True)
  • user_password  – The “user password” allows
Read the rest

Memory profiling in Python using memory_profiler

To install memory_profiler: sudo easy_install -U memory_profiler 1 sudo easy_install -U memory_profiler
  • Profile function/script: Add following line in script to import memory profiler: from memory_profiler import profile 1 from memory_profiler import profile Decorate the function you would like to profile
  • Read the rest

    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 command: sudo pip install cprofilev 1 sudo pip install cprofilev… Read the rest

    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 example, the space
    Read the rest

    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… Read the rest

    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… Read the rest