Lebowtech Blog

Convert Existing Git Repo to Svn

| Comments

Git is great for starting a project quickly but the office uses svn. Here is how I add my existing git repository to a new svn repo.

make svn from git
1
2
3
4
5
6
7
svn mkdir --parents  svn://repo/trunk svn://repo/branches svn://repo/tags
git svn clone -sA authors.file  svn://repo
cd repo
git checkout -b trunk trunk
git rebase master
git rebase remotes/trunk
git svn dcommit

First thing we do is make the new svn repository.

Then clone into our existing git repository, repo

Next we checkout the trunk, and rebase our existing work onto it.

Now we move master to point back to trunk, and push changed to svn.

Convert TimeZones in Mysql Preserving DST

| Comments

When converting time zones with MySql you should use the method CONVERT_TZ so that it will automatically take into account DST ( Daylight savings time / שעון קיץ )

convert date preserving timezone
1
SELECT CONVERT_TZ('2013-03-29 12:00','America/New_York','Asia/Jerusalem');

This will convert a date in New York to our local time.

If you do not use this method and just subtract 7 hours from the time, you will have errors when we switch to and from DST.

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
1
2
3
4
5
6
7
from unidecode import unidecode
import os
#use 'u' to get unicode file names
for fn in os.listdir(u"."):
   print fn
   os.rename(fn,unidecode(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
1
2
3
4
5
6
7
8
9
10
11
12
>>> 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"יִשרָאֵל")
yishrael
>>> print unidecode(u"יִשׂרָאֵל")
yishrael
>>> print unidecode(u"נוּ")
nvv'
>>> print unidecode(u"לוֹ")
lvo

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.

1
2
3
4
5
<select>
    <option value="a">a</option>
    <option value="ab">ab</option>
    <option value="abc">abc</option>
</select>

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.

Octopress

| 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.

Shabbosalarm

| 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
end

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

# mail it off
mutt -a csvsAndPos.zip 

Hacked

| 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.

Enjoy!