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.

Activating Guarddog Settings on Startup

Like many Linux users, I use Guarddog as a frontend to my iptables firewall. At some point, I noticed that Guarddog started acting strangely. Every time I restarted my computer, all internet traffic was blocked (both incoming and outgoing). The only way to fix this situation was to open Guarddog and press “Apply” (without making any changes). While it was annoying, it didn’t bother me much because I used to restart my computer about once a month. But a few days ago, I decided to solve this problem once and for all.
Continue reading Activating Guarddog Settings on Startup

Delete Unversioned Files Under SVN

Sometimes svn switch fails because unversioned files exist in the working copy, and the need to erase them comes up. This is also true when updating to an old revision (usually one that misses directories that exist in the head revision), doing some work (like compiling), and then trying to update back to the head revision. Subversion (SVN) will fail, complaining that directories/files already exist.
Continue reading Delete Unversioned Files Under SVN

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

Vim Macros for Wrapping Strings for Gettext

I’m working on a website, and we decided to localize it using GNU gettext. Soon enough, I found it tiring to wrap each string manually in _( and ), and also to do it in Smarty (using {t}string{/t}). So I decided that I needed a macro that would let me highlight the string that needs translation, and the macro would wrap it for me.

I ended up writing two macros: one for PHP files (but it’s also good for C/C++, etc.) and one for Smarty.

:vmap tg di_(<ESC>pa)<ESC>
:vmap ts di{t}<ESC>pa{/t}<ESC>

To use these macros, just highlight the string for translation in Vim’s visual mode and press tg (or ts), and your string will be wrapped for translation.

Multibyte String Truncate Modifier for Smarty – mb_truncate

When working with Smarty, a PHP templating engine, I discovered that while the regular truncate modifier works great on ASCII strings, it doesn’t work with multibyte strings, i.e., UTF-8-encoded strings. This leads to problems in internationalization (i18n), as UTF-8 is the popular encoding for non-Latin alphabets nowadays. The problem can be solved by modifying the built-in truncate modifier and creating a new one that takes an additional argument, the charset of the string, and acts accordingly. The new modifier, mb_truncate, is implemented below.
Continue reading Multibyte String Truncate Modifier for Smarty – mb_truncate

C’s “Goes To” Operator

Well, it isn’t really an operator, but this is a nice C code construct I ran into. It doesn’t seem to have any benefit except as a nice way to create a reverse loop:

int count = 100;
while (count-->0) {
        //some work
}

As I said, I don’t think I’ll find any performance benefit in using this code snippet. On the other hand, it is always fun to see the puzzled face other programmers have the first time they see the code.