Siirry sisältöön
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">
        <bool>true</bool>
      </edit>
    </match>
    

    (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:

#!/bin/bash
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 ..;
done
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:

\makeatletter
\renewcommand*{\@biblabel}[1]{/#1/}
\renewcommand*{\@cite}[1]{/#1/}
\makeatother

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

kesäkuu 26, 2008 / Jussi

Quickly Convert Text Encodings

Just run:

iconv -f from -t to < input > output

where for example from=ISO88591 and to=UTF8

kesäkuu 12, 2008 / Jussi

Koodaussymboleiden ääntämisestä

Coding Horrorissa oli tänään juttu ASCII-merkkien ääntämisestä koodia luettaessa. Ajattelinpa laittaa tähän sitten omat lukutapani suomeksi ja englanniksi. Sulut ja lainaukset luen joko “sulut auki/sulku kiinni” tai “suluissa”, englanniksi “opening/closing parenthesis” tai “in parentheses”. Lopussa on vielä lista useamman merkin yhdistelmistä.

!
not, huutomerkki, ei, kertoma (matikkayhteyksissä)
not, exclamation point, factorial

"
lainausmerkki, lainaus
quote

#
risuaita
hash

$
dollari, äs (muuttujien nimissä)
dollar

%
prosentti, modulo
percent, mod

&
änd, ja, et (xml)
and, amp (xml)

'
heittomerkki, heitto
single quote, char quote

( )
sulut
parentheses

[ ]
hakasulut, laatikkosulut
brackets, at index

{ }
aaltosulut, lohkosulut
(curly) braces, block

< >
pienempi/suurempi kuin, kulmasulut (xml)
less/greater than, angle brackets

*
tähti, kertaa
star, pointer (c), times

+
plus
plus

,
pilkku
comma

-
miinus, viiva
minus, dash

.
piste
dot, period (at least in Pascal "end.")

/
kautta, kauttaviiva, per (matikka)
slash, over

\
keno, kenoviiva
backslash

:
kaksoipiste
colon, as (Pascal type), in (Java foreach)

;
puolipiste
semicolon

=
on
equals

?
kysymysmerkki
question mark

@
ät
at

^
hattu, ksor
hat, xor

_
alaviiva
underscore

`
yläpilkku
grave

|
or, tai, putki (asiayhteydestä riippuen)
or, pipe

~
tilde, ei
tilde, not

Ja sitten monimerkkiset:

==
on on, tupla-on
equals, is, double equals

===
on on on, tripla-on
really equals, triple equals

=< =>
pienempi/suurempi tai yhtä suuri kuin
less/greater than or equal

:=
kaksoispiste-on
is

!= <>
ei ole, erisuuri kuin
not equals, is not

::
tuplakaksoispiste
double colon

=>
jolle (C#), nuoli (PHP)
for which, arrow

+= -= /= *= &= |= ^= %= .=
plus on, miinus on, kautta on, tähti on, ja on, tai on, hattu on, prosentti on, piste on
plus equals, minus equals, slash equals, times equals, and equals, or equals, ex-or-equals, mod equals, dot equals

...
piste piste piste
ellipsis

->
nuoli
arrow

..
-sta -een, piste piste
from to, dot dot

<>
oikealle
right, shift right

<<<
kolmoisnuoli
triple arrow

++ --
plus plus, miinus miinus
plus plus, minus minus

**
tähti tähti
star star

@"
ät lainaus
at quote

<< >>
vasemmalle/oikealle
left/right, shift left/right

..
-sta -een, piste piste
from to, dot dot

->
nuoli
arrow

<<<
kolmoisnuoli
triple arrow
kesäkuu 11, 2008 / Jussi

An Excellent Guide to Getting PulseAudio to Work in Fedora 8

This guide saved my day: Pulseaudio Fedora 8 Howto. Now I can play MIDI music with TiMidity++ and sounds at the same time, which is good for playing DOS games :)

Seuraa

Get every new post delivered to your Inbox.