Category Archives: Uncategorized

Regex Expression: |

Syntax: pattern1|pattern2

Search for both of them, if either is found it is true.


 re.findall("(the|top|coder)", "Marius is one of the topcoders.")
['the', 'top', 'coder']

Regex Expression: ^

Syntax: ^pattern

This would return True only if pattern is at the starting of the given text.


re.findall("^http", "")

Regex Expression: $

Syntax: pattern$

Returns True if pattern is in the end of given text


 re.findall("in$", "")

Regular Expression: .

Syntax: pattern.

Use to match a single character.

 >>> re.findall("htt.", "")

>>> re.findall("ht..", "")

Regular Expression: { }

Syntax: Pattern{number of times pattern must repeat continuously}

It multiplies the pattern number of times given within the braces and then search for it in the given text. In the following example it multiplies ‘t’ twice thus pattern to be searched is ‘tt’


>>>re.findall("t{2}", "")

Regular Expression: { ,}

Syntax: Pattern{n,}

Matches n or more occurrences of preceding expression.


>>> re.findall("t{2}", ""

Basics of Regular Expressions in Python

The Future of Gaming Technology

We have the responsibility to develop something similar for generations to come -:)

Xpath in Python using lxml

def extract_html(xpath, html):
# This method takes xpath and html content as input 
# and returns a list of tags and corresponding content seperated by ':::'
	from lxml import etree
	tree = etree.HTML(html)
	r = tree.xpath(xpath)
	for x in r:
		pattern = x.tag+":::"+x.text

LINUX Basic Commands

Count a string in many files without opening them

cat * | grep -c string

Count the number of files in a directory

ls -l . | egrep -c ‘^-‘

Compressing a file in tar.bz2 format

tar jcvf .tar.bz2 dir1 dir2 file1 file2 …

Decompressing a file in tar.bz2 format

tar -xjvf example.tar.bz2

All files and directory would be compressed in the same folder

Counting Number of files in a folder

ls | wc -l


What exactly is bash?


Installing Cisco Any Connect on Ubuntu 11.04 64bit

Note: This method don’t work for Ubuntu 11.10 x64 and I have completely no idea what method would. If you find some blog article stating a working nice method for Ubuntu 11.10 x64, please drop the link in the comments area. 10x

Who should read?

If you have been googling/binging how to do this from a long time and you realized most of the blog articles talk about 32 bit edition. Moreover, the one who does talk about 64 bit edition are stating a very complicated procedure.


First of all you would need to download Cisco AnyConnect VPN Client from your company’s portal. It would first try to auto-install and finally a manual Installation message would be displayed with the download link. Now you have to download file by clicking on this Linux i386 link

Step 2:

The problem is the file downloaded in step 1 wont run on you machine because you got 64bit while the setup is for 32bit. So, all you need to do now make you machine support 32bit installations. And that can be done writing this command in your terminal:

sudo apt-get install ia32-libs lib32nss-mdns

Step 3:

Bash your or install this .sh file whatever way you feel like doing it.

sudo bash

Done, enjoy!!

LXML HTML Parsing Usage Example

from lxml.html import fromstring

for x in range(0,1000):
	mySearchTree = fromstring(open(str(x)).read())
	f.write("Product Name: ")

	for a in mySearchTree.cssselect('tr input'):
		f.write(a.get('value')) #product_name
	for a in mySearchTree.cssselect('h3 a'):
		f.write(a.get('href')) #url

Read all lines of file as array

From file as a parameter in argument

keywords = open(sys.argv[1]).readlines()

Empty Inbox

import imaplib
for x in range (0,10000):
	box = imaplib.IMAP4_SSL('', 993)
	print x, ":Connected"
	print "Logged In"'Inbox')
	print "Inbox Selected"
	for num in range(1,100):, '+FLAGS', '\\Deleted')
	print "100 mail selected"
print "I think all mails have been deleted"

delete all email

import imaplib
box = imaplib.IMAP4_SSL('', 993)
typ, data =, 'ALL')
for num in data[0].split():, '+FLAGS', '\\Deleted')

Logging Traceback

import traceback
import sys
		print x
	except Exception, ex:
		raise NameError
except Exception, er:
	print x