Skip to content
syyskuu 20, 2010 / Jussi

Recursive move in cmd.exe

for /r and move commands can move files to a different extension recursively:

for /r %x in (*.ext) do ren "%x" *.other.ext

syyskuu 20, 2010 / Jussi

Regex not matching a subexpression

E.g. ^((?!.*\...-..\.resx).)*$

kesäkuu 17, 2010 / Jussi

Outer join in LINQ to SQL

LINQ to SQL provides direct access to inner joins only. However, it does take much to write an outer join either.

from l in context.LeftTable
join x in context.RightTable on l.Id equals x.LeftTableId into y
from r in y.DefaultIfEmpty()

Unfortunately I can no longer remember where I learned this from so I can’t give credit.

Joel Albahari points out in an MSDN thread that it is not necessary to use the join keyword at all and presents this, (IMO) much more understandable version:

from l in context.LeftTable
from r in context.RightTable.Where(x => x.LeftTableId == l.Id).DefaultIfEmpty()

The above snippets accomplish the same as

from LeftTable l
left join RightTable r on l.Id = r.LeftTableId

in regular SQL. The key in both solutions is the DefaultIfEmpty()

helmikuu 20, 2010 / Jussi

Font smoothing, Firefox, *ubuntu

I’ve found the font smoothing in Firefox on *ubuntu not to be quite doing its job. Some fonts are OK, but ones containing e.g. precise sub-pixel hinting or advanced ligatures just look bad. Just as an example, install Calibri and use it as the default font. Then open a page in Wikipedia and you’ll see how dodgy the rendering is.

What’s the solution then?

There are three steps, all quite simple, and they just require a restart of the browser.

  1. Enable quality rendering in Cairo for smaller font sizes.

    This can be done through about:config. Find browser.display.auto_quality_min_font_size and set it to a pixel value of your choice. If it’s zero, all text will be rendered in quality mode. Note that this will affect performance, so you may want to skip this step.

  2. Make Firefox use GTK settings for smoothing.

    This is also done through about:config. Find gfx.use_text_smoothing_setting and change it to true.

  3. Enable autohinting in GTK.

    Open a file called .fonts.conf in your home directory. Add the following section to it:

    <match target="font">
      <edit mode="assign" name="autohint">

    (If the file does not exist, you can see its structure here.)

Now, just restart the browser and enjoy smooth fonts!

lokakuu 30, 2008 / Jussi

Illustrator, EPS and LaTeX

Ironically, Adobe Illustrator creates malformed files when you save your illustrations as EPS, and of course LaTeX, ghostscript and thus pdflatex choke on them. There’s however a simple remedy: the eps2eps ”distiller” strips all non-essential parts away from EPS files thus fixing also malformed AI EPS files.

For reference, here’s the gist of my (unoptimized) eps2pdf script I use before I run pdflatex:

mkdir temp-eps-eps
for file in *.eps; do
    echo -e "$file";
    eps2eps $file temp-eps-eps/$file;
    cd temp-eps-eps;
    epstopdf $file --outfile=`echo -e $file | sed -e "s/\.eps/\.pdf/g"`;
    mv `echo -e $file | sed -e "s/\.eps/\.pdf/g"` ..;
    rm $file;
    cd ..;
rmdir temp-eps-eps

This should be called in the directory whose EPS files you wish to convert to PDF.

And why do I use EPS? Pretty much any vector graphics application supports it. Pretty often, saving your illustrations directly as well-behaving PDFs can be much more difficult than using EPS.

lokakuu 15, 2008 / Jussi

Modifying LaTeX citation styles

To modify citation styles for basic bibitem citations, use the following lines in the preamble:


The code above changes the citation marker from [n] to /n/.

To change the bibliography title, use (right before \begin{thebibliography}, especially if you’re using babel):

\renewcommand\refname{New Title}   % for article, or
\renewcommand\bibname{New Title}   % for other types
syyskuu 1, 2008 / Jussi

N2S: Rebuilding VirtualBox Kernel Module

This needs to be done whenever a new kernel is installed. (Sometimes a newer version of VBox is needed as well, if the current one does not support the new kernel.)

sudo /etc/init.d/vboxdrv setup