What I Learned Today

Mar 14

iptables dropping traffic

Here is a simple rule to drop traffic from a source using linux iptables

sudo iptables -A INPUT -s 192.168.247.1 -j DROP

to remove the rule at a later time, run:

sudo iptables -D INPUT -s 192.168.247.1 -j DROP

Eclipse ShellEd - nice bash/scripting editor

Jan 05

How to use the stand alone Flash player to run / debug apps in Flash Builder 4

By default, Flash Builder 4 will run or debug your applications in a browser.  This is just annoying.

Instead, you can make it open the apps inside the Flash Stand Alone Player. First, download the “Projector Content Debugger” (Adobe’s funny name for the Flash Player) for your OS from here: http://www.adobe.com/support/flashplayer/downloads.html. Install and run the program once to make sure your operating system knows where to find it.

Next go to the run or debug properties of your project and change the target path from /some/long/path/file.html to /some/long/path/file.swf

That’s all you need to do!

Dec 16

Emulate network latency using tc

Use this code:

PATH=$PATH:/sbin
lat=$1  ## desired bandwidth in megabits per sec
destip=$2  ## destination host to limit traffic to

if [[ -z $lat ]]
then
        lat=100
fi

if [[ -z $destip ]]
then
        echo "using default IP: 192.168.245.21"
        destip=192.168.245.21
fi

echo "note this may not work for VMs since it uses eth instead of peth0"

tc qdisc del dev eth0 root

tc qdisc add dev eth0 root handle 1: prio
tc qdisc add dev eth0 parent 1:3 handle 30: netem \
     delay ${lat}ms 
## add to end of previous line for distribution: 10ms distribution normal

## I think the line below is for bandwidth
#tc qdisc add dev eth0 parent 30:1 tbf rate 20kbit buffer 1600 limit 3000

tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 \
     match ip dst $destip/32 flowid 1:3

(Source: linuxfoundation.org)

Dec 10

Making a /proc entry with a kernel module

This is actually really simple. 

Just follow this example.

Oct 29

Watching process list in mysql

Run show processlist; in a mysql terminal to see all currently running commands.

Also useful:  show table status;

Oct 14

A4 paper size in latex

You need to be very careful when producing A4 PDFs because some packages will reset the paper size on you.  Thus you should define the page size AFTER importing all packages:

\documentclass[10pt,twocolumn,preprint,natbib,authoryear]{sigplanconf}
\bibpunct{[}{]}{,}{a}{}{;}


\usepackage{times}
\usepackage{subfigure}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{color}

% NOW force pdflatex to use A4 paper
\setlength{\pdfpagewidth}{210mm}
\setlength{\pdfpageheight}{297mm}

Oct 06

Latex font sizes

  1. \tiny
  2. \scriptsize
  3. \footnotesize
  4. \small
  5. \normalsize
  6. \large
  7. \Large
  8. \LARGE
  9. \huge
  10. \Huge

(Source: engineering.purdue.edu)

Sep 16

Simple Sed examples

Use sed to replace old strings with new strings in a file:

sed ‘s/old_string/new_string/’ file > newfile
mv newfile file 

or, if you are willing to live slightly dangerously, replace the file directly:

sed -i “” ‘s/old_string/new_string/’ file

If you want to replace all occurences of old_string, you need to use “g”

sed -i “” ‘g/old_string/new_string/’ file

Sep 03

Deleting a full table in MySQL

to delete all the data in a table, but not the table itself, run

truncate TABLE;

Resyncing DRBD

If you mount the LVM device under a DRBD volume instead of the DRBD one itself, then DRBD does not track any changes you make to the disk.  As a result, it will not synchronize those blocks to the secondary if you later switch back to using the drbd resources.

To force a full verification and resync, add a line like this to the resource config:

 syncer {
        verify-alg      md5;

Then run:

drbd adjust r0
drbdadm verify r0
## Watch the verify process in /proc/drbd
## if the oos:XXX value is greater than zero, blocks are out of sync
drbdadm disconnect r0
drbdadm connect r0

it will only force the resyncing of blocks if you disconnect/reconnect. 

Sep 02

How to increase Tomcat heap size

To adjust the tomcat heap size, edit $CATALINAHOME/bin/catalina.sh and add this line near the top:

export CATALINA_OPTS=”-Xms512m -Xmx512m”

then restart tomcat.  You can verify that it worked by running:

ps -ef | grep java

and looking for the -Xms line in the output

Sep 01

Filtering data in R

To get only the values in an R array which match some criteria, use code like this:

dataNonZero=data[data>0]

Aug 31

Resize an LVM disk and FS

Resize the partition using LVM:

sudo lvextend -L30G  /dev/mapper/VolGroup00-LogVol05

Unmount the partition (hopefully it isn’t the root!):

sudo umount /dev/mapper/VolGroup00-LogVol05

Check the FS for errors

sudo e2fsck -f /dev/mapper/VolGroup00-LogVol05

Adjust the FS to the new size

sudo resize2fs /dev/mapper/VolGroup00-LogVol05

Remount the disk

sudo mount /dev/mapper/VolGroup00-LogVol05 /home

Aug 27

List all modules on linux system

Run: cat /proc/modules or lsmod