Convert PNMs to DjVu

I’ve decided to scan some notebooks. After researching a bit, I’ve decided to use DjVu instead of PDF, which I normally use. I’ve chosen to use DjVu because it offered great quality with a very good compression rate (~26KB per page) in lineart (black and white).

While XSane can natively save a multipage project into PDF, it can’t do so for DjVu. So the solution is to use the PNMs generated by XSane and convert them using the command line tools offered by DjVuLibre to bundle them together into a DjVu file. As you can guess, doing this manually is pretty hard work. To make this task easier, I’ve written a small bash script to automate the process.
Continue reading Convert PNMs to DjVu

Fixing the Home Link in the Telem System (OpenU)

This post can be helpful for students of the Open University of Israel. As a student there, I found it very annoying that the link to the courses’ homepage in the Telem system is a JavaScript link. This prevents it from opening in a new tab and thus requires various workarounds to get back to the homepage in a different tab. So, a little while ago, I wrote a little Greasemonkey script to fix it.

// telem.user.js
// version 0.1 
// 2008-01-01
// Copyright (c) 2008, Guy Rutenberg
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name          OpenU's Telem - Fix Home Button
// @namespace     http://www.guyrutenberg.org/
// @description   Fixes the home button link in the telem system of the OpenU.
// @include       http://maagar.openu.ac.il/opus/*
// ==/UserScript==


home = document.getElementById('home');
if (home) {
    re = /javascript:find_home_page('(.*?)','(.*?)',/
    match = re.exec(home.href)
    home.href = 'http://telem.openu.ac.il/courses/'+match[2]+'/'+match[1]
}

This script changes the link to a regular, non-JavaScript link. I’ve tested it for more than a month now without finding any bugs. However, if you find something or have any suggestions, please comment.

Update: See A Greasemonkey Fix to the Top Menu in Sheilta (Open University); it has a fix for the top menu bar in the Sheilta system.

Convert CSS layout to RTL – cssrtl.py

This is a re-release of a script of mine that helps convert CSS layouts to RTL. I originally released it about a year ago, but it was lost when I moved to the new blog. The script, cssrtl.py, utilizes a bunch of regular expressions to translate a given CSS layout to RTL.

Continue reading Convert CSS layout to RTL – cssrtl.py

spass – A Secure Password Generator Utility

spass is a secure password generation tool. spass was designed under the assumption that a password generator is only as good as its random number generator, so spass uses the Random class, a /dev/random-based cryptographically strong random number generator class. As always, I tried to make the command-line interface as user-friendly as possible (as much as a command-line interface can be friendly).
Continue reading spass – A Secure Password Generator Utility

radio.py-0.4 – Listening to Radio the Easy Way

Update: radio.py 0.5 is available.

radio.py is a little script that makes it very easy to listen to radio under Linux (and maybe other OSs too) with mplayer. All you need to do is call radio.py with the name of the station you want to listen to. For example:

radio.py Radio Paradise
or
radio.py BBC3
To read more about radio.py, go to the first post discussing radio.py.

What’s New

Here are some of the things that have changed in radio.py-0.4 compared to the previous release (0.3). Continue reading radio.py-0.4 – Listening to Radio the Easy Way

Random – A Random Number Generator Class

After dealing with the seeding of srand(), I’ve realized that rand() just doesn’t generate random numbers that are strong enough for some of my needs (e.g. a strong password generator), so I decided to find a better solution. The solution came in the form of Random, a cryptographically strong pseudo-random number generator class.
Continue reading Random – A Random Number Generator Class

radio.py – a Wrapper Script for Listening to Radio in Linux

Download radio-0.3.tar.gz.

Update: radio.py-0.4 is now available.

I like listening to music and radio while working, and fortunately there are numerous ways to do that. Unfortunately, most ways that allow you to listen to radio are very resource-consuming memory hogs (such as listening to streaming media via web browsers) or very unfriendly to users (listening via mplayer, for example). So, I set out to find a way that would use as few system resources as possible while keeping it user-friendly. One other requirement I had was being able to do all that from the command line, so it would work great with GNU Screen and wouldn’t require an X server (if I worked without one).

I used mplayer for some time for listening to radio. I had a file with a list of web radio stream URLs, which I would copy and pass to mplayer -playlist. This method met two of the requirements (minimal resources and command-line interface), but wasn’t really user-friendly. So, I wrote a little wrapper script in Python around mplayer – radio.py. After a quick installation (download and extract the tar archive and copy radio.py somewhere in your PATH), radio.py will allow you to listen to stations easily, and it will also do a couple more things for you.

To listen to a station, just call radio.py with the station’s name; e.g., in the command line enter radio.py BBC1 to listen to BBC Radio 1. To view a list of known stations, run radio.py --list. Currently there aren’t many stations (just stations I thought were needed or that I listen to). You can easily edit radio.py to add new stations (the script is documented and very clear). If you do so, please write a comment or email me so I will be able to add those stations to the next release by default.

So, as you’ve seen, radio.py allows you to easily listen to radio, as easily as writing the station’s name. But, as I said, it can do more things that I thought should be in a radio script. It has both a sleep feature (that turns off the radio after a specified amount of time) and a wake-up feature (that starts the radio after a specified amount of time). These two features can be used together, and practically allow you to use radio.py as an alarm clock.

You can find more information about radio.py options by calling radio.py --help. I hope you will find this script as useful as I do.

Download:
radio-0.3.tar.gz.

Convert KDevelop’s Source Archive to a Source Package

I use KDevelop as my main IDE, and I’m pretty satisfied. KDevelop can create a source archive of the project’s source code automatically for you, which simplifies distribution of the project. Unfortunately, the archive created isn’t ready for distribution. The user can’t just run ./configure ; make, as they need to run all the automake tools first. That’s not ideal for distribution. So you need to convert this source archive to a source package that is ready for the user to compile immediately.

Continue reading Convert KDevelop’s Source Archive to a Source Package