June 8, 2009, 8:08 pm
In this post I’m going to show you how to include source code snippets in your Latex documents. To perform the task we’re going to use the listings package.
First we’re going to define the source code’s layout. We’ll define two different styles to show the capabilities of the package. The first style comes in handy for including source code. The second one is better for including, for instance, console commands. Of course you can define different styles to suit your own needs.
\definecolor{gray92}{gray}{.92}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
\lstdefinestyle{source_code}
{
numbers=left,
stepnumber=5,
basicstyle=\normalsize,
captionpos = b, %bottom
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
backgroundcolor=\color{gray92},
frame=lrtb,
framerule=0.5pt,
linewidth = \textwidth
}
\lstdefinestyle{console}
{
numbers=none,
basicstyle=\bf\ttfamily,
backgroundcolor=\color{gray92},
frame= lrtb,
framerule=0.5pt,
linewidth=\textwidth,
}
Once the styles are defined there are two ways to include the snippets in the document:
- Writing the source code directly in the Latex document.
- Importing the source code file.
\begin{lstlisting}[style=console, caption=A command]
# gcc -o hello hello.c
\end{lstlisting}
Note how we can specify the source code’s programming language as well as the listing’s caption:
\lstinputlisting[style=source_code, label = some label, caption=A shell script, language=bash]{example.bash}
The final result looks like this:

You can get the full Latex source code here.
June 6, 2009, 3:17 am
Sometimes you need to set up some service at home (e.g., a Web Server or a Mail Server). In my case, my IP address is dynamic and likely to change. You can always pay for a static IP address but there other valid solutions. For instance you can use a dynamic DNS service such as DynDNS. Service setup is easy; you have to follow these steps:
- Register an account at dyndns.org and configure a hostname (e.g., myhost.dyndns.org).
- Download the DynDNS client and configure it with your registered hostname. There are versions for Windows, Linux and Mac.
Now every time your IP address changes, the DynDNS client updates the corresponding DNS records and your services are accessible again. This mode of operation has a drawback related to DNS catching. All records in DNS have a Time to Live (TTL) value. This value dictates how long a record should be stored locally before a new copy of the record must be retrieved from DNS. Sometimes the information in DNS changes, but the old information is still stored in the DNS caches. When the cached record is different from the newest information in DNS, it is called a caching error.
DynDNS allows you to set the TTL value to 60s or 4h. If your IP is dynamic you should use the 60s value.

In summary, if availability and grade of service are key aspects for you, pay for a static IP. Otherwise you can always use services like DynDNS.
June 4, 2009, 3:37 am
Hace unas semanas Aitor Ibañez (Responsable Técnico de la Zona Norte de Oracle) ofreció una charla muy interesante en la Escuela de Ingenieros de Bilbao. En ella realizó una panorámica sobre diferentes empresas TIC tanto nacionales como internacionales, y ofreció una serie de consejos muy útiles para el desarrollo profesional.
Desde luego una presentación muy útil para todos aquellos que vamos a entrar en el mercado laboral en breve.
June 4, 2009, 2:18 am
Control versioning systems are an essential tool for every programmer and provide very useful options such as keeping different branches of the same project or reverting the source code to a previous version.
In this post I’m going to show you how to set up and integrate Subversion with VS2008. Continue reading ‘Adding Subversion support to Visual Studio 2008’ »
May 22, 2009, 4:59 pm
Producing tables is latex is not an easy task. Fortunately I found a very handy macro that transforms Excel tables into Latex code. It is written by Joachim Marder and can be obtained here. If you use OpenOffice you can take a look at calc2latex. With the table creation problem solved, now we can focus on improving the style. We are going to need the following packages:
\usepackage[dvipsnames,usenames]{color}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
Next we specify some formatting commands:
%increase the column separation and the cell height
\renewcommand{tabcolsep}{0.25cm}
\renewcommand{arraystretch}{2}
%We can define our custom colors in RGB format
\definecolor{tableheading}{rgb}{0.82,0.82,0.82}
\definecolor{softblue}{rgb}{0.8,0.8,1} %Change the bar color
\arrayrulecolor{ForestGreen}
… and voila! Latex has produced a very stylish table.
This is the full latex source code:
\documentclass[12pt,a4paper]{report}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage[dvipsnames,usenames]{color}
\usepackage{array} \usepackage{colortbl}
\usepackage{booktabs}
\renewcommand{tabcolsep}{0.25cm}
\renewcommand{arraystretch}{2}
\definecolor{tableheading}{rgb}{0.82,0.82,0.82}
%definecolor{totalcolor}{rgb}{1,0.7,0.7}
%definecolor{firstcolumncolor}{rgb}{0.7,1,0.7}
\definecolor{softblue}{rgb}{0.8,0.8,1}
\arrayrulecolor{ForestGreen}
\begin{document}
% Table generated by Excel2LaTeX from sheet 'material'
\begin{table}[!h]
\centering
\begin{tabular}{ccccc}
\toprule
\rowcolor{tableheading} {bf ID} & {bf Description} & {bf Price} & {bf Redeem period} & {bf Redeemed cost} \
\midrule
M1 & PC 1 & 500,00 & 9,00 & 150,00 \
\midrule
M2 & PC 2 & 500,00 & 9,00 & 150,00 \
\midrule
M3 & Server 1 & 1.000,00 & 9,00 & 250,00 \
\midrule \textit{Total} & & & & multicolumn{1}{>{columncolor{softblue}}c}{550,00} \
\bottomrule
\label{tab:test}
\end{tabular}
\caption{Test table}
\end{table}
\end{document}
May 19, 2009, 5:59 pm
Surprisingly, there aren’t too many web services libraries in Python. On the one hand, we have ZSI, allegedly the most powerful one. However its documentation is outdated and the beginnings aren’t easy. Keeping my search I discovered soaplib. Soaplib is an easy to use python library for writing and calling soap web services. To install it follow these steps:
svn co https://svn.optio.webfactional.com/soaplib/trunk soaplib
cd soaplib python setup.py install
Creating web services with soaplib is quite easy. This is the server:
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Array
class HelloWorldService(SimpleWSGISoapApp):
@soapmethod(String,Integer,_returns=Array(String))
def say_hello(self,name,times):
results = []
for i in range(0,times):
results.append('Hello, %s'%name)
return results
if __name__=='__main__':
from cherrypy._cpwsgiserver import CherryPyWSGIServer
# this example uses CherryPy2.2, use cherrypy.wsgiserver.CherryPyWSGIServer for CherryPy 3.0
server = CherryPyWSGIServer(('localhost',7789),HelloWorldService())
server.start()
And this is the client:
from soaplib.client import make_service_client
from helloworld import HelloWorldService
client = make_service_client('http://localhost:7789/',HelloWorldService())
print client.say_hello("Dave",5)
As you can see writing a simple web service just takes a few seconds. This example passes primitive data types (String, integer …) to the remote method. We’ll see how to pass complex data another time.
May 18, 2009, 8:55 pm
In a previous post we talked about RIP. Today I’m going to show you how to configure OSPF. OSPF is a dynamic link-state routing protocol used in IP networks. OSPF is perhaps the most widely used interior gateway protocol (IGP) in large enterprise networks. OSPF exceeds RIP in many aspects:
- It has very low convergence times.
- When no topology changes occur, OSPF is very quiet.
- OSPF enables network subdivision into areas.
- Supports authentication.
- Uses multicast.
- Only routing changes are propagated, not the full routing table like in the RIP case.
- …
To configure OSPF in your cisco router you should follow these steps:
fry> enable
fry# configure terminal
fry(config)#router ospf 1
fry(config-router)#network 192.168.2.0 0.0.0.255 area 0
fry(config-router)#network 192.168.3.0 0.0.0.255 area 0
fry(config-router)#network 192.168.4.0 0.0.0.255 area 0
You have to specify all the interfaces in which you want to run OSPF with network commands. 0.0.0.255 is a wildcard and means that OSPF will run in any interface with an IP address belonging to the 192.168.2.0/24 network. You can also indicate a specific IP address. If the interface’s IP address changes (e.g. from 192.168.4.1 to 192.168.4.2), OSPF will stop running. The configuration is as follows:
fry(config-router)#network 192.168.4.1 0.0.0.0 area 0
To propagate a default route you can execute this command:
fry(config-router)#default-information originate always
One OSPF drawback could be the configuration complexity. However, if the network topology is point-to-point and we only have one area (like in this case) configuration is pretty straightforward.
May 18, 2009, 12:54 am
The free version of Hotmail doesn’t offer POP3 access. Fortunately there is a SW that emulates POP3 for hotmail. Freepops retrieves mail via web, but emulates a POP3 server your mail client can talk to. There also exists a mac version called Macfreepops. Freepops is very easy to configure and allow you to easily read your mail from a wide variety of webmail providers. Definitely a great piece of SW!
May 17, 2009, 6:14 pm
Routing Information Protocol (RIP) is an Interior gateway protocol that uses the distance-vector routing algorithm. The original specification of RIP, defined in RFC 1058, uses classful routing. The periodic routing updates do not carry subnet information, lacking support for variable length subnet masks (VLSM). RIPv2 introduces VLSM support, multicast and authentication capabilities. Although RIP has important limitations (slow convergence times, 15 hop limit, full routing updates periodically…) it’s very easy to configure and can come in handy for some networks. To configure RIP in your cisco router you should follow these steps:
router> enable
router# configure terminal
router(config)#router rip
router(config-router)#network 192.168.2.0
router(config-router)#network 192.168.3.0
router(config-router)#network 192.168.4.0
router(config-router)#version 2
You have to specify all the interfaces in which you want to run RIP with network commands. And that’s all. You have RIP running on your router. Note: In most current networking environments, RIP is not the preferred choice for routing as its capabilities are poor compared to EIGRP, OSPF, or IS-IS.
May 17, 2009, 8:01 am
I used to enjoy listening music from last.fm but it isn’t free anymore. Hence I decided to search from a free alternative and came across Spotify. Spotify allows you to listen to a wide variety of music, instantly and at no cost. Besides it has some advantages over last.fm. For instance you can choose which song to play and you can listen to the whole song, not just a fragment like in last.fm. I definitely recommend it.
P.D.: I have some spare Spotify invitations. If you need one leave a comment or send me an email to jorge.marsal@gmail.com