Archive for June, 2005


I wanted to setup a counter for a friends web site, where all the logic is done in the SQL – the reason is that MySQL offers atomic updates (unlike some [read: most] RDBMS which I won’t name here), so I don’t need to lock anything- If I can do all the logic in one statement I get multi-thread safey for free :-).

In case I forgot to mention

My friend Elad is touring the world (Australia at the moment, south america later), and his travel blog is a really good read.

It sounds like he is having a lot of fun and encountering some interesting people, places and events.

Its not like I don’t know Ruby

Its not like I don’t know Ruby

I’ve read about Ruby a lot, and practiced with some code snippets and even started on a large app (some kind of management service with an XML-RPC frontend) – but I haven’t yet written something meaningful with Ruby, something that I can look at and say – “Ye, I can write Ruby real nice now”.

I had the same problem with Python for a while, then I sat down and ported my web-comics-strip-fetching application to Python (and a few other modifications such as a DB backend, split mails, CLI etc’).

When I got down and dirty for a while and came up with a gem – then I can say that I know how to program in Ruby.

Smallest base64 decoder

That I’ve written so far anyway. I’m sure its possible to write a smaller one using perl or maybe even C, but this is the smallest Java decoder I’ve seen.

	private final static char[] base64CharMap =
	private final static byte[] base64RevCharMap = new byte[256];
	static {
		for (byte i = 0; i < base64CharMap.length; i++)
			base64RevCharMap[base64CharMap[i]] = i;
	* Decode a base64 encoded data back into a byte array
	* @param text base64 decoded data
	* @return binary
	public static byte[] base64(String text) {
		if (text == null) return null;
		char[] chars = text.trim().toCharArray();
		int sind = 0, dind = 0, shl = 0;
		byte[] out = new byte[chars.length/4*3];
		while (sind < chars.length && chars[sind+1] != '=') {
			out[dind++] = (byte)
				( (base64RevCharMap[chars[sind++]] << (shl+2))
				| (base64RevCharMap[chars[sind]] >>> (4-shl)));
			if ((shl = (shl + 2) % 6) == 0) sind++;
		return Arrays.copyOf(out, dind);

Now I need to work on my encoder, which is both a mess and way too big, unlike the decoder above which is just a mess 🙂


Removed wisestring (which was stupid in the first place) in favor of returning a proper byte array. Also cleaned up some syntax.


In many situations (normally in buisness correspondance), an email discussion with the client needs to include many people from both sides. As long as everyone keeps replying to each other, its no big deal – the first person went to the trouble of adding all the required people and everyone else just “Reply All” eveytime.

This gets a little more complicated when you have something new to say which should belong on the same thread of an already active discussion, but still need to be delivered to the same people. You now have the option of either composing a completely new email and adding all those people by hand, or using “Reply All” and removing manually all the content of the old discussion before starting a new one. The problem with the latter method is that it does not remove headers that the email software would send on this particular eventulity, which include items to allow advanced mail user agents to understand context of discussions – who replied to who and when. Such email clients will display your new message as part of the original thread.

Kmail/Kontact offers a simple way to solve this problem: creating distribution lists is as easy as locating an email item containing all the people you want in your new list. Now just hit “Replay All” on that email and click “Save as list”. Type in a new name for that list and “Ok”. Now you can close the original email, and start a new clean composer in whose address bar you can start typing the name you just gave your new distribution list. The mail compose will of course help you by auto completion.

Internet Keywords anyone ?

Slashdot recently published another hit-n-run article about some kind of search-engine-come-social-application that defines keywords which you can use to quickly search web accessible databases.

What’s new here ? As many slashdoters noted – nothing much. Konqueror had that functionality like forever, Firefox has it after being imported from epiphany some time ago and even opera carries some basic keyword support. So why would I want to use a web site based keyword search ? oh. Maybe if I have Internet Explorer as my main browser. But then again I don’t.

כתום זה במקום רשות הדיבור?

יש עכשיו איזה מכתם שעושה את דרכו בדוא”ל, שכאילו טוען שמתנגדי ההתנתקות עושים צרות לכל העולם – חוסמים כבישים, מתקיפים אתרים, וכו’ – עושים זאת מתוך ביטוי לגיטימי לתסכול שהם חשים מכך שסותמים להם את הפיות.

כמובן שזה הכל בבל”ת: אנחנו עדיין גרים במדינה חופשית בה חופש הדיבור מובטח לכל אחד ובכל זמן. אף אחד לא מונע מאנשים, בעלי דעות אילו ואחרות, מלכתוב מכתבים, לפרסם מאמרים או כרזות בעיתונות, להפגין (בצורה מתורבתת מול משרדי הממשלה השונים), לתלות כרזות (מה שהם יודעים לעשות יפה מאוד – בעיקר במקומות בהם אסור כגון על תמרורי תנועה) ולבטא את עצמם ואת דעותיהם הפוליטיות בכל דרך לגיטימית.

אבל האנשים בכתום – יוק. הם נהנים להשתמש בכלים הדמוקרטיים הזמינים לכל אדם למטרות שלהם (ונגד כך אין לי טענות), אבל ברגע שהם מיצו את האפשרויות שהדמוקרטיה מציעה להם בלי להגיע לתוצאה הרצויה – שהרי בדמוקרטיה גם לרוב הדומם מגיע זכות הצבעה – אזי הם ממהרים לפרוק כל עול וחוק.

זה בערך כמו שאני אביע את התנגדותי לגזרות הכלכליות הניטחות עלינו חדשות לבקרים ע”י זה שאתחיל לשדוד חנויות מכולת. אני גם אצפה שיתייחסו אלי בסובלנות – הרי אני בסך הכל מביע את תסכולי מכך שסותמים את פי.

Spam prevention powered by Akismet