I explained here (in greek) a bit about metaprogramming and here about an application in a python/c++ finite element code but this book is everything you need about metaprogramming in Ruby. Written by Paolo Perrotta in a way that two colleagues discuss and solve every day problems. The book is full of example code and assumes some basic knowledge of the Ruby language. The first part of the book deals with general metaprogramming concepts in Ruby from objects and methods to blocks and classes to finally code that writes code. The second part dives in the metaprogramming techniques of Rails, with ActiveRecods being the most important part. The last chapter deals how to use metaprogramming safely. As Yukihiro "matz" Matsumoto says in the foreword "It's a bit like magic", but be ware because there is white magic and black magic.
Friday, 22 October 2010
Metaprogramming Ruby
I explained here (in greek) a bit about metaprogramming and here about an application in a python/c++ finite element code but this book is everything you need about metaprogramming in Ruby. Written by Paolo Perrotta in a way that two colleagues discuss and solve every day problems. The book is full of example code and assumes some basic knowledge of the Ruby language. The first part of the book deals with general metaprogramming concepts in Ruby from objects and methods to blocks and classes to finally code that writes code. The second part dives in the metaprogramming techniques of Rails, with ActiveRecods being the most important part. The last chapter deals how to use metaprogramming safely. As Yukihiro "matz" Matsumoto says in the foreword "It's a bit like magic", but be ware because there is white magic and black magic.
Sunday, 17 October 2010
TeX code generation with perl
#!/usr/bin/env perl
sub initialize{
$text = '\documentclass{article}'."\n";
$text .= '% Created by '."\n";
$text .= '\begin{document}'."\n";
}
sub usepackage{
$text = '\usepackage{'.$_[0]."}\n";
}
sub finalize{
$text = '\end{document}'."\n";
}
sub itemize{
$text = '\begin{itemize}'."\n";
$text .= "\t\item"."\n";
$text .= '\end{itemize}'."\n";
}
sub enumerate{
$text = '\begin{enumerate}'."\n";
$text .= "\t\item"."\n";
$text .= '\end{enumerate}'."\n";
}
sub figure{
$text = '\begin{figure}'."\n";
$text .= "\t".'\includegraphics{}'."\n";
$text .= '\end{figure}'."\n";
}
sub table{
$text = '\begin{tabular}'."\n";
#$text = 'table';
$text .= '\end{tabular}'."\n";
}
sub tabbing{
$a = '\begin{tabbing}'."\n";
$a .= '\end{tabbing}'."\n";
}
sub section{
$a = '\section{'.$_[0]."}\n";
}
sub subsection{
$a = '\subsection{'.$_[0]."}\n";
}
sub equation{
$a = '\begin{equation}'."\n";
$a .= $_[0];
$a .= '\end{equation}'."\n";
}
And a simple example is given below:
print &initialize;
print &usepackage("graphicx");
print &itemize;
print &enumerate;
print &figure;
print &table;
print &finalize;
Friday, 8 October 2010
Book Review: Foundations of GTK+ Development

Wednesday, 6 October 2010
xcf2pdf
#!/usr/bin/python
from subprocess import *
import re
def convert(file):
p = Popen(['convert', file, file[:-3]+'pdf'], stdout=PIPE, stderr=PIPE)
p = Popen('ls', stdout=PIPE, stderr=PIPE)
ls, error = p.communicate()
files = re.split('\n', ls)
for i in files:
if i[-3:]=='xcf':
convert(i)
There are a few features missing and known bugs, e.g. it will convert every layer of the xcf file to a different page in the same pdf. (Beware of the python code formatting)
GGGears
In many engineering applications engineers have to calculate how gears are working under stress. GGGears is a free software that does exactly this by means of the finite element package GETFEM++ and the mesh generation package GMSH, both also free software. It supports both 2D and 3D mesh generation and solver. The user does not need to know anything about finite elements or mesh generation; he/she just need to insert the geometrical data of the gear systmem.
The installation of the software can be easily done in Ubuntu by first adding the repository