Category: programming

Untyped Constants in Golang

Golang is extremely explicit with types. It supports constants of a type. But how about a const 2 or hello. What type would they assume!? Go solved this problem with untyped constants. Untyped means: A constant’s type depends on the type of assignee variable. The assignee’s type must have compatibility to hold constant’s value. Example…

Design Internals of UNIX Non Blocking Sockets

Fundamental of asynchronous programming: Non Blocking Sockets Why async socket programming An application can create thousands of sockets but creating a thread per socket becomes infeasible for a large number (e.g. 100k sockets) An async framework consists non-blocking sockets and an event loop * The kernel allows applications to seek for an event * Application…

Golang Essentials for C & C++ Developers: Part I

I have been a C/C++ developer for more than a decade and now getting a chance to work in Go. There are many past references of C, C++, and Python to learn the language quickly. but there are some new syntax that appear unfamiliar. We share such language specific nuances, used widely in production quality…

Linux Device Driver Development: Block Device Driver

It is my very first interaction with Linux kernel at device driver level. My objective is to develop a block device driver, very simple, that just forward I/O requests to a virtual device. This post explains my observations limited to attacking the problem. Block v/s Character Device Linux support block and character device drivers. Only…

Dissecting Python List allocator (CPython)

List is one of the most frequently used data structure in Python applications. The code for Python list object allocator is present in Python-2.7.5/Objects/listobject.c. Python allocates list objects in heap and uses underlying malloc based APIs. List is a container of Python object references. In plain C terminology. it is a dynamic array of pointers.…

Openstack swift: EADDRNOTAVAIL error

Problem swift-bench keeps EADDRNOTAVAIL error with a highly concurrency setting and multiple swift-bench clients. Setup Ubuntu 13, Swift single machine installation (refer SAIO), swift-client runs local with no-proxy mode. Solution EADDRNOTAVAIL stands for either unavailability of ephemeral ports and a known kernel bug. Check your range of ports: $cat /proc/sys/net/ipv4/ip_local_port_range swift-bench in no-proxy mode uses…

Best Python memcache client: Python-memcached v/s Pylibmc

Recently, I tried to access memcached server on local and remote setup in a Python application. I am sharing my experience with two of most popular clients. Python-memcached The first choice was a pure  Python solution to access memcached, that is python-memcached. It is a simple to install, understand and use solution. It do not…

Parenthesize an expression in Python

    def pref(op):         print “called with op”, op         ret = -1         if op == ‘+’:             print “matched +”             ret = 1         if op == ‘-‘:             print “matched -”             ret = 2         if op…

Pylucene- Part III: Hightlighting in Search

The search result can be customized to highlight the phrases that contain the requested keyword. The following code uses “Highlighter” class from Pylucene. We emit result in HTML formatted syntax. from lucene import \             QueryParser, IndexSearcher, IndexReader, StandardAnalyzer, \         TermPositionVector, SimpleFSDirectory, File, SimpleSpanFragmenter, Highlighter, \     QueryScorer, StringReader, SimpleHTMLFormatter, \             VERSION, initVM,…