How to: Embed dot graphs (graphviz) in LaTeX

September 13th, 2010

Dot graphs (from GraphViz) are known for their easiness in expressing complex graphs in a plain text format and generating those graphs file into static images. For example, look at the following dot graph:

digraph Example {
rankdir=LR;

node [shape="box",color="blue"]; q_0 q_1 q_2 q_3 q_4 q_6 q_7 q_8 q_9 q_10;
node [shape="circle",color="black"]; q_5;

q_0 -> q_1 [label="1"];
q_1 -> q_2 [label="1"];
q_2 -> q_3 [label="1"];
q_3 -> q_4 [label="1"];
q_4 -> q_5 [label="1"];
q_5 -> q_5 [label="0, 1"];

q_0 -> q_6 [label="0"];
q_1 -> q_7 [label="0"];
q_2 -> q_8 [label="0"];
q_3 -> q_9 [label="0"];
q_4 -> q_10 [label="0"];

q_6 -> q_7 [label="0, 1"];
q_7 -> q_8 [label="0, 1"];
q_8 -> q_9 [label="0, 1"];
q_9 -> q_10 [label="0, 1"];

q_10 -> q_0 [label="0, 1"];
}

A graph starts with “graph” or “digraph”, followed by its name. Properties of the graph are wrapped in a pair of accolades. In this example, the first property is “rankdir=LR“, which sets the orientation of the graph to left-to-right (instead of the default top-to-bottom). Line four and five define the appearance of each node used in the graph. At the end of this dot graph is a list of relations between the defined nodes. Below is the generated image of this graph.

automaton generated by GraphViz' dot graphs

automaton generated by GraphViz' dot graphs

Read the rest of this entry »

How-to: Install HipHop (PHP to C++ translator) on Ubuntu 9.10

April 4th, 2010

HipHop has been developed on CentOS and Fedora, building on Ubuntu 9.10 is experimental. At the moment, HipHop can only run on 64 bits systems. The following information about installing hiphop is provided by Facebook’s HipHop wiki.

Packages installation

Using sudo or as root user:

sudo apt-get install git-core cmake g++ libboost-dev flex bison re2c libmysqlclient-dev libxml2-dev libmcrypt-dev libicu-dev openssl binutils-dev libcap-dev libgd2-xpm-dev zlib1g-dev libtbb-dev libonig-dev libpcre3-dev git-core autoconf libtool libcurl4-openssl-dev libboost-system-dev libboost-program-options-dev libboost-filesystem-dev

Getting HipHop source-code

mkdir hiphop
cd hiphop
git clone git://github.com/facebook/hiphop-php.git
cd hiphop-php
export CMAKE_PREFIX_PATH=`/bin/pwd`/../
export HPHP_HOME=`/bin/pwd`
export HPHP_LIB=`/bin/pwd`/bin
git submodule init
git submodule update
cd ..

Building third-party libraries

libevent

wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xzvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
cp ../hiphop-php/src/third_party/libevent.fb-changes.diff .
patch < libevent.fb-changes.diff
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..

ICU4

wget http://download.icu-project.org/files/icu4c/4.2.1/icu4c-4_2_1-src.tgz
tar -xvzf icu4c-4_2_1-src.tgz
cd icu/source
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ../../

libCurl

Make sure that your system time is correct, otherwise ./configure will fail.

wget http://curl.haxx.se/download/curl-7.20.0.tar.gz
tar -xvzf curl-7.20.0.tar.gz
cd curl-7.20.0
cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
patch -p0 < libcurl.fb-changes.diff
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..

Building HipHop

cd hiphop-php
cmake .
make

Now, we have successfully compiled HipHop! The next post will contain information about using HipHop (compiling PHP code in various modes and circumventing some of HipHop’s limitations).

How-to: Profiling PHP scripts using XDebug

October 21st, 2009

Today, I found a new tool the analyse PHP scripts for bottlenecks. By using XDebug you can collect a list of called functions and their runtime. That information is very useful, because the most time consuming tasks are most likely the ones you want to optimize. After collecting the information, we want to generate a graph to visualize the functions. The image below is a graph of the DuoWorks’ main page. DuoWorks is a MVC PHP framework, designed for optimizing web applications performance, but that is another subject.

An example of a dot graph of XDebug's profiling log of DuoWorks' main page

An example of a dot graph of XDebug's profiling log of DuoWorks' main page

Perhaps you already noticed that not every function is listed in the graph. This is because I generated the graph with the default threshold of at least 1% runtime. Every function with a runtime of less than 1% of 12 ms (= total runtime) is therefore not visible. These functions are useless to optimize anyway.

Read the rest of this entry »

DuoStyle: a cross-browser, well-organized, user-friendly CSS component framework

October 10th, 2009

The framework is a collection of the following components.

User Interface

  • Galleries (with thumbnails)
  • Grids
  • Lists
  • Treeviews
  • Toolbars
    • Buttons
    • Dropdown boxes
  • Tooltips

Website

  • Breadcrumbs
  • Typography
    • Code blocks
    • Headers
    • Lists (bullets and numeric)
    • Text
  • Fieldsets
  • Forms
    • Check- and radio boxes
    • Input boxes
    • Textareas

How-to: Install Prism 1.0 with Adobe Flash Player 10 on Ubuntu 8.10 (Intrepid Ibex)

August 4th, 2009

As an active Firefox user, I would like to share Prism with you. Prism is a so-called single site browser and runs each instance in a different, sandboxed process. Therefore it is useful for browsing heavyweight web applications. Tabbed browsers might slow down, when opening a webpage with many and/or large JavaScripts.

YouTube running in Prism

YouTube running in Prism

Prism allows you to browse web applications with an minimalistic user interface. Applications can be opened from the dock or a shortcut on the desktop. Just like normal applications!

This how-to installs prism from the binaries provided by Mozilla and not from the Ubuntu repository. The version in the Ubuntu repository is a bit out of date and therefore it misses some essential features.

First, we get the Prism binaries and move the folder to /usr/share/prism/.

mkdir prism
cd prism/
wget http://prism.mozilla.com/downloads/1.0b1/prism-1.0b1.en-US.linux-i686.tar.bz2
tar --bzip2 -xf prism-1.0b1.en-US.linux-i686.tar.bz2
sudo mv prism /usr/share/

Then its time to install the Flash Player. You need to install the Flash Player plug-in in each user directory, otherwise the Flash Player wouldn”t work for that user.

wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz
tar xfz install_flash_player_10_linux.tar.gz

for path in /home/*
do
 if [ -d "$path" ]
 then
 mkdir -p $path/.prism/plugins
 cp install_flash_player_10_linux/libflashplayer.so $path/.prism/plugins/libflashplayer.so
 fi
done

After installing the Flash Player plugin, Prism is ready to use! You can now create shortcuts by running the following command:

/usr/share/prism

Enjoy the power of Prism!

How-to: Install Trac on Ubuntu 8.10 (Intrepid Ibex)

August 4th, 2009

Download and install Trac’’s requirements from the ubuntu repositories. Please note that Subversion is optional for Trac, but handy during softwaredevelopment, so I added it to the list.

sudo apt-get install apache2 subversion mysql-server python python-mysqldb

Download and install mod_python for Apache and enable the module.

sudo apt-get install libapache2-mod-python libapache2-mod-python-doc
a2enmod mod_python

You need to add the following to your “httpd.conf”, to add a simple setup of Trac:

<Location /projects/myproject>
 SetHandler mod_python
 PythonInterpreter main_interpreter
 PythonHandler trac.web.modpython_frontend
 PythonOption TracEnv /home/trac/myproject
 PythonOption TracUriRoot /projects/myproject
</Location>

Download and install Trac 0.10.4 from the ubuntu repositories.

sudo apt-get install trac

Download the ClearSilver source, extract the source and open the directory.

wget http://www.clearsilver.net/downloads/clearsilver-0.10.4.tar.gz
tar -xzf clearsilver-0.10.4.tar.gz
cd clearsilver-0.10.4/

To get ClearSilver working with python2.5, I had to change one line in “configure”. So open the file and add version “2.5″ to the allowed python versions.

vim configure

Go to line 6560, and change the line to:

python_versions="2.5 2.4 2.3 2.2 2.1 2.0 1.5 24 23 22 21 20 15"

and another line in “configure.in”:

vim configure.in

Go to line 250, and change the line to:

python_versions="2.5 2.4 2.3 2.2 2.1 2.0 1.5 24 23 22 21 20 15"

Build the new “neo_cgi.so” and copy it to the site-packages:

./configure
make
make install
cp python/build/lib.linux-x86_64-2.5/neo_cgi.so /usr/lib/python2.5/site-packages/neo_cgi.so

Create a new Trac-environment.

trac-admin /home/trac/myproject/ initenv

Test your installation by browsing to “http://localhost/projects/myproject“. An example page of Trac will be displayed. Happy bugtracking!