Monthly Archives: June 2008

Lynx doesn’t display some Unicode characters properly

For me, it’s the Lithuanian ą, č, ę, ė and their uppercases. Funny enough, the rest of these characters were displayed OK.

It’s easy to find on Google that this is because of lynx having been compiled against ncurses, whereas you would need ncursesw (with wide character support).

Modify /usr/ports/www/lynx/Makefile to have

CONFIGURE_ARGS+=--with-screen=ncursesw --with-zlib --libdir="${L_LIB}" \
--enable-nsl-fork --enable-persistent-cookies \

instead of

CONFIGURE_ARGS+=--with-screen=ncurses --with-zlib --libdir="${L_LIB}" \
--enable-nsl-fork --enable-persistent-cookies \


Thunderbird->mutt, sendmail->postfix (FreeBSD)

So, decided to make a switch.

As always, refer to the Handbook first. Here’s an excerpt from one of the pages:

FreeBSD ships with sendmail by default, responsible for receiving incoming mail as well as delivering outgoing mail. It is not responsible for the collection of mail using protocols such as POP or IMAP to read your email, nor does it allow connecting to local mbox or Maildir mailboxes.

So, I installed fetchmail (handbook section). That covers mail collection.

What about sending?

Well, it worked pretty well with sendmail, until I wanted SSL-encrypted connections to the POP3 server, so that the password wasn’t sent in plain text. (At least that’s what I think all the fuss is about. Do correct me if I’m wrong in my ignorance.)

Turned out SSL wasn’t compiled in.

I could do that, and probably should have, but at that point I read some discussions about sendmail’s insecurities, and decided I should switch to postfix.

Anyway, this whole thing ended up real bollockey. Postfix had trouble reading my self-signed certificate, not sure what was the cause.

Here’s some valuable links I came accross:

The directory for certificates is (I think) /usr/local/share/certs/.

Console RSS news reader

I was looking for one today, and only found these three:

Raggle – written in Ruby, last version dates 2004, feeds-articles-content layout common to graphical aggregators.
Snownews – a simple list layout.
Newsbeuter – very much like mutt in layout.

All three support some sort of filtering/grouping; and importing/exporting OPML.

Here’s the memory usage:

36264 user 1 96 0 24100K 19852K select 0:12 0.00% ruby
36506 user 1 5 0 14388K 10632K ttyin 0:07 0.00% newsbeuter
35062 user 1 5 0 6728K 3664K ttyin 0:00 0.00% snownews

Other notes:

  • Snownews doesn’t support Atom. The other two do.
  • Snownews and Raggle have feed encoding conversion problems, at least on my machine. Newsbeuter doesn’t.
  • Snownews and Raggle can be run under cygwin. Don’t know about Newsbeuter.

FreeBSD: script to manage processor speed

I have posted about this before <broken link>.

This time, it’s not one script, but many.

  • cpuctl is the script to be used when you want to switch the processor frequency. It goes anywhere you feel comfortable, I put it in ~/bin/.
  • cpucontrol is a wrapper script to sysctl. It’s required, since a common user is not allowed to change sysctl values. So, this script is run at startup with root permissions and works in the background. It reads from a file and issues the sysctl command. You control who can change the frequency by setting the aforementioned file’s permissions.
  • rc.d-cpucontrol is the rc.d file. It’s required to run cpucontrol on startup.
  • awesome-cpu is a widget for the awesome window manager. I use that. If you don’t, just delete it.

You can get all the files packed. SERVER DIED

Check the files, they have modifiable values. To install, issue something like:

cp cpuctl ~/bin/cpuctl
sudo cp cpucontrol /usr/local/bin/cpucontrol
sudo cp rc.d-cpucontrol /usr/local/etc/rc.d/cpucontrol
sudo echo 'cpucontrol_enable="YES"' >> /etc/rc.conf

RDF to iCal converter (PHP script)

…which can easily be adapted to, say, RSS or shit.

I wrote this with a particular RDF feed in mind, so you might have to tweak it, if you want to use it.

Also, see the TODOs.


// GPLv3.
// Parsing part copied over from PHP manual.
// Also used RFC2445:
// Distributed under fuck you license.

class RDFItem {
	var $link;		//
	var $title;		//
	var $description;	//
	var $date;		//
//	var $dc:date;		// hell knows what this is

    function RDFItem ($link)
        foreach ( $link as $k => $v )
            $this->$k = $link[$k];

function readRDF( $filename )
    // read the RDF
    $data = implode("", file($filename));
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $tags);

    // loop through the file structures
    foreach ($tags as $key=>$val) {
        if ($key == 'item') {
            $itemranges = $val;

            // each contiguous pair of array entries are the
            // lower and upper range for each RDF feed item
            // (what?..)

            for ($i=0; $i < count($itemranges); $i+=2) {
                $offset = $itemranges[$i] + 1;
                $len = $itemranges[$i + 1] - $offset;
                $tdb[] = parseItem( array_slice($values, $offset, $len) );
        } else {

    return $tdb;

function parseItem($subElements)
	for ( $i = 0; $i \n/", "", $desc, 1 );

	// Make sure all lines except the 1st have a space up front.
	$desc = str_replace( "\n", "", $desc );
	$desc = str_replace( "<br />", "\\n\n ", $desc );
	$desc = str_replace( "<br/>", "\\n\n ", $desc );

	// Manage links.
	$desc = preg_replace( "/<a href=\"(.*?)\">/s", " [$1] ", $desc );
	$desc = str_replace( "</a>", "", $desc );

	// Manage all other HTML tags.
//	$desc = preg_replace( "/<(?:.*?)>/s", "", $desc );

	// TODO: check that lines are folded at 75 octet.

	return $desc;

$db = readRDF( 'hardcore.rdf' );

echo "<pre>";
echo "</pre>";

// Now for the dirty punk solution.
// Create the calendar.
$cal .= "X-WR-CALNAME:Vilnius Hardcore Events | [TODO: date]\n";

foreach ( $db as $info )
	$info->date = fix_date($info->date);
	$info->description = fix_description($info->description);

	$cal .= "BEGIN:VEVENT\n";
	$cal .= "DTSTART;VALUE=DATE-TIME:".$info->date."\n";
	$cal .= "DTEND;VALUE=DATE-TIME:".$info->date."\n";
	$cal .= "SUMMARY:".$info->title."\n";
	$cal .= "DESCRIPTION:".$info->description."\n";
	$cal .= "URL:\n";
	$cal .= "UID:".$info->link."\n";
	$cal .= "END:VEVENT\n";

$cal .= "END:VCALENDAR\n";

//echo $cal;
echo file_put_contents ( "hardcore.ics", $cal );


FreeBSD: script to manage processor speed

Edit: this has been updated <broken link>.

You might ask: why not use powerd? Well, I tried. It sure does save energy, but there are also annoying pauses between when I start manically switching windows and it changes the frequency.

So, I wrote a C Shell script to do the thing. Yes, C Shell is a nuisance, but Bourne Shell doesn’t have arrays, and I’ve wasted quite some time trying to work around that. Then I just dumped the idea.

It ain’t that long anyway, so you are able to catch the bugs before they run away.

To use it, set the freq_levels array to what you’ve got.

The drawback is that it uses sudo when setting the frequency. I’m currently trying to find out how not to.

# Script to manage cpu freqency (scaling). Tested on FreeBSD.

## NOTE: allowed frequencies must be set manually.
## On FreeBSD, see: sysctl -a | grep dev.cpu
# -----
# dev.cpu.0.freq_levels: 1660/27000 1452/23625 1328/18900 1162/16537
# 996/10800 871/9450 747/8100 622/6750 498/5400 373/4050 249/2700 124/1350

# Smaller values go earlier.
set freq_levels = ( 373 871 996 1162 1660 )

# Get current frequency and check which level it is.
set freq_current = `sysctl dev.cpu.0.freq | cut -d' ' -f 2`
set level_current = 0	# level is unknown
set i = 1		# iterator

while ( $i <= $#freq_levels )
	if ( $freq_current == $freq_levels[$i] ) then
		@ level_current = $i
	@ i = $i + 1

if ( $level_current == 0 ) then
	echo "Current CPU frequency not in supported frequency list."
	exit 1

# Check which action is to be performed. If no argument specified,
# output help.
if ( $1 == "" ) then
	goto help
switch ($1)
	case "up":
		if ( $level_current  1 ) then
			@ level_current = $level_current - 1
			eval 'sudo sysctl dev.cpu.0.freq=$freq_levels[$level_current]'
	case "show":
		echo "Current frequency: $freq_current"
		echo "Current level:     ${level_current}/${#freq_levels}"

	case "-h":
		echo "cpuctl [ up | down | show ]"
	case "--help":
		goto help

	case "*":
		echo "Unknown parameter: $1"
		goto help

exit 0

awesome: launch custom commands from menu

The menu in the awesome wiki is a good one, yet it has some drawbacks:

1) It’s written in bash. Not all systems have bash. Not all systems have bash in /bin/bash.
2) The menu is stored inside the script itself, which makes it hard to edit.

My solution: write a menu file with choices:

% pwd
% cat menu

Add a command to .awesomerc, like this one:

modkey = {"Mod4"} key = "F2" command = "spawn"
arg = "cat /usr/home/cy/.config/awesome/menu | awesome-menu -e 'sh ~/bin/awesome-exec ' 'Execute:' &"

Finally, write ~/bin/awesome-exec (or elsewhere, if you fancy):


case $1 in
                exec linux-sunbird & ;;
                exec $1 & ;;

As you can see, this solution is a lot more simple than the one in the awesome Wiki. Also, you can edit the menu easily, like this:

echo mutt >> ~/.config/awesome/menu // add
cat ~/.config/awesome/menu | grep -v mutt > ~/.config/awesome/menu //remove

I’m saying “easily”, because you can add these commands as an alias.

vim: go to …


will go to line 47.


will go 3 lines further.

:go[to] 53

will go to character 53.

Simple instructions on installing the Samsung ML-2015 printer in FreeBSD

I’ve written about this once <broken link> already. Now, that time the whole thing got a little hectic, which was somewhat related to the promille phenomenon. Anyway, this time it’s gonna be a little simpler.

The instructions presented here are on installing CUPS for Samsung ML-2015. ML-2015 is (basically) the same as ML-2010.

These instructions will also be useful with other Samsung printers, since the printing language (and drivers as a consequence) are disgustingly similar for Samsungs. (How do I know? I don’t. I’m a mockingbird.)

I assume you know how to use pkg_add, portupgrade (my case) or other port managing utility. If not, just ask.

1) Install cups-base. You probably have this. Add to /etc/rc.conf:


(Re)start CUPS. Check localhost:631 if it works. If you try installing a printer in CUPS now, Samsung won’t be listed yet.

2) Install splix.

ports% cat /usr/ports/print/splix/pkg-descr
SpliX is a set of CUPS printer drivers for SPL (Samsung Printer Language)
printers. Below is a non-exhaustive list of currently supported printers. Note
that only SPL2 and SPLc printers are currently supported!

At this point if you try installing a printer in CUPS, you will have Samsung listed.

3) Install cups-pstoraster.

ports% cat /usr/ports/print/cups-pstoraster/pkg-descr
This distribution is based on GNU Ghostscript and provides the "driver" for
CUPS that supports non-PostScript printer drivers within CUPS.

Samsung printers don’t support PostScript, at least to my severely limited knowledge they don’t.

Restart CUPS.

4) Modify ulpt0 permissions.

cd /dev
/dev% ll ulpt0
crw-r--r-- 1 root operator 0, 121 Jun 13 22:00 ulpt0
/dev% sudo chown root:cups ulpt0
/dev% sudo chmod g+w ulpt0

Now for some elaboration. You might wonder why not just add user cups to group operator. The answer is simple: security.

Fact is, cups only needs access to the printer, and that’s it. The operator group, on the other hand, has access to a lot more: other USB devices, hard disk devices, and hell knows what other system files in whichever depths of /usr or /var or /etc.

Now, you just do what you think is better. If you want to add cups to operator – then do it. After all, root is thy lord. I’m just telling what I did.

EDIT: if you don’t take measures, settings to /dev will be reset on restart.

5) Start the printer if not already done (from CUPS’ administrative interface). Print a test page.

6) If you smoke, have a smoke. If you drink beer, have a beer. If you drink coffee, have another coffee. If you lapdance, have a lapdance. If you fuck children for breakfast – go kill yourself.


Wouldn’t have figured this all out without this BSD forums thread and this blog post.

MPC aliases for tcsh

mpc commands are quite lengthy, so here’s what I put in my .cshrc:

# mpc/mpd control
alias mpca 'mpc search \!* | mpc add -' # search and add tracks
alias mpcc mpc clear
alias mpcl mpc playlist
alias mpcs mpc stop
alias mpcp mpc play

I also added some shortcuts to use the WIN+FXX keys in awesome:

# MPC control through WIN+FXX keys.
key { modkey = {"Mod4"} key = "F7" command = "spawn" arg = "mixer vol -5:-5" }
key { modkey = {"Mod4"} key = "F8" command = "spawn" arg = "mixer vol +5:+5" }
key { modkey = {"Mod4"} key = "F9" command = "spawn" arg = "mpc toggle" }
key { modkey = {"Mod4"} key = "F10" command = "spawn" arg = "mpc stop" }
key { modkey = {"Mod4"} key = "F11" command = "spawn" arg = "mpc prev" }
key { modkey = {"Mod4"} key = "F12" command = "spawn" arg = "mpc next" }