Posts

Understanding filter, map and reduce

Most of the computation problems that I have faced in the past could easily be solved using a mix and match of filter, map and reduce operations . These operations could be performed on any set of objects that can be iterated. Filtering operation is one of the most fundamental operations that we perform more frequently than we think. In simple terms, we define a predicate and check if this predicate is true for each object in the set, iterating over them one by one. Whenever the predicate is true, we append the object to the output, otherwise we ignore. Consider grep tool as an example. The lines in the file(s) are iterable. If the current line is L, the the predicate is the question: "does L contain the pattern XYZ?". The output set has utmost as many elements as input set has. Mapping is the operation of producing an output for each element in the input, by performing a function on that input. Unlike filtering, which used a predicate to check, the map uses a function . The...

dhclient - Obtaining IP address dynamically

Whenever you want to obtain a dynamic IP address for your Linux/Unix machine from a DHCP server, you should use dhclient utility. Both DHCP request and responses are UDP requests. If you use a sniffer to identify the pattern of the request responses, the following is what you might see. The following was taken from dhclient running in FreeBSD 6.1. Len SrcIP SrcMACAddr DestIP DestMACAddr Protocol 342 0.0.0.0 00:0c:29:c1:13:81 255.255.255.255 ff:ff:ff:ff:ff:ff UDP 62 192.168.49.254 00:50:56:ef:75:a8 192.168.49.128 ff:ff:ff:ff:ff:ff ICMP ping request 342 192.168.49.254 00:50:56:ef:75:a8 192.168.49.128 00:0c:29:c1:13:81 UDP 60 192.168.49.128 00:0c:29:c1:13:81 ff:ff:ff:ff:ff:ff ARP request If you observe the source and destination (IP, MACAddr) patterns, it is easy to appreciate what happens. Here is what happens: A DHCP request is sent on the network. Both destination MACAddr and IPAddr are broadcast addresses. The DHCP server chooses and IP ...

VMWare Server - Free to download

A couple of weeks old news, but still thought worth sharing. For all those VMWare fans, the VMWare Server is now available free of cost for download. Earlier only VMWare player was available for download. Download and try it from here . You might wish to view all my previous posts on VMWare to know few more tricks.

Opening control panel from command prompt

How do you go to a tab in control panel directly from command prompt? Under the system32 directory, you will find a few *.cpl files. Running these files will take you directly to the control panel tab corresponding to them. For e.g. appwiz.cpl will take you to "Add/Remove Programs" tab in control panel. You can get a complete list of these files from this Microsoft Knowledge Base article . It saves a lot of time especially when you are running in a lesser privileged account and want to switch to admin account to install/uninstall programs.

A python script to monitor a process

Here is a python script to monitor a process' memory usage in Linux. This tool periodically prints how much of heap that has been used by the process so far. When you stop monitoring the script prints out a summary along with a text graph that will help you understand the trend. You can take a look at the script here . It might be useful and handy.

Debugging by printing

There are two ways to debug a program. One is to study the source code and try to understand what the program is doing and try to figure out what could have gone wrong. This is a kind of static debugging. Doing a dry run of the program is at times overkill. The other is to let the program run and print its state information. We can reason out what might have gone wrong from the collected information. Roughly speaking, state of a running program includes everything in the memory of the running program. But to make out what might have gone wrong, we only have to focus on what is really necessary. When I say "let the program print its state information," it could be the modified program with a lot of print statements. Or it could be a debugger attached to the running process and printing the state information. It definitely helps to learn a few ways to print the state information. An incomplete list of useful information on how to print in various systems. Language or Tool F...

Browsable HotSpot VM Source Code

With JDK source code having been made open source, I wanted to go through the source code to figure out how things have been done. I found the following two links to be useful. OpenGrok - A wicked fast source browser (and it lives upto its word!) OpenJDK Subversion Trunk OpenGrok link is too good if you would like to search something in the source code. If you have any better links, please do care to post in the comments.