Ken (Chanoch) Bloom's Blog

1st December 2009

Using git with wdiff

To configure git to use wdiff to compare files (which can be useful when working with text files that wrap differently even for small edits), add the following to .git/config

[difftool "wdiff"]
    cmd = /usr/bin/wdiff -l ${LOCAL} ${REMOTE} | less

Then you can use wdiff by calling

git difftool --tool=wdiff ...

Update Mar 17, 2009 Stefano Zacchiroli shared the git diff --color-words option, which does the same thing, but is a little less clunky in terms of how it uses th pager.

Permalink | linux.
12th December 2009

The Beit Yosef's Question about Chanukah

The Beit Yosef famously asked that since there Maccabees found enough oil to last for one day, then the fact that the oil lasted for 8 days isn't a miracle -- only 7 of the days are a miracle. Why then do we celebrate Chanukah for 8 days?

At our shul Chankah party tonight, there was a lot of excitement as we asked the kids to answer this question and they presented a lot of nice answers. One of these answers was that the 8th day is for berit milah.

My problem with this answer is that there are three mitzvot that the Greeks forbid the Jews from performing: berit milah, shabbat, and kiddush hachodesh. It seems odd that this answer singles out only one of these three mitzvot.

It appears to me however, that Chanukah's scheduling does hint to each of these mitzvot. Chanukah lasts 8 days long (as a reference to berit milah), it includes Rosh Chodesh Tevet (kiddush hachodesh), and it includes a Shabbat.

Permalink | torah.
29th December 2009

Tree Traversals in Scala

Just documenting an algorithm that I don't want to keep figuring out all over again every time I need it.

Supposing we want to perform a depth-first search of a tree in Scala, labeling each node with a number, and the number of its parent:

case class Tree(children:Tree*){
   var id:Int = -1
   var parent:Int = -1
}

def identify(parentID:Int)(myID:Int,tree:Tree):Int={
   tree.parent=parentID
   tree.id=myID
   tree.children.foldLeft(myID+1)(identify(myID)_)
}

Supposing we want to label the tree nodes with nested left-and-right keys, as well as the left key of the parent:

case class LRTree(children:LRTree*){
  var left:Int = -1
  var right:Int = -1
  var parentLeft:Int = -1
}

def identifyLR(parentLeft:Int)(myLeft:Int,tree:LRTree):Int={
   tree.parentLeft=parentLeft
   tree.left=myLeft
   tree.right=tree.children.foldLeft(myLeft+1)(identifyLR(myLeft)_)
   tree.right+1
}
Permalink | scala.
My Website Archives

Tags