March 2011
2 posts
2 tags
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
3 tags
Eclipse ShellEd - nice bash/scripting editor →
January 2011
1 post
2 tags
How to use the stand alone Flash player to run /...
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...
December 2010
2 posts
3 tags
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...
2 tags
Making a /proc entry with a kernel module
This is actually really simple.
Just follow this example.
October 2010
3 posts
1 tag
Watching process list in mysql
Run show processlist; in a mysql terminal to see all currently running commands.
Also useful: show table status;
1 tag
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...
1 tag
Latex font sizes
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
September 2010
5 posts
1 tag
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 “”...
1 tag
Deleting a full table in MySQL
to delete all the data in a table, but not the table itself, run
truncate TABLE;
2 tags
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:
...
2 tags
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
1 tag
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]
August 2010
3 posts
4 tags
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...
1 tag
List all modules on linux system
Run: cat /proc/modules or lsmod
1 tag
nfs mount error
If when trying to mount a remote directory using NFS you get this error:
[root@localhost ~]# mount -t nfs 192.168.245.21:/home/CloudNet /mnt
mount: wrong fs type, bad option, bad superblock on 192.168.245.21:/home/CloudNet,…
Then it means you are missing an important nfs package! Run sudo yum install nfs-utils and it should be fixed.
June 2010
2 posts
1 tag
Add page numbers in latex
Simply add this at the top of your document (underneath use packages)
\pagenumbering{arabic}
3 tags
Bind Address in Use error
I was getting this error when trying to start tomcat:
java.net.BindException: Address already in use:8080 LifecycleException: Protocol handler initialization failed: java.net.BindException: Address already in use:8080
To fix this, I followed these instructions:
Find the zombie process holding the port open: netstat -anp | grep 8080
use kill -9 to stop it
May 2010
1 post
2 tags
Using TC to limit bandwidth
This code will limit the bandwidth between the source host and the destination IP set.
bw=$1 ## desired bandwidth in megabits per sec
destip=$2 ## destination host to limit traffic to
tc qdisc del dev peth0 root
tc qdisc add dev peth0 root handle 1: htb
tc class add dev peth0 parent 1: classid 1:1 htb rate ${bw}mbit ceil ${bw}mbit
tc class add dev peth0 parent 1:1 classid 1:11 htb rate...
April 2010
3 posts
3 tags
Quickly Counting 1 bits on 64bit platforms
Bits counting
One of the most important operations in bit set arithmetic is counting number of 1 bits. BM uses integer-based bitvectors. It means that each bitvector uses arrays of integers as a minimal building block for bit sets. The default method used in BM splits each integer into 4 characters and looks up a table containing bits count. This linear approach can be improved by using 16-bit...
2 tags
Fixing FMDB crashes on iPhone
I was trying to use the FMDB wrapper for sqlite in a simple iphone app, but I found that I would get a crash whenever I created a DB in one function and then use it again in a later one. I eventually realized that the memory region that was supposed to be holding my DB was being freed up without me knowing it. To fix the problem, I edited the FMDatabase.m file as follows:
+...
1 tag
Trouble adding CoreData library to existing iPhone...
I was trying to get core data to work inside an app that I had already started, but I was getting errors like:
/…/Classes/MyAppAppDelegate.h:12: error: expected specifier-qualifier-list before ‘NSManagedObjectModel’
It seemed like it was not including the CoreData library, but I had added the framework—what else did I need to do?
It turns out, that you also have to edit...
January 2010
3 posts
2 tags
Distributing Compilation with distcc
Distcc has a client and a server. To build the client, you need python-devel package.
On server nodes:
distccd —daemon —allow 192.168.246.102
On client:
create ~/.distcc/hosts file with IP addresses of all server nodes
run distcc —show-hosts to verify it has a list
use make -j8 CC=distcc to build something
I had to build the distcc client/server code from source on a...
2 tags
Recovering Crashed Mysql tables
If you see error messages in /var/log/mysql.log about a table being crashed, log into the mysql console and run: recover table;
Pretty easy!
For tpcw, you can use this script to recover everything:
repair table item; repair table country; repair table author; repair table customer; repair table orders; repair table order_line; repair table cc_xacts; repair table address; repair...
5 tags
Resizing Ext3 Partitions
These were the basic steps I had to go through to resize a partition inside of a DRBD disk device. I think a similar procedure would be needed to resize the disk inside a file based disk image.
Check the partition info using parted’s “print” command
Number Start End Size Type File system Flags 1 32.3kB 107MB 107MB primary ext3 2 ...
December 2009
5 posts
1 tag
Passing Variables to awk in a script
To pass bash variables to an awk script, use -v to turn them into awk variables first:
awk -v var=$var '{print $1 + var}'
1 tag
All about dd →
3 tags
Profiling C Code with Gprof
Use Gnu Prof to find out how much CPU time is spent in each function and how often they are called.
First, compile the code with the -pg flag
Then, run the program as usual. It will produce a gmon.out file
Run gprof execname to view the output statistics (probably want to redirect or use less)
1 tag
Averaging all columns with AWK
From here
Very handy for processing data files:
awk '{for(i=1; i<=NF; i++){sum[i]+=$i}} END {for(i=1; i<=NF; i++){printf sum[i]/NR "\t"}}' file
1 tag
Growl message popups
To make a “growl” message appear, first install the growlnotify app from the extras folder in the growl distribution. Then you can run:
ssh soporifix.cs.umass.edu “echo test message | /usr/local/bin/growlnotify -s”
to make a sticky growl notification appear. Nice for alerts that an experiment is done!
September 2009
4 posts
2 tags
Slow SSH on VMs
When having very slow ssh connections between VMs, it may be because of DNS resolution. I tried disabling DNS lookups in the sshd config file, but it didn’t help. Instead, I ended up just manually adding the relevant IP/hostnames to /etc/hosts.
2 tags
TPC-W database.properties problems
Tomcat was crashing everytime I tried to access the TPC-W site. The catalina.out file listed an error saying it couldn’t find the database.properties file. This was very strange because sometimes the site worked fine, and other times it would crash.
To fix this, I edited the $CATALINA_HOME/bin/setclasspath.sh file to make it include $CATALINA_HOME/lib/ on the classpath, then made a symlink...
1 tag
Adjust number of file descriptors
cat >> /etc/security/limits.conf
* hard nofile 32768
* soft nofile 32768
Test with: ulimit -n
1 tag
Mysql: Create new user
CREATE USER 'user1'@'%' IDENTIFIED BY 'pass1'; GRANT ALL ON *.* TO 'user1'@'%';
August 2009
13 posts
1 tag
Crontab start at bootup
To run a script or command at every restart, add this to crontab by running crontab -e
@reboot /path/to/my/program
1 tag
Switchonthecode - iPhone tutorials →
2 tags
Gnuplot PNG Template
Simple Gnuplot script for PNG:
set terminal png size 500,350 large
set output "file.png"
set xlabel "Link Bandwidth (Mbps)"
set ylabel "Migration Time (sec)"
set xtics 250
set mxtics 2
set ytics 10
set mytics 2
plot "input.txt" using 1:($2+$3) with lp title "Default Xen" lw 2, \
"" using 1:4 with lp title "Optimized Xen" lw 2
1 tag
Centos Disable Firewall
You can change SELinux and firewall settings by running:
sudo system-config-securitylevel
1 tag
Mercurial Install (CentOS 5.3)
Mercurial is not available in yum. Supposedly it can be easily installed if you have the easy_install python tool, but I didn’t have that setup.
Building from source is easy, but requires an extra step:
wget http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz
tar xzf mercurial-1.3.1.tar.gz
cd mercurial-1.3.1
sudo make install
add to...
2 tags
Mysql: Install (CentOS)
To install mysql on Centos:
sudo yum install -y mysql mysql-server
sudo /etc/init.d/mysqld start
sudo chkconfig --level 345 mysqld on ## To auto start at boot
2 tags
Rubis: Update item end dates
When you create a rubis database it sets an end date for all items. If you try to benchmarks the system after that end date, you will get funny results, since there will be no items for sale. To deal with this, go into the DB and run:
UPDATE items SET start_date=NOW(), end_date=DATE_ADD(NOW(), INTERVAL 700 DAY);
1 tag
Mysql change password
To change password in mysql, log in and type:
set password = password(‘NEWPASSWORD’);
3 tags
Java IO: Writing to a File
To write to a file:
BufferedWriter outputStream =
new BufferedWriter(new FileWriter("filename.txt"));
outputStream.write("hello");
3 tags
Java IO: Reading a File
To read a file from disk:
BufferedReader in = new BufferedReader(new FileReader("foo.in"));
while ((strLine = in.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
3 tags
Eclipse: UML Diagram Generator
Soyatec eUML2
Not sure yet if this does anything useful, but it can make basic class diagrams showing dependencies.
Install following these directions
3 tags
Eclipse: install SVN plugin
Go to help->software updates
Install Collaboration -> Subversive SVN Team Provider
Then go to Polarion website to find URL for SVN Connector Update site
Add this as a new update site and add a connector (I used SVNKit 1.3)
2 tags
Eclipse: Enable assert statements
To enable assertions, you need to modify the run configuration:
To enable (make active) assert statements, you must set a flag to the compiler. Go to Run -> Run… -> Arguments, and in the box labeled VM arguments:, enter either -enableassertions or just -ea. Accept the changes and close the dialog.
July 2009
6 posts
2 tags
Simple Makefile
A very simple makefile template:
CC=g++
CFLAGS=-I.
DEPS = SuperFastHash.h TcpDumper.h
%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
hellomake: msb.o parseTest.o rabinpoly.o TcpDumper.o
g++ -o dumpPrinter parseTest.o TcpDumper.o -I.
2 tags
Python File I/O (Reading Files)
To read in a file from python
infile = file(filename, "r")
while(infile):
line = infile.readline()
if(line == ""):
break
else:
print line
2 tags
Set IP address in CentOS
To set a static IP address (ie for a new VM from stacklet.com)
nano /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 BOOTPROTO=none ONBOOT=yes TYPE=Ethernet IPADDR=192.168.246.30 NETMASK=255.255.255.0 GATEWAY=192.168.246.254
Then: ifdown eth0; ifup eth0
Or, to run from the command line:
ifconfig eth0 192.168.99.14 netmask 255.255.255.0 up
To configure name server:
cat >...