Block IP’s through iptables

WARNING: The following code will REPLACE your existing firewall rules as it uses iptables-restore in order to add hundreds of individual ip rules into the INPUT chain very fast.

rm -f /root/listed_ip_*
wget -q -c --no-cache -P /root/ --output-document=/root/
unzip /root/ > /dev/null

echo "*filter" >/tmp/iptables-save
echo ":INPUT ACCEPT [0:0]" >>/tmp/iptables-save
echo ":FORWARD ACCEPT [0:0]" >>/tmp/iptables-save
echo ":OUTPUT ACCEPT [0:0]" >>/tmp/iptables-save
IPS=$(grep -Ev "^#" $BLOCKDB)
for i in $IPS
echo "-A INPUT -s $i/32 -p tcp -m tcp --dport 80 -j DROP" >>/tmp/iptables-save
echo "COMMIT" >>/tmp/iptables-save
cat /tmp/iptables-save | iptables-restore

How to check packet loss for VOIP purposes

Yesterday I had some problems with the VOIP connection. I heard my party very well but he could barely hear me.
Normal run of mtr to the other host showed no packet loss but I was able to pinpoint the packet loss to the other party with
mtr -n -s 200 -i 0.02 [ip-address]
(you need to be root)
which sends 50 packets/seconds 200 bytes/packet which pretty much emulates the rtp stream.

SPL-C ERROR – Please use the proper driver on Samsung CLP-310N printer

If you get this error written on the test page when using Ubuntu or any other Linux distribution, you should install the Samsung Unified Driver. I’ve followed the tutorial on point II.c and then I’ve added the network printer as lpd:///PASSTHRU with Make and Model “Samsung CLP-310 Series (SPL-C)” (NOT Samsung CLP-310 Foomatic/foo2qpdl)

How to programmatically dump the threads list of a running java process in bash

It seems that jdb cannot accept commands from command line, so we must use expect.
I created the following expect script dumpthreads
You can use it like:
dumpthreads java_process_pid

set pid [lindex $argv 0];
spawn jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=$pid;
expect ">";
send "threads\n";
expect ">";
send "quit\n";

Midnight commander does not save the settings in Ubuntu

Today I encountered a strange problem with Midnight Commander 4.6.2 in Ubuntu. I wanted to change the default Ubuntu setting to use the internal edit. I actually like the mc internal editor and I want to use it. The problem was that the setting was not saved when I chosed “Save setup” even if a message “Setup saved to ~/.mc/ini” appeared. There was no ~/.mc folder. After I did
mkdir ~/.mc
everything worked as expected.
This seems to be a bug in mc.

Emtec S800 board picture

Here is a picture of the internal board of my newly aquired Emtec S800 PVR. It works on Linux but Emtec was not so kind to provide the sources of the PVR application (there are some sources of an alternative OEM – Ellion available on the net). I needed to open the box to put a resistor at the internal fan because it was too noisy.

How to convert DVD iso to avi using mplayer

Here is a python script to convert an .iso of a DVD to avi and to encode it using mpeg4. It is a slightly modified version of the script found at to work with newer versions of mplayer/mencoder.

Later edit:
It seems that mplayer/mencoder know to play/convert .iso files directly so we can do:
mencoder in.iso -o /dev/null -ovc xvid -xvidencopts pass=1:bitrate=800:threads=2 -oac copy
mencoder in.iso -o out.mpeg -ovc xvid -xvidencopts pass=2:bitrate=800:threads=2 -oac copy

How to convince the SmartGWT ListGrid to automatically fetch from the server only the data it displays

Since I was looking all over the net how to do this and I only found pieces of information, here is an example:

public class OperationsGrid extends ListGrid{
TreeGridField accNoField = new TreeGridField(“accountNo”, 150);
TreeGridField commentField = new TreeGridField(“comment”, 150);


public class OperationsDS extends DataSource{
static OperationsDS instance = null;
static OperationsDS getInstance(){
if(instance == null){
instance = new OperationsDS();
return instance;


DataSourceTextField noField = new DataSourceTextField(“accountNo”, “Account Number”, 128);
DataSourceTextField commentField = new DataSourceTextField(“comment”, “Comment”, 128);


protected Object transformRequest(DSRequest dsRequest){
String url = null;

return super.transformRequest(dsRequest);
protected void transformResponse(DSResponse response, DSRequest request,
Object data) {
DSOperationType operationType = request.getOperationType();

if (operationType == DSOperationType.FETCH) {
JSONArray info = XMLTools.selectObjects(data, “/response/resultInfo/numTotalRows”);
Integer total = (int)Math.round(info.get(0).isNumber().doubleValue());

info = XMLTools.selectObjects(data, “/response/resultInfo/startRow”);
Integer start = (int)Math.round(info.get(0).isNumber().doubleValue());

info = XMLTools.selectObjects(data, “/response/resultInfo/endRow”);
Integer end = (int)Math.round(info.get(0).isNumber().doubleValue());

if(total != null)
if(start != null)
if(end != null)
} else {
super.transformResponse(response, request, data);


In this example the server outputs in JSON format and returns the the current start row, current end row and total number of rows in response/resultInfo.
Basically you need to override transformRequest and transformResponse. In transformRequest you should add the start and end row to the requestURL and in transformResponse you should set the startRow, endRow, and totalRows, provided that you receive this information from your server. Also don’t forget to setAutoFetchData(true) on the grid.

Hope this helps somebody.

MySQL Java SQLException error codes enum

Because I had this problem and I could not find a list of MySQL error codes on the Internet, I’ve decided to implement my own MySQL error codes enum. It is based on MySQL 5.1.35 sources, include/mysqld_ername.h file.
Now I can do something like this:

catch (SQLException e) {
if(e.getErrorCode() == MySQLExceptionCode.ER_DUP_ENTRY.getErrorCode()){
} else

You can find the java file here.