Simulating dropped packets (aka crappy internets) with iptables

Disclaimer #1

I am not an iptables expert. This tip will work best on your local linux development box where you probably have no iptables rules setup. Do not play around with this shit on production machines, unless you know what you are doing. Speak with your friendly sysadmins before doing this on any machine for which they feel responsible.

Disclaimer #2

According to this tip, do not drop more than 14% of the packets otherwise you will cause all tcp sockets to stall.


Why would you want to do this? sometimes people (aka customers) might complain that your super-duper application that they use via the Internets (aka a series of tubes) is slow. One reason could be a dodgy internet connection and/or packet loss. See this great article about how packet-loss affects web applications and how to drop packets with a microwave oven.

And now finally…

To simulate a dropped packets with iptables, you can use the following commands (as root):

# for randomly dropping 10% of incoming packets:
iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP

# and for dropping 10% of outgoing packets:
iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Once done, you can use the following for removing these packet-drops:

# for the incoming packets:
iptables -D INPUT -m statistic --mode random --probability 0.1 -j DROP

# and for the outgoing packets
iptables -D OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Auto Install the SUN JDK on Linux

Sometimes (yes it does happen), you need to install the JDK from SUN automatically (without having to answer yes/no to the license). Why? For example in a Kick Start script to auto-install the JDK.

And so to do this, here a bash & perl script for this exact purpose. This script works only with the .bin install package that you download from SUN’s website.



echo $1

# just spew out the agreement
perl -p -i -e 's/^more/cat/g' $1

# set the 'agreed' value for jdk 1.5
perl -p -i -e 's/\s+agreed=$/agreed=1/g' $1

# set the agree value for jdk 1.6
perl -p -i -e 's/`agree`/yes/g' $1

# do not call the register_jdk method
perl -p -i -e 's/\s+register_JDK/#register_JDK/g' $1

# and now run the installation
bash $1

How to

Create a new script file called containing the above script. and run it as follows:

$ cd /install/to/directory
$ /my/downloads/jdk-6u16-linux-x64.bin

Ruby FIX Message Viewer 1.0

Today I released my Ruby FIX Message Viewer 1.0. This is a command line based FIX message viewer programmed in Ruby. I made it command line because most, if not all, of the FIX logs that I have at work are on a server when I have only ssh access. Rather than copy them over and use some GUI tools, I find it quicker just to use this tool on the server.

scp2here: scp command to here

I usually need to scp stuff from/over-to servers on a regular basis. And here is a function in .bashrc that I use:

#function to get the scp path to here
function scp2here


    if [ ! -z "$1" ]

    echo $output

This function prints out the scp command argument to copy a file/directory to a location.


Then to copy something to a target server where I have scp2here, I can cd to the target directory and do this: ~ $ scp2here
... ~ $ scp bigassfile.txt

Or if I want to copy a file from a location that has scp2here: ~ $ scp2here somefile.txt
... ~ $ scp .


How to import java projects with eclipse JDT

During the coding of my Bulk Import Plugin, I had the needs to import java projects into a workspace via code. Via Eclipse’s API to be precise. After reading the code of what happens when you import a project, here is the critical bit of code:

Runnable runnable = new Runnable() {
    public void run() {
    try {
        IPath projectDotProjectFile = new Path(pathToMyProjectDir+ "/.project");
            IProjectDescription projectDescription =
            IProject project = workspace.getRoot().
            JavaCapabilityConfigurationPage.createProject(project, projectDescription
                .getLocationURI(), progressMonitor);
        catch(CoreException e) {

// and now get the workbench to do the work
final IWorkbench workbench = PlatformUI.getWorkbench();

Eclipse Bulk Import V 1.0

Today I released the V 1.0 of my Eclipse Bulk Import plugin. The source is also available at github.

I created this plugin because at work we have too many eclipse projects (over 200). And sometimes the workspaces get corrupt. Using this plugin, I can save the locations of the current projects in my workspace. And I can also import those projects with one-click. Check out the movie of it in action. This plugin saves me quite a bit of time in creating new workspaces (and then importing over 200 projects), and recovering from corrupted workspaces.

Certified “Works on my machine” :) . If you try it out let me know how it goes.

Using Dropbox for Eclipse Projects

I have a bunch of java projects that I like to work on when I have some free time. Only issue is that this “free time” is from different locations, different computers and different Operating Systems. And since I don’t have a lot of “free time”, its hard for me to setup svn, builds etc. I needed a quicker solution: Dropbox

Of course this wont work out of the box. The trick is to make the eclipse projects self contained. In other words, they must not reference any libs/jars/resources outside their own directory. Most self respecting eclipse users would know how to do this. Then the entire project can be synced with Dropbox.

As my project folders will be synced to anywhere I install Dropbox. All I need is a working eclipse and i can start coding. Yay!