Jan. 24th, 2011

juan_gandhi: (Default)
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?

23andme

Jan. 24th, 2011 02:50 pm
juan_gandhi: (Default)
Получил результаты.

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

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

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

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

Я думаю, один из читателей моего жж ему это не преминет передать, в ближайшие же дни - так передай же ему, Лёва, ещё, что я его всё равно уважаю, будь он хоть бы и негр преклонных годов.

mysql wtf

Jan. 24th, 2011 04:52 pm
juan_gandhi: (Default)
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)
  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)

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 1920 21
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 27th, 2025 07:30 pm
Powered by Dreamwidth Studios