Category: python
-
pylibmc – Kestrel Queue Client – Simple Test using Memcache Protocol
Installation pylibmc is a great Python client for memcached written in C. sudo pip install pylibmc Mini Benchmark cat > kestrel-benchmark.py
-
beanstalkc – beanstalkd queue – python client library
Installation beanstalkc is a c-based python client library for beanstalkd. Installation using PIP Installer The library and dependencies can be easily install using the pip installer sudo pip install PyYAML sudo pip install beanstalkc Installation directly from Github This can useful if the pip installed library is too old and required new functionality/bug fixes are…
-
Apache Cassandra CQL3 – Installation and Tests using Python
Installation using PIP # install python-pip sudo apt-get install -y python-pip # install cql driver sudo pip install cql Manual Installation from the Sources # download path mkdir -p ~/build/python-cql cd ~/build/python-cql # download git clone https://github.com/pcmanus/python-cql cd python-cql sudo python setup.py install Query Example # create and move to diretory mkdir -p ~/build/python-cql cd…
-
pycassa – Gettting started with Apache Cassandra using python
Install easy_install and pip # install easy_install sudo apt-get install -y python-setuptools # install python-pip sudo apt-get install -y python-pip Install pycassa sudo pip install pycassa Test pycassa cat > cassandra_test.py
-
Python – pyinotify – Observe Files and Directories – open, close, delete
sudo pip install pyinotify Example a@a:~$ vim notify_test.py import pyinotify class MyEventHandler(pyinotify.ProcessEvent): def process_IN_ACCESS(self, event): print “ACCESS event:”, event.pathname def process_IN_ATTRIB(self, event): print “ATTRIB event:”, event.pathname def process_IN_CLOSE_NOWRITE(self, event): print “CLOSE_NOWRITE event:”, event.pathname def process_IN_CLOSE_WRITE(self, event): print “CLOSE_WRITE event:”, event.pathname def process_IN_CREATE(self, event): print “CREATE event:”, event.pathname def process_IN_DELETE(self, event): print “DELETE event:”, event.pathname def…
-
Selenium – Solving the “Can’t load the profile” Exception
I had a wierd “Can’t load the profile” exception in a selenium script that simply would go away. Turns out the reason is a version problem between the selenium server and python library Exception Error a@a:/home/dev/code$ python selenium_test.py Traceback (most recent call last): File “/home/dev/code/selenium_test.py”, line 905, in main() File “/home/dev/code/selenium_test.py”, line 56, in main…
-
Linux – Install Eclipse IDE
The easiest way to install Eclipse in Ubuntu is through the standard repository sudo apt-get install -y eclipse Unfortunately, this install an outdated version. Currently the version 3.8.0 gets installed, although the latest stable version is 4.2.1. The eclipse team does have a Debian PPA as well, ppa:eclipse-team/debian-package. Adding this PPA doesn’t change anything and…
-
Python – GeoIP City and Country using MaxMind
PyGeoIP is a pure python GeoIP API based on MaxMind’s C-based Python API. The python implementation is ported from the PHP GeoIP API written by Jim Winstead and Hans Lellelid. Option 1: Installation using PIP sudo pip install pygeoip Option 2: Download and Install from Github repository An alternative to pip is to download the…
-
Python – Timing Decoration
# -*- coding: utf-8 -*- from __future__ import print_function import time import sys from time import strftime import inspect import traceback # http://www.siafoo.net/article/68 # being nice to subsequent decorator calls or chains, otherwise losing the name of the function def timing(result=True, params=True, start=False): def timing_decorator(f): def wrapper(*args, **kw): t1 = time.time() function_result = None try:…
-
Python – Clustering Text in Python
# -*- coding: utf-8 -*- “”” Source: http://stackoverflow.com/questions/1789254/clustering-text-in-python See also: http://docs.scipy.org/doc/scipy/reference/cluster.html http://hackmap.blogspot.com/2007/09/k-means-clustering-in-scipy.html “”” import sys from math import log, sqrt from itertools import combinations def cosine_distance(a, b): cos = 0.0 a_tfidf = a[“tfidf”] for token, tfidf in b[“tfidf”].iteritems(): if token in a_tfidf: cos += tfidf * a_tfidf[token] return cos def normalize(features): norm = 1.0 /…