2011-01-24

juan_gandhi: (Default)
2011-01-24 11:46 am
Entry tags:

inheritance: is circle an ellipse?

It's a known puzzle from the depths of object-oriented teaching: is Circle a subclass or Ellipse. From school we know it is; but as we read in books, for programmers, it is not. How come? Oh, "Liskov principle". They use Liskov principle to scare kids.

Actually we know that a circle is an ellipse with both axes being the same length.

But in programming, an ellipse is something different. It is at least stretchable. And it is also moveable. Somehow it is not rotatable, but we can skip it for simplicity.

An ellipse in programming is (almost) always horizontal; it can be moved (by changing coordinates of its center) and it can be stretched/compressed by changing its height and width. Sure a stretchable ellipse is neither an ellipse nor a circle, not even a stretchable circle. A stretchable circle stretches equally in all directions.

That's it, no? Questions? Objections?
juan_gandhi: (Default)
2011-01-24 02:50 pm

23andme

Получил результаты.

Во-первых, выглядит жульничеством. Я им послал 4 с половиной гига данных, а они мне в ответ едва ли килобайт надыбали.

Но зато, зато выяснил, что я чистокровный европеец. :р

Теперь как-то неудобно не записываться белым. Буду теперь белым, хуле. Грех от собственных генов отрекаться.

Я знал одного физика, который, на волне перестройки, вдруг оказался поляком, потом перекинулся в немцы, потом обернулся евреем, а когда и из этого ничего не вышло, стал наконец русским патриотом.

Я думаю, один из читателей моего жж ему это не преминет передать, в ближайшие же дни - так передай же ему, Лёва, ещё, что я его всё равно уважаю, будь он хоть бы и негр преклонных годов.
juan_gandhi: (Default)
2011-01-24 04:52 pm

mysql wtf

I'm trying to drop a foreign key constraint on a 6-mil table; after an hour I dropped the effort. Now it seems like this specific foreign key does not have an index, maybe that's why. So now I've created an index, and trying to do it again...

On the other hand, my colleagues come up with a revolutionary idea: for the data that is readily available cached in memory, there may be no need to have this constraint. Check it in the code, on the fly. Retrieve the data on the fly, from the cache, too. Sounds weird but convincing.
juan_gandhi: (Default)
2011-01-24 10:32 pm

the simple thing I missed in Scala

  def bytes(is: InputStream) : Iterator[Byte] = new Iterator[Byte] {
    def hasNext = is.available > 0
    def next = is.read.toByte

  def isText(b: Byte) = b == 0x0a || b == 0x0d || b >= 32 && b < 0xff

  def chars(is: InputStream) = bytes(is) filter isText map (_.toChar)



So that I can use it like this:
  def main(args: Array[String]) {
    val is = new FileInputStream(args(0))
    for (c <- chars(is)) print(c)
  }


(that's monadic, kind of)