Thursday, February 26, 2009

Siddur for Blackberry Storm

This one is going to be short.

My friend recently asked me to help find Siddur for his new Blackberry Storm (he got it at work).

I am not familiar with Blackberry so I will just dump my findings:

First you may need to set up/fix Hebrew on Storm:

Resource 1:
It includes: Chumash, Tehillim, Rambam, Siddur, Targum, Mishnayos, Gemara / Talmud, Shulchan Aruch and much more for your BlackBerry.

Check out the instructions and desktop installation files at this link:

The installation files are also available OTA from your BlackBerry at:

PS. it's interesting to see how nusach Ari goes on the first place and Ashkenaz goes last one after three others...

Resource 2:
ASiddur is a siddur written in J2ME. This allows it to be used on many cell phones, Blackberries, Palm and Windows Mobile PDAs (with some extra software installed). When development is finished, ASiddur will be able to infer the correct text of each tefilla based on the date.

Download: (you will want a development version since it has scrolling fixed for Storm)

Monday, February 23, 2009

Translate and format phone number with PHP

Prior to writing some function that I plan reusing in couple of different places I often do a research at how other people solve my problem. Sometimes it saves time by giving an easily modifiable and customizable piece of code, sometimes shows how not to do, sometimes just lets me know where my personal solution would've failed and how to fix it.
Also my memory is not very good so I often forget functions I rarely use or haven't used at all but read it's docs.

This one got me really frustrated that most of solutions I've seen within first 3 or 4 pages on Google and with couple of different search queries (all together I saw over 50 solutions including identical) were written in a very long form, which did not add functionality to the code but even made it more limited for different variations of phone number 'spelling'.

In USA phone number can be at least written in these forms and there will be many other ways that I didn't think off (why am I supposed to think of every way phone number could be spelled if I am writing a universal function??):

+1 (800) 282-8623
(800) 282 - 8623

May be I was searching wrong but I didn't find a short all in one universal solution. I didn't find a solution that would be shorter than mine. But main thing that I didn't find was converting branded phone number (i.e. to it's numeric representation. Obviously I knew I can do it with a simple enough RegEx but I hoped I will see how other people do it.

So here's what I've got in the first place:

function _format_phone ($phone) {
$regex = array('/[^0-9A-Z]/i','/[ABC]/i','/[DEF]/i','/[GHI]/i','/[JKL]/i','/[MNO]/i','/[PQRS]/i','/[TUV]/i','/[WXYZ]/i');
$replace = array('',2,3,4,5,6,7,8,9);
$new_phone = preg_replace($regex,$replace,$phone);
if (preg_match("/^[1]?[2-9][0-8]\d[2-9]\d{2}\d{4}\d*$/",$new_phone)) {
return preg_replace("/^[1]?([2-9][0-8]\d)([2-9]\d{2})(\d{4})([0-9]*)$/", "$1-$2-$3", $new_phone);
} else {
return $phone;
function _format_phone ($phone) {
$new_phone = preg_replace('/[^0-9A-Z]/i','',$phone);
$new_phone = strtr($phone,'abcdefghijklmnopqrstuvwxyz','22233344455566677778889999');
if (preg_match("/^[1]?[2-9][0-8]\d[2-9]\d{2}\d{4}\d*$/",$new_phone)) {
return preg_replace("/^[1]?([2-9][0-8]\d)([2-9]\d{2})(\d{4})([0-9]*)$/", "$1-$2-$3", $new_phone);
} else {
return $phone;
Well, after bashing other solutions I accept that my solution is not ideal either. At least I'm concerned about IF statement containing check for RegEx while using preg_replace() twice. However I think it's much more functional and shorter than many others at the same time. At least in 7-8 lines it provides more functionality:
  • Cleanup all formatting characters
  • Translate letters to numbers
  • Format phone number to desired standard (very customizable)
  • Fail silently by returning original phone number if something went wrong

TinyURL with one line of PHP? Easy!

Everyday we learn something new. For programmers it's especially important so that we don't sour and stink like a month-old milk.

Yesterday I was looking for a better (read cleverer) solutions to build a TinyURL analog. Everyone find his own need to build such a service, I needed it to be able to share URLs in SMS (text messages), track usage and statistics and be independent from 3rd party solutions such as (one rule I learned at my job - you can't rely on anyone - even google may go down while you're up and your service should not be interrupted).

So saying that much I'm pushing away the solution which is really one line of PHP! To convert URL to it's short representation you need:
$short_url = base_convert($url_id, 10, 36);
To convert short URL to it's original you will need:
$url_id = base_convert($short_url, 36, 10);
This will return a numeric id of the long URL stored in the DB with following structure:
`id` int(11) NOT NULL auto_increment,
`url` text NOT NULL,
Obviously you will need little bit more lines of code to provide some type of interface for your application, but it's main part is done by magic of base_convert() function which converts regular decimal number (base 10) to base 36 which uses letters of English alphabet as additional digits.

And if you are so lazy that you can't even think about writing your own application utilizing provided function or you trully believe in Open Source - I also found a full listing of such application for you.

Just to break the silence

Unfortunately these days are pretty busy and I can't find a good moment to bring my thoughts in a right order and dump them here.

Anyways here's a short recap of past three weeks:
  • Week of Shabbos B'shalach:
    • My friend got a mouse. Real one. She waited for it for a while and sounded happy!
    • I finally happened to get out of town!!!! After a year or even more... Went to Perth Amboy and enjoyed it very much. Will use next opportunity to go there again!
    • Going to Perth Amboy involved taking train (not the subway) and this is something that I enjoy from only one thought about it. Almost missed my stop 2 hours before Shabbos...
    • Watched Coraline. Enjoyed. And had a thought that if we were looking for some new trend happening around us (like radio, phones, TVs, PCs and cell phones in XX century) then Coraline is definitely part of it. You would ask how? There's a new trend of movies coming which is made cartoonish but not for kids. And 9 will prove my theory [although I am linking to it's preview you'd better to watch it in the movie theater to get better emotions about it]. And one of the better sides of this very new trend is that it's not centered on scenes with sex which every regular movie today is just a must have. Tiring...
    • My mom went to Israel for the first time in her life!!!
  • Week of Shabbos Yisro:
    • Can't recall anything significant now
    • Found this video and find it amazing!
  • Week of Shabbos Mishpatim
    • Second OT! This time to Monsey. Went with my friend. Went to two families for seudos and both of them were great. Gave us (at least me) a lot of good emotions.
    • On motzey Shabbos we went to: New Square (Rebbe's Tish), Schmuz at Ohr Samayach (this one I enjoyed a lot) and Kiryas Joel (however we came there at 11 and didn't know where to go; we asked some chossid if there's any place to eat and he said probably everything is closed; so we didn't really see the town)
So that was a short recap of my social part of life. Now I'm planning to post one or two technical posts on my recent findings.

Sunday, February 15, 2009

BTS's view and reply on “Goyish” Music, TV, and Movies by Babysitter

This was supposed to be a simple comment on Babysitter's post, but at some point I realized it's to big for a regular comment and is good enough to posted as a reply in my blog. Especially after I didn't write here for a long time it was a good chance to fix this issue.

So Babysitter was writing about her views on non-jewish music, movies and TV. She's an FFB (not to hurt any one's feelings) and I wanted to add my 2 cents as BT.

So here's a copy of my reply:


From a BT point I'm more accustomed to non-jewish music. I should bring that at the age of 3 I knew AC/DC is playing on radio from first to second accords. Don't remember this myself but my brother recently told me this.

Anyway I think for the amount of non jewish music I listen to compared to jewish one I have more against jewish. Here are my points:

1) I hate these modern remixes of non-jewish music where new words were put up to make it sound jewish. It cuts my ears since I knew all this stuff in original. I know that our old Rabbeim used to take non-jewish music and that's how we have lots of nigunim today, but I would not compare Rabbeim of 200 years ago to people who of today's who try to kosher non-jewish stuff to make it appropriate for less modern masses. At some point I dreamed of finding some heavy metal styled jewish music but later I changed my point to "if you say that's tuma don't put it in a kosher pot". Though, I still appreciate open use of guitars on Shwekey's CDs (take Wedding Album for example).

2) As I mentioned before I trust to Rabbeim of 200 years ago who didn't write any songs for money. Today it's not that clear so many "inspirational" just doesn't make a cut for me since I don't know who wrote this, what was on in his mind at that moment, what was in his blood at that point (rare cases I guess) and how much of tzadik his is for the words in the lyrics. So most modern stuff is cut off for me except of Just One Shabbos and couple of others.

3) [this is not anti-jewish reason] I listen to goyishe music for my entire life, I grew up on it and there were days when it helped me survive through my long lasting depression. Today it is something irregular to see me without headphones or have my music turned off, however today often music for me is just a wall around myself which lets me concentrate on things I'm doing and forget about things around; I often don't pay attention to what exactly plays in my ipod and what words are being sang. Plus I know most of music (not exactly lyrics) in my ipod by heart.

I happened to share these views with one girls I was on shidduch with and then she said no. It is something very personal and doesn't have to be always shared with others as I learned.

As of my kids - I really don't want them to listen to crap I listen to so I understand at some point I will have to sacrifice most time of listening to it for my kids not take example of me.


Can't say anything particular about TV, since I didn't watch TV much after I got PC at 13 so can't say much. If this is allowed to kids it has to be explicitly monitored as there's less of safe stuff on TV today than things that just dump tons of spoiling dirt on people watching it. I happen to come to my friends house sometimes and she always has TV on so I can catch some things going on there.


Movies. Should be judged on per item basis. What I learned is that movies for teens dirtier than any movies for adults. Seriously. Adult movies usually concentrated more on certain idea than bed scenes and such stuff.

For example I have a friend who is also FFB but comes from a russian BT family which is probably not as strict as pure muli-generational FFB families. She goes to movies and Broadway shows sometimes.  She has a personal view on many things and more into serious stuff than into teenagers' interests. She loves Johny Depp, Alan Rickman, Adrien Brody and many other charismatic characters.
So looking at her I can't say she's got spoiled anyhow by movies she watched.

Don't think I was spoiled much by movies either, although I for sure watched less movies than her. I watched American Beauty when I was about 13 and re-watched it recently, watched couple of American Pies about 5 or 7 years ago. That didn't add much to my spoilness either.
Yes, I should admit I was more opened to many things that happen in a non-frum world during my teen age than most of FFB boys and girls, but if they watch movies except of type of mentioned here and in the Babysitter's post I don't believe there will be lots of harm.