Skip to content

Instantly share code, notes, and snippets.

@NightRa
NightRa / Fib.hs
Created October 13, 2015 14:30
Fibonacci Stream
module Fib where
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Fusion.Stream as S
import qualified Data.Vector.Fusion.Stream.Monadic as SM
import Data.Vector.Fusion.Stream.Size
import Data.Vector.Fusion.Util
{-
euler2 n = sum $ filter even $ takeWhile (<n) $ fibs
How can I write this and fuse into what's below?
@NightRa
NightRa / SLINK.java
Created April 21, 2015 18:08
SLINK Agglomerative Hierarchical Clustering
@NightRa
NightRa / JavaFXUtil.scala
Created December 31, 2014 22:03
JavaFX reinversion of memory control
package nightra.reversi.util
import scala.ref.WeakReference
import scalafx.beans.property.{Property, BooleanProperty, ObjectProperty}
import scalafx.beans.value.ObservableValue
import scalafx.collections.ObservableBuffer
import scalafx.event.subscriptions.Subscription
object JavaFXUtil {
/**
@NightRa
NightRa / gist:61999b8b13b8f7d763f3
Last active August 29, 2015 14:05
Optics with Monocle - Modeling the part and the whole.
Functional Programming is based on the concept of using pure functions,
which at first sight limit us from various things as I/O, mutation - change and throwing exceptions - dealing with errors or uncertainty.
Optics help us deal with change inside compound structures and with branches (as with error handling),
by providing facilities for looking into complex structures, and modifying a part of them,
as well as powerful abstractions for composing optics, in order to build even more complex systems.
In this talk, I will introduce some of the optics, as Lenses, Prisms and Isomorphisms, and the motivation behind them,
powerful use cases with Polymorphic Optics in Monocle,
and explain the deep and interesting representation of Lenses through Van Laarhoven Lenses,
מה עשית?
[21:35:30] Ilan: ואו, הרבה
[21:35:36] Ilan: היו תחנות
[21:35:41] Ilan: תחנה 1:
[21:36:00] Ilan: סימולציה שאתה עובד כלשהו ויש לקוח לא מרוצה
[21:36:48] Ilan: אני הייתי מוכר הכרטיסים בקולנוע ובאה אחת שהזמינה 2 כרטיסים בשורה 10 ונתנו לה כרטיס בשורה 1 ובשורה 5
[21:36:52 | 21:36:54 נערך] Ilan: והיא רוצה לשבת עם חברה שלה
[21:37:01] Ilan: ואי אפשר לתת החזר כספי
[21:37:23] Ilan: ואי אפשר יום אחר כי זה היום הולדת של חברה שלה
[21:37:50] Ilan: וניסיתי לעזור לה שאולי תשאל אנשים באולם אם אפשר להחליף
@NightRa
NightRa / gist:173adb9c1ad15d45852f
Last active August 29, 2015 14:00
Scalaz concurrency issue.
Wanted behavior:
[info] Started 1
[info] Started 2
[info] Started 3
[info] Started 4
[info] Started 5
[info] Finished 5 in 215
[info] Finished 4 in 615
[info] Finished 3 in 825
[info] Finished 2 in 1109
@NightRa
NightRa / Task.scala
Last active November 20, 2015 09:35
Task - Reader[ExecutionContext, IO[Future[A]]]
package nightra.mashovNotificator.network
import scala.concurrent.{ExecutionContext, Future}
import scalaz.effect.IO
import scalaz.effect.IO._
import scalaz.Reader
import scala.util.{Success, Failure, Try}
case class Task[A](task: Reader[ExecutionContext, IO[Future[A]]]) {
def map[B](f: A => B): Task[B] = Task(Reader(implicit executor => task(executor).map(_.map(f))))
@NightRa
NightRa / DataStructuresCheatSheet
Created April 8, 2014 19:42
Data Structures cheat sheet
Pre-Oreder:
root-->left-->right
In-Oreder:
left-->root-->right
Post-Oreder:
left-->right-->root
==================================================
Sorts:
Max-Sort:
trait Decorable[A, B] {
def decorate(obj: A, dec: B): Either[String, A]
}
object Decorator {
def decorate[A, B](implicit d: Decorable[A,B]) = d
}
object TagsDecorator {
@NightRa
NightRa / gist:8924667
Last active August 29, 2015 13:56 — forked from nuttycom/gist:6690987
trait Functor {
type M <: { type T }
def fmap[A, B](fa: M { type T = A })(f: A => B): M { type T = B }
}
implicit class EitherRightFunctor extends Functor { self =>
type L
type M = Either { type A = self.L ; type T = B } //doesn't this specify a subtype of Either, rather than Either itself?
def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } =