Barnoid’s Knowledge Base

Bits of Collected Wisdom

January 18th, 2010

Gentoo: Installing Fonts

Lots of howtos are out there, here’s mine:
Install the fonts somewhere in the /usr/share/fonts/ directory. For Type1 fonts (only .pfb and .pfm files are present, but no .afm files), you need to run the type1afm command first to generate the necessary .afm files (otherwise the fonts won’t show up in OpenOffice, for example). Then generate the font directory and scale files and register the new font directory in the system. In shell-speak:

# cd /usr/share/fonts
# mkdir myfont
# cd myfont
# cp font files, i.e., *.afm *.pfb *.pfm .
# type1afm `ls *.pfb`
# mkfontdir /usr/share/fonts/myfont
# mkfontscale /usr/share/fonts/myfont
# xset fp+ /usr/share/fonts/myfont
# xset fp rehash
# fc-cache

Check whether the new font shows up in the font list:

# fc-list | grep -i 

Done. Restart the application (restarting the X server is not necessary)

November 5th, 2008

1001 reasons why C/C++ is evil

Consider the following C++ code:

class A
{
int do(string key, bool b)         { cout << "do('" << key << "', " << (b ? "true" : "false") << ")" << endl; };
int do(string key, string value) { cout << "do('" << key << "', '" << value << "')" << endl; };
};

...

A *a = new A();
a->do(”do”, “something”);

What is printed? Well, not what I expected:

# ./reason1
do('do', true)

Intuitively, the second method, do(string string), should be executed, but gcc (4.1) executes the first method, do(string, bool). This is because the second ’string’, “something”, is interpreted as ‘char *’.

One down, 1000 more reasons to come.

September 10th, 2008

Ebuild for nslookup / dig?

Can’t find the ebuild containing nslookup or digg? Install the bind-tools:

# emerge -avD net-dns/bind-tools

and you’re all set:

# nslookup 127.0.0.1

Server:        xxx.yyy.zzz.1
Address:    xxx.yyy.zzz.1#53

1.0.0.127.in-addr.arpa    name = localhost.
September 1st, 2008

Thunderbird + Lightning: Layout Messed Up?

If Thunderbird’s Lightning calendar extension messes with your Thunderbird layout and doesn’t work as expected, make sure to install libstdc++5 and then re-install Lightning.

# emerge -av libstdc++

[ebuild  N    ] virtual/libstdc++-3.3

September 1st, 2008

VIM: Search for selection

After yanking a piece of text into the buffer, you can search for it by pressing <ctrl>-<r> ” (that is: control-r double quotes) in search mode (”/”).

September 1st, 2008

VIM <-> X11 middle-mouse copy/paste

That one is easy: just enable the “vim-with-x” USE flag and recompile vim:

# echo "app-editors/vim vim-with-x" >> /etc/portage/packages.use

# emerge -av vim

[ebuild   R   ] app-editors/vim-7.2  USE="acl gpm nls perl python vim-with-x -bash-completion -cscope -minimal -ruby -vim-pager”
April 20th, 2008

Generating a Self-Signed, Unencrypted SSL Certificate

Generate an RSA private key:

# openssl genrsa -des3 -out server.key.encrypted 1024

Create a self-signed certificate (make sure to enter the FQDN for the ‘Common Name’)

# openssl req -new -x509 -nodes -sha1 -days 365 -key server.key.encrypted -out server.crt

Remove the password from the encrypted key

# openssl rsa -in server.key.encrypted -out server.key
# chmod 400 server.key
October 14th, 2007

ALSA Sound Problems (e.g. in Firefox when watching Videos)

Recent sound problems (for example no sound when watching Youtube videos in Firefox or Thunderbird crashes whenever it pops up a calendar alarm) are probably caused by missing plugins. ALSA_PCM_PLUGINS controls which plugins are built; by default, it should build all of them, but apparently a recent update does not set the variable.

Symptoms are, for example, no sound from flash videos within Firefox. When started from a shell various error messages are printed, such as:

ALSA lib pcm_misc.c:740:(snd_pcm_parse_control_id) Cannot get index for 0
ALSA lib pcm_dmix.c:914:(snd_pcm_dmix_open) unable to open slave
ALSA lib conf.c:3510:(_snd_config_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib pcm.c:2144:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib pcm_hw.c:1351:(_snd_pcm_hw_open) Invalid value for card
ALSA lib confmisc.c:769:(parse_card) cannot find card ''

Try

# echo 'ALSA_PCM_PLUGINS="adpcm alaw copy dshare dsnoop extplug file hooks ladspa lfloat linear meter mulaw multi null rate route share shm"' >> /etc/make.conf
# emerge --oneshot alsa-lib
# /etc/init.d/alsasound restart
June 28th, 2007

Concatenate PDF Files

To concatenate two or more PDF files together into one, try

# gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=concatenated.pdf file1.pdf file2.pdf [file3.pdf [...]]

With the -dBATCH -dNOPAUSE option, ghostscript won’t show a prompt and you won’t have to press return after each page. Comes in handy if the PDFs are long.

June 15th, 2007

CPUFreq Daemon Fails to Stop

On my Gentoo notebook, stopping cpufreqd fails:

# /etc/init.d/cpufreqd stop
* Stopping CPU Frequency Daemon ...           [ !! ]

It seems that start-stop-daemon fails to terminate the cpufreqd processes, so let’s help it a bit. Simply add the following bold line to the stop() function in your /etc/init.d/cpufreqd script

stop() {
ebegin "Stopping CPU Frequency Daemon"
kill -9 `ps -A | grep cpufreqd | sort -n | head -n 1 | awk ‘{print $1}’`
start-stop-daemon –stop –exec /usr/sbin/cpufreqd
eend ${?}
}

Now cpufreqd should shut down nicely:

# /etc/init.d/cpufreqd stop
* Stopping CPU Frequency Daemon ...           [ ok ]