Lebowtech Blog

Transliterate With Python

| Comments

I bought my kids a new CD player that also takes a USB drive with MP3 files.

The problem is that many of the file names are in Hebrew and the MP3 player can’t read Hebrew file names, it just shows up as XXXXXXXXXXXXXX.mp3 and that’s not very helpful.

I found a nice module for python that transliterates Unicode to ASCII, I believe using Iconv,Unidecode.

The installation was straight forward. The tests failed, but the module seemed to work anyway.

Convert all filenames in the current directory to ASCII from Unicode
from unidecode import unidecode
import os
#use 'u' to get unicode file names
for fn in os.listdir(u"."):
   print fn
   print fn

One catch was how to get the file names in Unicode. Using the path name for listdir as Unicode, gets the file names in Unicode.

Works decent, but not 100%. I’m not sure who set up the transliteration rules but we get some funny results, for Hebrew at least.

converting unicode strings
>>> print unidecode(u'בוקר טוב ילדים. מה נישמע מה שלומכם? אנחנו תמיד אמרים ברוך ה')
bvqr tvb yldym. mh nyshm` mh shlvmkm? nkhnv tmyd mrym brvk h
>>> print unidecode(u"щи да каша – пища наша")
shchi da kasha - pishcha nasha
>>> print unidecode(u"יִשרָאֵל")
>>> print unidecode(u"יִשׂרָאֵל")
>>> print unidecode(u"נוּ")
>>> print unidecode(u"לוֹ")

Still more informative than XXXXXXXXXXXXXX.mp3.

Jewish Month Length Mnumonic

| Comments

If you want to find out if a month is Male (30 days ) or Chaser ( 29 days ). Start counting from Nisan and the month number plus the number of days in the month will always be odd, like a parity bit

Nisan(1) + 30 = 31 //odd
Iyar(2)  + 29 = 31 //odd
Sivan(3) + 30 = 33 //odd

This works for a regular, Kseder year.

For a leap year, Adar 1 is 30 , and Adar 2 is 29, so here you can find the length of Adar n, by using a modified parity bit rule.

 Adar (1) + 30 = 31 //odd
 Adar (2) + 29 = 31 //odd

The only thing this doesn’t cover is Chesvan and Kislev, because they change depending on if the year is Male or Chaser, and that is a much more complicated calculation.

Jewish Leap Year Calculations

| Comments

The Jewish calendar has a 19 year cycle, where Years 3, 6, 8, 11, 14, 17, and 19 (גוחאדז”ט) are leap years (מ), they have a second Adar. The other years are Pashut, simple years with only one Adar.

Obviously we can calculate the position of the current year in the cycle by doing mod 19.

5773 % 19 == 16 ; // This year is pashut, but next year is a leap year.

How can we write a single equation that we can use to test if a year is a leap year or not.

There is a solution on Wikipedia, but I’m more interested in the process than the final answer.

Delay Ajax on Selects

| Comments

Recently I made an application that would reload the data via AJAX when data in a form was changed, standard stuff. The submit action of the form was connected to the AJAX request and the form elements have their onChange action submit the parent form.

A strange issue that we noticed was when using select elements. If you tab to one of the elements and start typing the select box will change to the option that matches what you started typing.

    <option value="a">a</option>
    <option value="ab">ab</option>
    <option value="abc">abc</option>

If you were to type abc the browser would change the value of our select box first to a then ab then abc, each time firing our form’s AJAX submit each time. You can see how this can add unneeded stress requests to the server, especially if you have a lot of options in your select tag.

The solution that we came up with is to insert a delay before firing the submit action when we are dealing with the onchange handler for selects.


| Comments

So now I’m switching my blog format again, this time to Octopress.

I like the fact that it lets me post in markdown, but my old HTML posts, left over from Joomla days, still work.

Getting it set up was pretty simple and I can post by pushing my changes to a git repository, forcing me to commit often.

It’s based on Jekyll and very robust. In the passed, my dynamic sites got hacked on dreamhost, so anything that creates static content is a plus.


| Comments

So this is going to be my first app that I plan to subbmit to the iTunes store. It is something that I missed from my old treo, you could tell the alarm how many times to repeat its self, that means that it won’t keeping ringing for hours on shabbos morning ( or when I forgot my phone at home ).

My app will create weekly alarms that will ring for a few times then quit.

Aditionally it shows a clock with the hebrew date, and the touch screen will not respond to touches when the alarm is firing, to limit chilul shabbos.

I hope to add some screen shots and submit to appstore soon.

Count Words in Html Files

| Comments

We created a new translation system for a project where we are using html files that will be then sent off for translation. This allows us to make changes to the layout if needed to fit a specific language.

The translation company needs to know the word count to give us a price quote, and we don’t want then to take into account the tags.

Here is a one-liner in fish shell that should get the word count for all the .phtml files.

cat (find . -iname "*.phtml"  ) | w3m -dump -T text/html  | wc -w

In bash you would probably replace the parens with backticks.

Also we are using PO files for short text throught the site. The translator we are using doesn’t know how to work with po files. So we used po2csv to create them files that they can open in a spreadsheet, although it makes me wonder what type of translation company can’t use po files.

Here is som fish shell code to make the csv files and bundle them into a zip and send them off:

# for each lang directory make a csv dir and put the new csv's in there
for lang in ??
    ehco $lang
    mkdir $lang.csvs
    po2csv $lang $lang.csvs

# zip up our csv and po files
find -name "??_messages.*" | sort | zip csvsAndPos -@

# mail it off
mutt -a csvsAndPos.zip 


| Comments

I’ve been hacked!!

So my joomla site was hacked. No real damage done except that I was marked as malware on google.

So here is my replacement for now.


Headup Safari Extension

| Comments

HeadUp adds tool tip type info to key words.

This extension will add the headup script to every site that you visit.

Note: You wont see the links the first time you visit a site, try reloading the page after a few min.


Problems After Upgrading to 10.6

| Comments

Date: 8th of Cheshvan, 5770

Keywords: OSX SnowLeopard Upgrade


I was using the Zsh Osx templates and after the update nothing seemed to work, and it didn’t even seem to be reading my .zshrc file either.

I tried installing the SVN version from the google site, but that didn’t work.

What did work was that I moved my .zsh dir and .zshrc file to a backup location and reinstalled from the tarball. Then I was presented with the nice config dialogs.

Then I moved my old stuff back into place

~> cp old/.zshrc .zshrc 
~> source .zshrc 
~> cp old/.zsh/zshprompt .zsh/zshprompt 

Text Mate

The mate command stopped working for me , but after fixing zsh , it works again.


So PHP 5.3 comes with OSX 10.6 ! That would be excelent except that nothing works !!

Time zones


had to reinstall 5.2.10 using my instructions …

but add EXTRA_CFLAGS="-lresolv" make -j2


And it looks like I have a problem with GD , so needs to be built with out gd

CFLAGS='-arch x86_64' ./configure  \
            --without-iconv  \
            --with-apxs2  \
            --enable-pdo  \
            --with-zlib=/usr \ 
            --with-curl  \
            --with-mcrypt \
            --with-pdo_mysql=/usr/local/mysql/bin/mysql_config  \
            --with-mysqli=/usr/local/mysql/bin/mysql_config  \
            --with-mysql=/usr/local/mysql   \
            --prefix=/usr  \
            --without-mcrypt -mandir=/usr/share/man  \
            --infodir=/usr/share/info  \
            --with-apxs2=/usr/sbin/apxs  \
            --with-config-file-path=/private/etc  \
            --sysconfdir=/private/etc  \
            --enable-cli  \
            --enable-ftp  \
            --enable-mbstring  \
            --enable-mbregex  \
            --enable-sockets  \
            --with-ldap=/usr    \
            --with-mime-magic=/etc/apache2/magic  \
            --with-zlib-dir=/usr \


after recompiling JPEG libs I recopiled php adding the following options.

--with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/X11R6


look here for apple’s patch

PHP 5.3.0 on Mac OS 10.6 (Snow Leopard)

diff -Naur php-5.3.0/ext/iconv/iconv.c php/ext/iconv/iconv.c
--- php-5.3.0/ext/iconv/iconv.c        2009-03-16 22:31:04.000000000 -0700
+++ php/ext/iconv/iconv.c          2009-07-15 14:40:09.000000000 -0700
@@ -51,9 +51,6 @@
 #include <gnu/libc-version.h>

-#undef iconv 

 #include "ext/standard/php_smart_str.h"
 #include "ext/standard/base64.h"
@@ -182,9 +179,6 @@

-#define iconv libiconv

Still missing TTF


Hebrew dates.

I use hebrew dates on my OS and it worked fine , but now mails in my exchage box are getting wired dates. This is only happening in the message listing pane, but in the message view pane that date is fine.

Turns out it isn’t a problem with hebrew dates, I have the same issue with gregorian dates :(.

I moved my ~/Library/Mail folder and let Mail rebuild it , and that didn’t work …

I switched to using my old IMAP setup for this exchange account and it seems to work now .

Make not found..

Trying to install Xcode …