juan_gandhi: (VP)
2014-12-11 11:42 am
Entry tags:

robustness

(from the log:)
Thu Dec 11 09:00:07 PST 2014(355) [Error]: Operation hung, called by Ops.scala[148]
Thu Dec 11 09:00:07 PST 2014(356) [Info]: Navigating to https://members.****.net/.Claims_portlet/eob/eob-processing.jsp?CLAIM_KEY=MED%XXXXXXXXXXXXXXX
Thu Dec 11 11:35:17 PST 2014(357) [Debug]: Ensuring div#viewer with ''
Thu Dec 11 11:35:17 PST 2014(358) [Debug]: waitSelector(<>, initialDelay=5000, timeout after 40000)


And it proceeds.
juan_gandhi: (VP)
2014-12-05 05:00 pm
Entry tags:

а вот и весь мой рендеринг

  def questionHTML(i: Int, q: String) =
    <span>
      <h3>Question {i+1}</h3>{q}
      <br/><br/><br/><br/><br/><br/>
  </span>

  def variantHTML(v: List[String]) =
    <p style="page-break-after:always;">
      <h1><center>{title}</center></h1>
      {v.zipWithIndex map {case(q,j) => questionHTML(j,q)}}
    </p>

  def html(variants: List[List[String]]) = {
    <html><body>{
      variants map variantHTML
    }</body></html>
  }
juan_gandhi: (VP)
2014-12-05 03:53 pm
Entry tags:

навалял в духе проекта Эйлер

Короче, есть, скажем, пять вопросов для экзамена, каждый в нескольких вариантах; задача - изготовить варианты, чтобы они максимально различались. Ну типа всех возможных будет 55, а мне надо 27, ну вот взять первые 27 из таких.

С таким смаком навалял это на скале. Типа такого:

    def findFurthest(current: List[Index])(collection: List[Index]) = collection.map(i => (distance(current)(i), i)).max(order)._2

    def sortByDistance(source: List[Index], target:List[Index] = Nil): List[Index] = source match {
      case Nil => target
      case more => {
        val furthest = findFurthest(target)(source)
        sortByDistance(source.filterNot(furthest==), furthest::target)
      }
    }

    val sorted = sortByDistance(allIndexes).reverse
juan_gandhi: (VP)
2014-12-01 04:54 pm
Entry tags:

casual currying

no oop

I wanted this:
  def from(location: String) = {
    def loadTable(name: String, ignoring: String*) {
      def ignoringColumns(row: String Map String) = row.filterKeys(k => !(ignoring contains k))
      val src = Source.fromFile(s"$location/$name.csv").getLines().mkString("\n")
      
      val data = parseText(src) map ignoringColumns

      insertInto(name, data)
    }
  }


But has to write this:
  case class from(location: String) { self =>
    def loadTable(name: String, ignoring: String*): from = {
      // actually, the load order is opposite to deletion order    update(s"delete from $name")
      def ignoringColumns(row: String Map String) = row.filterKeys(k => !(ignoring contains k))
      val src = Source.fromFile(s"$location/$name.csv").getLines().mkString("\n")
      val data = parseText(src) map ignoringColumns toList

      insertInto(name, data)
      self
    }
  }


Using it like this:

  from(location).
  loadTable("users").
  loadTable("abusers","historyOfAbuse").
  loadTable("WMD","rocks","stones").
  loadTable("passwordAndKeys")
juan_gandhi: (VP)
2014-11-26 11:17 am
Entry tags:

map3-like

Guys,

If I introduce
 def mix[X1,X2,X3](r1: Result[X1], r2: Result[X2], r3: Result[X3]): Result[(X1,X2,X3)] = {
    (r1,r2,r3) match {
      case (Good(x1),Good(x2),Good(x3)) => Good((x1,x2,x3))
      case (b1,b2,b3)                   => bad(b1, b2, b3)
    }
  }

So that instead of ((a,b),c) <- result1 andAlso result2 andAlso result3 we could write (a,b,c) <- mix(result1,result2,result3)

Do you think mix is a good name? Other alternatives would be ‘blend’, ‘join’…
It is similar to map3 in Haskell, but map3 comes from lambda, and it also applies a function.

I'll have it for a bunch of ns, not bothering with macros yet.
juan_gandhi: (VP)
2014-11-21 11:07 am
Entry tags:

scala question

I wonder if we can have an implicit isomorphism of tuples, so that, say,

val (x,y,z) = ((x0,y0),z0) would involve the right transformation.

Would Be Cool.
juan_gandhi: (VP)
2014-10-29 01:01 pm
Entry tags:

some new code

  val _1:Unit = ()
  val _0: Nothing = ???

  case object None extends Maybe[Nothing] {
    override def ¬ : Maybe[Nothing] = Just(_0)
...
juan_gandhi: (VP)
2014-10-25 12:28 pm
Entry tags:

figuring out...

So, I kind of discovered that the stuff I'm doing with my Result class looks suspiciously close to linear logic, e.g., in LL we have !(A&B)≡!A⊗!B, and I have Good(a) <*> Good(b) == Good((a,b)).

Moving on.

Similarly, there's some connection between Good[Either[A,B]] and Good(a:A) orElse Good(b:B).

Actually, what I have, it seems to be a coaffine logic, but well, who cares right now. We will see.

"If Γ,Δ⊢Θ, then Γ,!A,Δ⊢Θ, for any A " maps to

Good(a) foreach (f()) is the same as f().

"If Γ,!A,!A,Δ⊢Θ, then Γ,!A,Δ⊢Θ" maps to
Good(Good(a)).flatten == Good(a)

Not everything works. But is not it weird.
juan_gandhi: (VP)
2014-10-23 01:16 pm
Entry tags:

DoggyEnglish

object DoggyEnglish {
  val meaningless = Set("name", "of", "the", "my", "your", "in", "what", "which", "was", "is")

  val synonyms = Set("city, town", "sibling, siblings", "job, work") .map {
    word => word.split(", ").toList
  } .collect {
    case main::tail => tail map (w => w -> main)
  } .flatten .toMap withDefault identity


  def simplifyQuestion(question: String) = {
    val noPunctuation = question.toLowerCase.replaceAll("[^a-z ]", "")
    val words = noPunctuation split " "
    val meaningfulWords = words filterNot meaningless
    val standardized = meaningfulWords map synonyms
    standardized mkString " "
  }

}
juan_gandhi: (VP)
2014-10-18 06:32 pm
Entry tags:

funny stuff worth reading

http://dreamsongs.com/Files/worse-is-worse.pdf

Those were the days when I was debugging into the microcode of a stupid machine from Severodonetsk, which was losing interrupt stack trace from time to time, and so we were out of luck: I did lose some significant money on trying to fix this, but figure it was theoretically impossible.

Anyway, the source of inspiration is this: http://pchiusano.github.io/2014-10-13/worseisworse
juan_gandhi: (VP)
2014-10-16 01:54 pm
Entry tags:

named tuple

Looking for a way to have and pass around named tuples, I'm kind of coming to a conclusion that this belongs to dependent types, roughly speaking. Or? Of course I'm only interested in Scala.
juan_gandhi: (VP)
2014-10-15 04:12 pm
Entry tags:

just found a bug

I had a function checking if a collection of sets (of keys) has any common elements (if they do, have to add prefixes to the keys, to disambiguate). Imagine, I was just calculating their intersection. OMFG, in short.
juan_gandhi: (VP)
2014-10-12 02:00 pm
Entry tags:

one specific isomorphism

implicit def flatten1[A,B,C]:(((a:A,b:B),c:C)) => (a,b,c)
implicit def flatten2[A,B,C]:((a:A,(b:B,c:C))) => (a,b,c)


Of course we cannot seriously count on applying it implicitly to all kinds of tuples, but still... It's an isomorphism.
juan_gandhi: (VP)
2014-10-10 05:23 pm

a pretty interesting suggestion

I have an applicative Result class.

Result[A] <*> Result[B] gives a Result[(A,B)].

Now Csaba, who does not like this ascii soup, and does not like the phrase "tensor product" either (do you see tensors around here?) suggested to call this construct 'andAlso'.

I like this idea a lot.

  for ((name, dob) <- findValue(html, “user”) andAlso findValue(html, “date of birth”))
juan_gandhi: (VP)
2014-10-09 11:14 am
Entry tags:

NPE in Scala

I'm REALLY tired of them.
juan_gandhi: (VP)
2014-09-14 07:48 am
Entry tags:

wired funny

http://www.wired.com/2013/09/the-second-coming-of-java/all/

What I read here:
- Java's back
- Twitter uses Java
- Java is the fastest
- Bob Lee sees no choice
- Medvedev visited Twitter office 4 years ago

Any ideas what it was about?
juan_gandhi: (VP)
2014-09-10 08:17 pm
Entry tags:

akka

Sitting at SF Scala listening to Jonas Boner's talk. First I was absolutely impressed. Then Sergey W told me, wtf, no definitions, just vague talk. Kaboom.

Now I think I'm not much interested in Akka actually. Seems like a sleazy bs; and if you want to model pi-calculus, use Erlang.
juan_gandhi: (VP)
2014-09-06 11:08 pm
Entry tags:

here "about categories"

my 6 chapters, math for programmers, categories from start to adjoints, with code samples in Scala.

Probably it's hard to read, formatting problems. Let me know if it's totally unreadable. Or if you think something should be fixed.

(updated)
http://orm-atlas2-prod.s3.amazonaws.com/pdf/455a990ff6b670a08f0ab9365538d284.pdf