juan_gandhi: (Default)
2017-05-20 09:02 pm

кстати о языцех

Джавасприпт, Хаскель и Скала, и, говорят, OCaml, из-за своей компактности, канают в качестве скриптовых языков.

Питон в этом смысле тоже ничо, но там, во-первых, споткнуться можно много где, во-вторых, на уровне компиляции нам ничего не скажут. Это уже на продакшене ебанется. То-то квора, которая на питоне, деплоится по сто раз в час (а тесты потом гоняют, и кодревью тоже). 
juan_gandhi: (Default)
2017-05-07 01:59 pm
Entry tags:

is this the right tool?

...for running linear algebra stuff on gpu?

github.com/deeplearning4j/nd4j - for Java
github.com/deeplearning4j/nd4s - for Scala

Judging by the title, got a feeling that yes.
juan_gandhi: (Default)
2017-04-06 04:03 pm
Entry tags:

is not it too much

        val counts = ((0 until 3 map (_ -> 0) toMap) /: (0 until something.length.toInt)) {
          case (c, i) => {
            val k = something.at8(i).toInt
            val v = c(k) + 1
            c + (k -> v)
          }
        }


Just counting. It's a piece of a test, so...
juan_gandhi: (Default)
2017-04-01 10:43 am
Entry tags:

в стиле Леся

einführen language.ukrainian

об'єкт  Прикладення
{

  визначити головне(аргументи: массив стрічок): Пусте =
     надрукувати "Привіт, світ" 

} 
src
juan_gandhi: (Default)
2017-03-24 12:15 pm
Entry tags:

у нас в скальном митапе...

завелся новый член, Хуй Ли.

Мне нравится. 
juan_gandhi: (Default)
2017-02-09 12:49 pm
Entry tags:

update on "FP performance"

Turned out all the delays were caused by two things:
- reading the files in parallel, as opposed to sequential (don't ask, will investigate)
- parallel output to stdout, instead of linearising the output. That was obviously my mistake, have to group the data, not mix them.

Now it's still 3 times faster than FP version. Got a suspicion that in JVM method dispatch is much heavier than plain if/else. It should be. But it's the staple of FP, never use booleans or ifs, but dispatch by the type. So, well... have to investigate.
juan_gandhi: (Default)
2017-01-31 03:04 pm
Entry tags:

in case you are interested in Spark...

    // Set name from main class if not given
    name = Option(name).orElse(Option(mainClass)).orNull
    if (name == null && primaryResource != null) {
      name = Utils.stripDirectory(primaryResource)
    }


Just a chunk of their funny shitty code.

FYI, var name: String = null

I'd rewrite all that crap, but it's not only code, I'm afraid. It's the whole Spark world that needs a doctor.
juan_gandhi: (VP)
2016-12-14 08:13 am
Entry tags:

funny scala puzzle (easy)

case class a(i:Int)
{
  override def canEqual(a: Any) = a.isInstanceOf[a]

  override def equals(o:Any) = AnyRef.equals(o)

  override def hashCode = AnyRef.hashCode
}

val aa = new a(1)
aa == aa //false
juan_gandhi: (VP)
2016-12-07 08:06 pm
Entry tags:

got an epiphany

You know the difference in Scala between val f: A=>B and def f(a:A): B?

I do.

The first one is a point in BA; the second one is an arrow from A to B. Yes, there's an adjunction, so there's a 1-1 correspondence; it's basically a special case of currying.
juan_gandhi: (VP)
2016-10-27 11:33 am

слайдов налепил

Categories for Scala Programmers

Pretty primitive, but well, the target audience... just to dispel some myths and clear the people's conscience.
juan_gandhi: (VP)
2016-10-15 04:23 pm
Entry tags:

ct4scala

Just slapped together a deck of slides, category theory for scala programmers

http://tinyurl.com/ct4scala

Comments wholeheartedly welcome
juan_gandhi: (VP)
2016-09-27 09:33 am
Entry tags:

чудесная нотация

В документации по спарку увидел
transformer: DataFrame =[transform]=> DataFrame

Ни хрена не мог понять, а потом понял и шибко оценил. Классно же! Жаль, нельзя так по жизни. Очень жаль.
juan_gandhi: (VP)
2016-09-26 03:42 pm
Entry tags:

spark masterpieces

  /**
   * Returns a Seq of the children of this node.
   * Children should not change. Immutability required for containsChild optimization
   */
  def children: Seq[BaseType]

  lazy val containsChild: Set[TreeNode[_]] = children.toSet


Imagine, we override the class, but our children are not to be mutable. Why t.f. then not declare it val?!

Another masterpiece
object CurrentOrigin {
  private val value = new ThreadLocal[Origin]() {
    override def initialValue: Origin = Origin()
  }

  def get: Origin = value.get()
  def set(o: Origin): Unit = value.set(o)

  def reset(): Unit = value.set(Origin())

  def setPosition(line: Int, start: Int): Unit = {
    value.set(
      value.get.copy(line = Some(line), startPosition = Some(start)))
  }

  def withOrigin[A](o: Origin)(f: => A): A = {
    set(o)
    val ret = try f finally { reset() }
    reset()
    ret
  }
}


So, we have a static object that wants to do something with a context. (See withOrigin.) That's "dependency injection", Fortran style. And we can do without vars, because, well, it's ThreadLocal.

Who wrote all this... could they hire Scala programmers, I wonder...
juan_gandhi: (VP)
2016-08-31 07:45 am
Entry tags:

another scala fun

scala> class A[T] { var x:T = _ }
defined class A

scala> val aInt = new A[Int]
aInt: A[Int] = A@36f6e879

scala> aInt.x
res2: Int = 0

  Until you take a closer look:

scala> class A[T] { var x:T = _; println(x) }
defined class A

scala> val aInt = new A[Int]
null
aInt: A[Int] = A@3fee9989

scala> aInt.x
res3: Int = 0


null magically turns into 0.