merge two sorted arrays in python

Here is a quick code snippet to merge two sorted arrays in python merged = [] l = 0 r = 0 for i in range(len(a)+len(b) ): lval = None rval = None if l < len(a): lval = a[l] if r < len(b): rval = b[r] if (lval < rval and rval and lval) or rval == None: merged.append(lval) l+=1 elif (lval >= rval and rval and lval)or lval == None: merged.
Read more →

Normalizing Ranges of Numbers

Range Normalization is a normalization technique that allows you to map a number to a specific range. Lets say that we have a data set where the values are in a range of 1 to 10, however we wish to normalise it to a range between 0 and 5 Mathematically speaking the equation comes down to translated to Python class Normaliser: def __init__(self,dH,dL,nH,nL): self.dH = dH self.dL = dL self.nH = nH self.
Read more →

how to make a web crawler in python

Here is a very simple web crawler in python import sys, thread, Queue, re, urllib, urlparse, time, os, sys dupcheck = set() q = Queue.Queue(100) q.put("http://www.varunpant.com") def queueURLs(html, origLink): for url in re.findall(''']+href="'["']''', html, re.I): link = url.split("#", 1)[0] if url.startswith("http") else '{uri.scheme}://{uri.netloc}'.format(uri=urlparse.urlparse(origLink)) + url.split("#", 1)[0] if link in dupcheck: continue dupcheck.add(link) if len(dupcheck) > 99999: dupcheck.clear() q.put(link) def getHTML(link): try: html = urllib.urlopen(link).read() print link # open(str(time.time()) + ".html", "w").
Read more →

How to configure Apache mod_wsgi

I am a big fan and user of python. one of the most popular ways to create quick web app in python is via using mod wsgi. The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.
Read more →

Serve the contents of any directory with Python’s SimpleHTTPServer

Generally, when I am in a middle of prototyping a concept or in a need of quickly executing Ajax requests or using browser features which would need the page to be hosted on a web server, I use Python’s SimpleHTTPServer module. Python’s SimpleHTTPServer is a great way of serve the contents of the current directory,all one needs to do is change directory and execute a command which will expose all contents as if they were hosted in a web page.
Read more →