Here are few snippets to make secure http requests using various python libraries. httplib2 import httplib2 link = "https://example.com h = httplib2.Http(".cache") r, content = h.request(link, "GET") another exmaple import httplib2 h = httplib2.Http(".cache") h.add_credentials('user', 'pass') r, content = h.request("https://api.github.com", "GET") print r['status'] print r['content-type'] Urllib2 Here is a simmilar example using urlib2 for comparison and lines of code. import urllib2 gh_url = 'https://example.com' auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(None, gh_url, 'user', 'password') opener = urllib2.
Brute-force approach Here I present a few approaches to deduce “minimum insertions” required to convert a string into a palindrome. The basic brute force approach is quite simple, given a string with length L, start comparing, the first character from left and the last character while scanning inwards. Here is a basic test for a palindrome. L = len(s) for i in range(L): if s[i] != s[L - i - 1]: return False,i,L-i -1 return True,0,0 The above code returns True if the string is a palindrome or returns False with mismatching indices.
Many useful algorithms are recursive in structure: to solve a given problem, they call themselves recursively one or more times to deal with closely related subproblems. These algorithms typically follow a divide-and-conquer approach: they break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem. The divide-and-conquer paradigm involves three steps at each level of the recursion:
Recently, I have been working on algorithms which needs elevation data as well as Land Cover data, with world coverage. Google has an excellent elevation API however free usage comes with a limit. While searching, I came across a dataset in geotiff format for landcover as well as a processed version of world elevation. Elevation data comes in various resolution (250m,500m,1km), landcover is 500m . So how do we read it ?